Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-10-13 18:37:08 +00:00
parent eaf29ad08d
commit af1053eeb0
28 changed files with 558 additions and 20 deletions

View File

@@ -0,0 +1,29 @@
async function findConvexHull(points) {
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = arr => {
const hull = [];
for (const p of arr) {
while (hull.length > 1 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
return [...lower, ...upper].reverse();
}
export default findConvexHull;

View File

@@ -0,0 +1,26 @@
async function findConvexHull(points) {
const { sortBy, uniqWith } = await import('https://cdn.skypack.dev/lodash');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = arr => {
const hull = [];
for (const p of arr) {
while (hull.length > 1 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
}
export default findConvexHull;

View File

@@ -0,0 +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');
if (points.length < 3) return points;
const sorted = sortBy(uniqWith(points, isEqual), ['x', 'y']);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHull = (pts) => {
const hull = [];
for (const p of pts) {
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
}
hull.pop();
return hull;
};
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
return [...lower, ...upper].reverse();
}
export default findConvexHull;

View File

@@ -0,0 +1,33 @@
async function findConvexHull(points) {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const uniquePoints = _.uniqWith(points, _.isEqual);
if (uniquePoints.length < 3) {
return uniquePoints;
}
const sorted = _.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 buildHalfHull = (pts) => {
const hull = [];
for (const p of pts) {
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
hull.pop();
}
hull.push(p);
}
return hull;
};
const lower = buildHalfHull(sorted);
const upper = buildHalfHull([...sorted].reverse());
const hull = [...lower.slice(0, -1), ...upper.slice(0, -1)];
return [hull[0], ...hull.slice(1).reverse()];
}
export default findConvexHull;

View File

@@ -0,0 +1,34 @@
async function findConvexHull(points) {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const uniqueSortedPoints = _.sortBy(
_.uniqBy(points, p => `${p.x}:${p.y}`),
['x', 'y']
);
if (uniqueSortedPoints.length < 3) {
return uniqueSortedPoints;
}
const crossProduct = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const buildHalfHull = pts => {
const half = [];
for (const p of pts) {
while (half.length >= 2 && crossProduct(half.at(-2), half.at(-1), p) <= 0) {
half.pop();
}
half.push(p);
}
return half;
};
const lower = buildHalfHull(uniqueSortedPoints);
const upper = buildHalfHull([...uniqueSortedPoints].reverse());
const ccwHull = lower.slice(0, -1).concat(upper.slice(0, -1));
return [ccwHull[0], ...ccwHull.slice(1).reverse()];
}
export default findConvexHull;

View File

@@ -0,0 +1,35 @@
const findConvexHull = async (points) => {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
const sortedPoints = _.sortBy(points, ['x', 'y']);
const uniquePoints = _.uniqWith(sortedPoints, _.isEqual);
if (uniquePoints.length < 3) {
return uniquePoints;
}
const crossProduct = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const lower = [];
for (const p of uniquePoints) {
while (lower.length >= 2 && crossProduct(lower.at(-2), lower.at(-1), p) <= 0) {
lower.pop();
}
lower.push(p);
}
const upper = [];
for (let i = uniquePoints.length - 1; i >= 0; i--) {
const p = uniquePoints[i];
while (upper.length >= 2 && crossProduct(upper.at(-2), upper.at(-1), p) <= 0) {
upper.pop();
}
upper.push(p);
}
const hull = [...lower.slice(0, -1), ...upper.slice(0, -1)];
return hull.reverse();
};
export default findConvexHull;

View File

@@ -0,0 +1,23 @@
const lod=import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
export async function findConvexHull(input){
if(!Array.isArray(input)) return [];
const {uniqBy:uniq,sortBy:sort}=await lod;
const pts=sort(uniq(input.filter(p=>p&&Number.isFinite(p.x)&&Number.isFinite(p.y)).map(p=>({x:+p.x,y:+p.y})),p=>`${p.x}:${p.y}`),['x','y']);
if(pts.length<2) return pts;
const area=(a,b,c)=>(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
const walk=list=>{
const res=[];
for(const p of list){
while(res.length>1&&area(res[res.length-2],res[res.length-1],p)<=0)res.pop();
res.push(p);
}
return res;
};
const low=walk(pts);
const up=walk(pts.slice().reverse());
const hull=low.slice(0,-1).concat(up.slice(0,-1));
const out=hull.length?hull:pts.slice(0,2);
return out.length<3?out:out.reverse();
}
export default findConvexHull;