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,15 @@
|
||||
async function findConvexHull(points){
|
||||
const {default:_}=await import('https://cdn.skypack.dev/lodash-es');
|
||||
const pts=_.uniqWith(_.sortBy(points,['x','y']),(a,b)=>a.x===b.x&&a.y===b.y);
|
||||
if(pts.length<3) return pts.slice();
|
||||
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
const l=[],u=[];
|
||||
for(const p of pts){
|
||||
while(l.length>1&&c(l.at(-2),l.at(-1),p)<=0)l.pop();
|
||||
l.push(p);
|
||||
}
|
||||
for(let i=pts.length;i--;){
|
||||
const p=pts[i];
|
||||
while(u.length>1&&c(u.at(-2),u.at(-1),p)<=0)u.pop();
|
||||
u.push(p);
|
||||
}
|
||||
l.pop();u.pop();
|
||||
return [...l,...u].reverse();
|
||||
let h
|
||||
const findConvexHull=async v=>{
|
||||
const {sortBy,uniqWith,isEqual}=await(h??=import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm'))
|
||||
const s=uniqWith(sortBy(v,['x','y']),isEqual)
|
||||
if(s.length<3)return s.slice()
|
||||
const r=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x)
|
||||
const l=[]
|
||||
for(const p of s){while(l.length>1&&r(l.at(-2),l.at(-1),p)<=0)l.pop();l.push(p)}
|
||||
const u=[]
|
||||
for(let i=s.length;i--;){const p=s[i];while(u.length>1&&r(u.at(-2),u.at(-1),p)<=0)u.pop();u.push(p)}
|
||||
l.pop()
|
||||
u.pop()
|
||||
return l.concat(u)
|
||||
}
|
||||
export default findConvexHull;
|
||||
Reference in New Issue
Block a user