mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -21,6 +21,6 @@ async function findConvexHull(points) {
|
||||
return hull;
|
||||
};
|
||||
|
||||
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
|
||||
return [...buildHull(sorted), ...buildHull([...sorted].reverse())];
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,27 +1,29 @@
|
||||
async function findConvexHull(points) {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
const findConvexHull = async (points) => {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
|
||||
const uniquePoints = uniqWith(points, isEqual);
|
||||
if (uniquePoints.length < 3) {
|
||||
return uniquePoints;
|
||||
const sortedPoints = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
||||
|
||||
if (sortedPoints.length < 3) {
|
||||
return sortedPoints;
|
||||
}
|
||||
|
||||
const sortedPoints = sortBy(uniquePoints, ['x', 'y']);
|
||||
|
||||
const crossProduct = (p1, p2, p3) =>
|
||||
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
|
||||
|
||||
const buildHull = pts => pts.reduce((hull, p) => {
|
||||
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
|
||||
hull.pop();
|
||||
const buildHalfHull = (pointSet) => {
|
||||
const hull = [];
|
||||
for (const p of pointSet) {
|
||||
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
hull.push(p);
|
||||
return hull;
|
||||
}, []);
|
||||
};
|
||||
|
||||
const lower = buildHull(sortedPoints);
|
||||
const upper = buildHull([...sortedPoints].reverse());
|
||||
const lower = buildHalfHull(sortedPoints);
|
||||
const upper = buildHalfHull([...sortedPoints].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
};
|
||||
export default findConvexHull;
|
||||
20
tests/2_convex_hull/outputs/openai_gpt-5.1-chat.js
Normal file
20
tests/2_convex_hull/outputs/openai_gpt-5.1-chat.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export async function findConvexHull(a){
|
||||
const _ = (await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js')).default
|
||||
a = _.uniqWith(a,_.isEqual)
|
||||
a = _.sortBy(a,['x','y'])
|
||||
const c=(o,p,q)=>((p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x))
|
||||
const b=[]
|
||||
for(const p of a){
|
||||
while(b.length>1 && c(b[b.length-2],b[b.length-1],p)<=0) b.pop()
|
||||
b.push(p)
|
||||
}
|
||||
const u=[]
|
||||
for(const p of [...a].reverse()){
|
||||
while(u.length>1 && c(u[u.length-2],u[u.length-1],p)<=0) u.pop()
|
||||
u.push(p)
|
||||
}
|
||||
u.pop()
|
||||
b.pop()
|
||||
return [...b,...u]
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,23 +0,0 @@
|
||||
let cache
|
||||
const loader=()=>cache??=import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js')
|
||||
|
||||
export const findConvexHull=async pts=>{
|
||||
const {sortBy:s,uniqWith:u,isEqual:e}=await loader()
|
||||
const data=u(s(pts,[v=>v.x,v=>v.y]),e)
|
||||
if(data.length<2)return data.slice()
|
||||
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x)
|
||||
const lower=[],upper=[]
|
||||
for(const p of data){
|
||||
while(lower.length>1&&cross(lower.at(-2),lower.at(-1),p)<=0)lower.pop()
|
||||
lower.push(p)
|
||||
}
|
||||
for(let i=data.length;i--;){
|
||||
const p=data[i]
|
||||
while(upper.length>1&&cross(upper.at(-2),upper.at(-1),p)<=0)upper.pop()
|
||||
upper.push(p)
|
||||
}
|
||||
lower.pop()
|
||||
upper.pop()
|
||||
return lower.concat(upper)
|
||||
}
|
||||
export default findConvexHull;
|
||||
Reference in New Issue
Block a user