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,19 @@
|
||||
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
|
||||
export async function findConvexHull(pts){
|
||||
const {default:_}=await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const p=_.orderBy(_.uniqWith(pts,(a,b)=>a.x===b.x&&a.y===b.y),['x','y']);
|
||||
if(p.length<3)return p;
|
||||
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 v of p){
|
||||
while(l.length>1&&c(l[l.length-2],l[l.length-1],v)<=0)l.pop();
|
||||
l.push(v);
|
||||
}
|
||||
const lower = scan(pts)
|
||||
const upper = scan([...pts].reverse())
|
||||
lower.pop()
|
||||
upper.pop()
|
||||
return lower.concat(upper)
|
||||
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);
|
||||
}
|
||||
return l.slice(0,-1).concat(u.slice(0,-1));
|
||||
}
|
||||
export default findConvexHull;
|
||||
export default findConvexHull;
|
||||
// Generation time: 10.565s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user