mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
async function findConvexHull(pts){
|
||||
const _=(await import('https://esm.run/lodash@4.17.21')).default;
|
||||
let p=_.uniqBy(_.sortBy(pts,['x','y']),q=>[q.x,q.y]);
|
||||
if(p.length<=2)return p;
|
||||
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
let lower=[];
|
||||
for(let q of p){
|
||||
while(lower.length>=2&&cross(lower[lower.length-2],lower[lower.length-1],q)<=0)lower.pop();
|
||||
lower.push(q);
|
||||
}
|
||||
let upper=[];
|
||||
let rp=[...p].reverse();
|
||||
for(let q of rp){
|
||||
while(upper.length>=2&&cross(upper[upper.length-2],upper[upper.length-1],q)<=0)upper.pop();
|
||||
upper.push(q);
|
||||
}
|
||||
return lower.slice(0,-1).concat(upper.slice(0,-1));
|
||||
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}`);
|
||||
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)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
Reference in New Issue
Block a user