Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-18 23:31:52 +00:00
parent 341252fec1
commit 5855cf8a6f
77 changed files with 972 additions and 1051 deletions

View File

@@ -1,29 +1,34 @@
async function findConvexHull(points) {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js').then(m => m.default);
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, _.isEqual), ['x', 'y']);
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
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 = (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);
const lower = [];
for (const p of sorted) {
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0) {
lower.pop();
}
hull.pop();
return hull;
};
lower.push(p);
}
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
const upper = [];
for (let i = sorted.length - 1; i >= 0; i--) {
const p = sorted[i];
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0) {
upper.pop();
}
upper.push(p);
}
return [...lower, ...upper];
lower.pop();
upper.pop();
return lower.concat(upper);
}
export default findConvexHull;

View File

@@ -1,27 +1,28 @@
const findConvexHull = async (points) => {
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
async const findConvexHull = async (points) => {
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
const uniquePts = _.uniqWith(points, _.isEqual);
if (uniquePts.length < 3) {
return uniquePts;
const cross = (p1, p2, p3) =>
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
const sortedPoints = sortBy(uniqWith(points, isEqual), ['x', 'y']);
if (sortedPoints.length <= 3) {
return sortedPoints;
}
const crossProduct = (o, a, b) =>
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const sortedPts = _.sortBy(uniquePts, ['x', 'y']);
const buildHalfHull = (pts) =>
pts.reduce((hull, p) => {
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
const buildHull = (pointSet) => {
const hull = [];
for (const p of pointSet) {
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
hull.pop();
}
hull.push(p);
return hull;
}, []);
}
return hull;
};
const lower = buildHalfHull(sortedPts);
const upper = buildHalfHull([...sortedPts].reverse());
const lower = buildHull(sortedPoints);
const upper = buildHull([...sortedPoints].reverse());
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
};

View File

@@ -0,0 +1,20 @@
const findConvexHull = async (pts) => {
const { sortBy: S, uniqWith: U, isEqual: E } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
const p = S(U(pts, E), ['x', 'y'])
if (p.length < 3) return p
const X = (a, b, o) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
const B = (list) => {
const h = []
for (const pt of list) {
while (h.length >= 2 && X(h[h.length - 1], pt, h[h.length - 2]) <= 0) h.pop()
h.push(pt)
}
return h
}
const l = B(p)
const u = B(p.reverse())
l.pop()
u.pop()
return l.concat(u)
}
export default findConvexHull;

View File

@@ -1,22 +0,0 @@
const findConvexHull = async (pts) => {
const { default: _ } = await import('https://cdn.skypack.dev/lodash');
const P = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
const n = P.length, k = [], C = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
if (n < 3) return P;
for (let i = 0; i < n; i++) {
while (k.length >= 2 && C(k[k.length - 2], k[k.length - 1], P[i]) <= 0) k.pop();
k.push(P[i]);
}
for (let i = n - 2, t = k.length + 1; i >= 0; i--) {
while (k.length >= t && C(k[k.length - 2], k[k.length - 1], P[i]) <= 0) k.pop();
k.push(P[i]);
}
k.pop();
return k;
};
export default findConvexHull;

View File

@@ -1,19 +1,18 @@
const findConvexHull = async (pts) => {
const { sortBy, uniqBy } = await import('https://esm.sh/lodash-es@4');
const cross = (a, b, c) => (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
const sorted = sortBy(uniqBy(pts, p => `${p.x},${p.y}`), ['x', 'y']);
if (sorted.length < 3) return sorted;
async function findConvexHull(pts) {
if (!Array.isArray(pts)) return [];
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
const points = _.sortBy(_.uniqWith(pts, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
if (points.length < 3) return points;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const build = (h, p) => {
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
};
const lower = [], upper = [];
for (const p of sorted) {
while (lower.length > 1 && cross(lower[lower.length-2], lower[lower.length-1], p) <= 0) lower.pop();
lower.push(p);
}
for (let i = sorted.length - 1; i >= 0; i--) {
const p = sorted[i];
while (upper.length > 1 && cross(upper[upper.length-2], upper[upper.length-1], p) <= 0) upper.pop();
upper.push(p);
}
lower.pop(); upper.pop();
return [...lower, ...upper];
};
for (const p of points) build(lower, p);
for (let i = points.length; i--; ) build(upper, points[i]);
lower.pop();
upper.pop();
return lower.concat(upper);
}
export default findConvexHull;

View File

@@ -1,21 +1,19 @@
async function findConvexHull(points){
const m=await import('https://cdn.skypack.dev/lodash?min')
const _=m.default||m
const pts=_.sortBy(_.uniqWith(points,(a,b)=>a.x===b.x&&a.y===b.y),['x','y'])
if(pts.length<3)return pts.slice()
const h=[]
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x)
for(const p of pts){
while(h.length>1&&c(h.at(-2),h.at(-1),p)<=0)h.pop()
h.push(p)
async function findConvexHull(points) {
const { uniqWith, isEqual, sortBy } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js')
const pts = sortBy(uniqWith(points, isEqual), ['x', 'y'])
if (pts.length < 3) return pts
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
const scan = (src, acc = []) => {
src.forEach(p => {
while (acc.length > 1 && cross(acc.at(-2), acc.at(-1), p) <= 0) acc.pop()
acc.push(p)
})
return acc
}
const t=h.length+1
for(let i=pts.length-2;i>=0;i--){
const p=pts[i]
while(h.length>=t&&c(h.at(-2),h.at(-1),p)<=0)h.pop()
h.push(p)
}
h.pop()
return h
const lower = scan(pts)
const upper = scan([...pts].reverse())
lower.pop()
upper.pop()
return lower.concat(upper)
}
export default findConvexHull;

View File

@@ -1,22 +1,12 @@
async function findConvexHull(points){
const{default:L}=await import('https://cdn.skypack.dev/lodash-es');
const{sortBy,uniqBy}=L;
let p=uniqBy(points,({x,y})=>`${x},${y}`);
async function findConvexHull(pts){
const{ sortBy:s,uniqBy:u }=await import('https://cdn.skypack.dev/lodash');
if(!pts?.length)return[];
const p=u(s(pts,['x','y']),t=>`${t.x},${t.y}`);
if(p.length<2)return p;
p=sortBy(p,['x','y']);
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
let l=[];
for(let i=0;i<p.length;i++){
let pt=p[i];
while(l.length>=2&&cross(l[l.length-2],l[l.length-1],pt)<=0)l.pop();
l.push(pt);
}
let u=[];
for(let i=p.length-1;i>=0;i--){
let pt=p[i];
while(u.length>=2&&cross(u[u.length-2],u[u.length-1],pt)<=0)u.pop();
u.push(pt);
}
return[...l.slice(0,-1),...u.slice(0,-1)];
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
let l=[];for(let t of p){while(l.length>1&&c(l[l.length-2],l[l.length-1],t)<=0)l.pop();l.push(t)}
let r=[];for(let i=p.length-1;i>=0;i--){const t=p[i];while(r.length>1&&c(r[r.length-2],r[r.length-1],t)<=0)r.pop();r.push(t)}
l.pop();r.pop();
return[...l,...r];
}
export default findConvexHull;