Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-07 22:07:45 +00:00
parent b5f81c6e8a
commit 1687dca49c
42 changed files with 784 additions and 847 deletions

View File

@@ -1,29 +1,23 @@
async function findConvexHull(points) {
if (!Array.isArray(points) || points.length < 3) return points || [];
if (!Array.isArray(points) || points.length < 1) return [];
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.default.min.js');
const ps = _.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y);
if (ps.length < 3) return ps;
const pts = _.sortBy(ps, ['x', 'y']);
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const lower = [];
const s = _.uniqBy(points, p => `${p.x},${p.y}`);
if (s.length < 2) return s.slice();
const pts = _.sortBy(s, ['x', 'y']);
const c = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const l = [];
for (let p of pts) {
for (; lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0;) lower.pop();
lower.push(p);
for (; l.length > 1 && c(l[l.length - 2], l[l.length - 1], p) <= 0;) l.pop();
l.push(p);
}
const upper = [];
const u = [];
for (let i = pts.length - 1; i >= 0; i--) {
const p = pts[i];
for (; upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0;) upper.pop();
upper.push(p);
for (; u.length > 1 && c(u[u.length - 2], u[u.length - 1], p) <= 0;) u.pop();
u.push(p);
}
const hull = lower.slice(0, -1).concat(upper.slice(0, -1));
if (hull.length <= 2) return hull;
let area = 0;
for (let i = 0; i < hull.length; i++) {
const j = (i + 1) % hull.length;
area += hull[i].x * hull[j].y - hull[j].x * hull[i].y;
}
if (area > 0) hull.reverse();
return hull;
l.pop();
u.pop();
return l.concat(u);
}
export default findConvexHull;