mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -21,9 +21,6 @@ async function findConvexHull(points) {
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = buildHull(sorted);
|
||||
const upper = buildHull([...sorted].reverse());
|
||||
|
||||
return [...lower, ...upper].reverse();
|
||||
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,17 +1,17 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js').then(m => m.default);
|
||||
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
|
||||
if (points.length < 3) return points;
|
||||
|
||||
const sorted = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
||||
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
|
||||
if (sorted.length < 3) return sorted;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const buildHull = arr => {
|
||||
const buildHull = pts => {
|
||||
const hull = [];
|
||||
for (const p of arr) {
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
@@ -21,9 +21,6 @@ async function findConvexHull(points) {
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = buildHull(sorted);
|
||||
const upper = buildHull([...sorted].reverse());
|
||||
|
||||
return [...lower, ...upper].reverse();
|
||||
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,15 +1,15 @@
|
||||
const findConvexHull = async (points) => {
|
||||
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js').then(m => m.default);
|
||||
|
||||
if (points.length < 3) return points;
|
||||
|
||||
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
const sorted = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
||||
|
||||
if (sorted.length < 3) return sorted;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const buildHalf = (pts) => {
|
||||
const buildHull = pts => {
|
||||
const hull = [];
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
@@ -21,9 +21,6 @@ const findConvexHull = async (points) => {
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = buildHalf(sorted);
|
||||
const upper = buildHalf([...sorted].reverse());
|
||||
|
||||
return [...lower, ...upper].reverse();
|
||||
};
|
||||
return [...buildHull(sorted), ...buildHull(sorted.slice().reverse())];
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,29 +1,29 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
|
||||
|
||||
const sortedUniquePoints = _.uniqWith(_.sortBy(points, ['x', 'y']), _.isEqual);
|
||||
|
||||
if (sortedUniquePoints.length < 3) {
|
||||
return sortedUniquePoints;
|
||||
if (points.length < 3) {
|
||||
return [...points];
|
||||
}
|
||||
|
||||
const crossProduct = (p1, p2, p3) =>
|
||||
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
|
||||
|
||||
const buildHalfHull = (pts) => {
|
||||
const hull = [];
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
|
||||
const sortedPoints = sortBy(points, ['x', 'y']);
|
||||
|
||||
const buildHull = (pts) =>
|
||||
pts.reduce((hull, p) => {
|
||||
while (hull.length >= 2 && crossProduct(hull[hull.length - 2], hull.at(-1), p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
return hull;
|
||||
};
|
||||
return hull;
|
||||
}, []);
|
||||
|
||||
const lowerHull = buildHalfHull(sortedUniquePoints);
|
||||
const upperHull = buildHalfHull([...sortedUniquePoints].reverse());
|
||||
const lowerHull = buildHull(sortedPoints);
|
||||
const upperHull = buildHull([...sortedPoints].reverse());
|
||||
|
||||
return [...upperHull.slice(0, -1), ...lowerHull.slice(0, -1)];
|
||||
const combinedHull = [...lowerHull, ...upperHull];
|
||||
|
||||
return uniqWith(combinedHull, isEqual);
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user