Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-14 03:31:28 +00:00
parent 7052d4f4b5
commit 9a64997884
37 changed files with 656 additions and 390 deletions

View File

@@ -21,6 +21,9 @@ async function findConvexHull(points) {
return hull;
};
return [...buildHull(sorted), ...buildHull([...sorted].reverse())];
const lower = buildHull(sorted);
const upper = buildHull([...sorted].reverse());
return [...lower, ...upper];
}
export default findConvexHull;

View File

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

View File

@@ -1,20 +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)
export async function findConvexHull(p){
const _=(await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js')).default
p=_.uniqWith(p,_.isEqual)
p=_.sortBy(p,['x','y'])
const c=(a,b,d)=>(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x)
const h=[]
for(const v of p){
while(h.length>1&&c(h[h.length-2],h[h.length-1],v)<=0)h.pop()
h.push(v)
}
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)
for(const v of [...p].reverse()){
while(u.length>1&&c(u[u.length-2],u[u.length-1],v)<=0)u.pop()
u.push(v)
}
h.pop()
u.pop()
b.pop()
return [...b,...u]
return [...h,...u]
}
export default findConvexHull;

View File

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