mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Delete tests/2_convex_hull/outputs_gemini directory
This commit is contained in:
@@ -1,25 +0,0 @@
|
|||||||
const findConvexHull = async (P) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
|
|
||||||
const U = _.uniqWith(P, _.isEqual);
|
|
||||||
if (U.length < 3) return U;
|
|
||||||
|
|
||||||
const S = _.sortBy(U, ['x', 'y']);
|
|
||||||
|
|
||||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
||||||
|
|
||||||
const build = (list) => {
|
|
||||||
const h = [];
|
|
||||||
list.forEach(p => {
|
|
||||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
h.push(p);
|
|
||||||
});
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
|
|
||||||
const l = build(S);
|
|
||||||
const u = build([...S].reverse());
|
|
||||||
|
|
||||||
return [...l.slice(0, -1), ...u.slice(0, -1)];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://esm.sh/lodash')
|
|
||||||
const u = _.uniqWith(pts, _.isEqual)
|
|
||||||
if (u.length < 3) return u
|
|
||||||
const s = _.sortBy(u, ['x', 'y'])
|
|
||||||
const cp = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
const scan = (lst) => {
|
|
||||||
const h = []
|
|
||||||
lst.forEach(p => {
|
|
||||||
while (h.length >= 2 && cp(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
})
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
const l = scan(s)
|
|
||||||
const uH = scan(s.reverse())
|
|
||||||
return _.concat(l.slice(0, -1), uH.slice(0, -1))
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
|
||||||
if (s.length < 3) return s
|
|
||||||
const h = [], x = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
|
||||||
for (const p of s) {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
}
|
|
||||||
const t = h.length + 1
|
|
||||||
for (let i = s.length - 2; i >= 0; i--) {
|
|
||||||
while (h.length >= t && x(h[h.length - 2], h[h.length - 1], s[i]) <= 0) h.pop()
|
|
||||||
h.push(s[i])
|
|
||||||
}
|
|
||||||
h.pop()
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
const findConvexHull = async points => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
|
|
||||||
const sorted = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y'])
|
|
||||||
if (sorted.length < 3) return sorted
|
|
||||||
|
|
||||||
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
const hull = []
|
|
||||||
|
|
||||||
for (const p of sorted) {
|
|
||||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
|
||||||
hull.pop()
|
|
||||||
}
|
|
||||||
hull.push(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
const lowerLen = hull.length + 1
|
|
||||||
for (let i = sorted.length - 2; i >= 0; i--) {
|
|
||||||
const p = sorted[i]
|
|
||||||
while (hull.length >= lowerLen && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
|
||||||
hull.pop()
|
|
||||||
}
|
|
||||||
hull.push(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
hull.pop()
|
|
||||||
return hull
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
const findConvexHull = async (p) => {
|
|
||||||
const { default: _ } = await import('https://cdn.skypack.dev/lodash');
|
|
||||||
const s = _.sortBy(_.uniqWith(p, _.isEqual), ['x', 'y']);
|
|
||||||
if (s.length < 3) return s;
|
|
||||||
|
|
||||||
const x = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
||||||
const h = [];
|
|
||||||
|
|
||||||
for (const i of s) {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], i) <= 0) h.pop();
|
|
||||||
h.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
const t = h.length + 1;
|
|
||||||
for (let i = s.length - 2; i >= 0; i--) {
|
|
||||||
const k = s[i];
|
|
||||||
while (h.length >= t && x(h[h.length - 2], h[h.length - 1], k) <= 0) h.pop();
|
|
||||||
h.push(k);
|
|
||||||
}
|
|
||||||
|
|
||||||
h.pop();
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
|
|
||||||
if (s.length < 3) return s;
|
|
||||||
|
|
||||||
const h = [], x = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
||||||
|
|
||||||
for (let i = 0; i < s.length; i++) {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], s[i]) <= 0) h.pop();
|
|
||||||
h.push(s[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = s.length - 2, t = h.length + 1; i >= 0; i--) {
|
|
||||||
while (h.length >= t && x(h[h.length - 2], h[h.length - 1], s[i]) <= 0) h.pop();
|
|
||||||
h.push(s[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
h.pop();
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const findConvexHull = async (points) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
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 buildHull = (list) => {
|
|
||||||
const hull = [];
|
|
||||||
list.forEach(p => {
|
|
||||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) hull.pop();
|
|
||||||
hull.push(p);
|
|
||||||
});
|
|
||||||
return hull;
|
|
||||||
};
|
|
||||||
|
|
||||||
const lower = buildHull(sorted);
|
|
||||||
const upper = buildHull([...sorted].reverse());
|
|
||||||
|
|
||||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://esm.sh/lodash@4');
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
|
|
||||||
if (s.length < 3) return s;
|
|
||||||
|
|
||||||
const k = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
||||||
const add = (h, p) => {
|
|
||||||
while (h.length > 1 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
h.push(p);
|
|
||||||
};
|
|
||||||
|
|
||||||
const l = [], u = [];
|
|
||||||
s.forEach(p => add(l, p));
|
|
||||||
for (let i = s.length - 1; i >= 0; i--) add(u, s[i]);
|
|
||||||
|
|
||||||
l.pop(); u.pop();
|
|
||||||
return [...l, ...u];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
|
||||||
if (s.length < 3) return s
|
|
||||||
|
|
||||||
const x = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
const scan = (arr, h = []) => {
|
|
||||||
for (const p of arr) {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
}
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
const l = scan(s), u = scan([...s].reverse())
|
|
||||||
return [...l.slice(0, -1), ...u.slice(0, -1)]
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://esm.sh/lodash');
|
|
||||||
const u = _.uniqWith(pts, _.isEqual);
|
|
||||||
if (u.length < 3) return u;
|
|
||||||
const s = _.sortBy(u, ['x', 'y']);
|
|
||||||
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
||||||
const f = (l) => {
|
|
||||||
const h = [];
|
|
||||||
for (const p of l) {
|
|
||||||
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
h.push(p);
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
const l = f(s);
|
|
||||||
const h = f([...s].reverse());
|
|
||||||
return [...l.slice(0, -1), ...h.slice(0, -1)];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
const findConvexHull = async points => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const s = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y'])
|
|
||||||
if (s.length < 3) return s
|
|
||||||
const x = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
|
||||||
const scan = (arr, h = []) => {
|
|
||||||
arr.forEach(p => {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
})
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
const l = scan(s)
|
|
||||||
const u = scan([...s].reverse())
|
|
||||||
return l.slice(0, -1).concat(u.slice(0, -1))
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
const findConvexHull = async points => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const p = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y'])
|
|
||||||
if (p.length < 3) return p
|
|
||||||
const h = [], x = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
for (let i = 0; i < p.length; i++) {
|
|
||||||
while (h.length >= 2 && x(h[h.length - 2], h[h.length - 1], p[i]) <= 0) h.pop()
|
|
||||||
h.push(p[i])
|
|
||||||
}
|
|
||||||
for (let i = p.length - 2, t = h.length + 1; i >= 0; i--) {
|
|
||||||
while (h.length >= t && x(h[h.length - 2], h[h.length - 1], p[i]) <= 0) h.pop()
|
|
||||||
h.push(p[i])
|
|
||||||
}
|
|
||||||
h.pop()
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
export const findConvexHull = async (points) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
const P = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
|
|
||||||
|
|
||||||
if (P.length < 3) return P;
|
|
||||||
|
|
||||||
const cross = (a, b, o) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
||||||
|
|
||||||
const buildChain = (nodes) => {
|
|
||||||
const hull = [];
|
|
||||||
for (const p of nodes) {
|
|
||||||
while (hull.length >= 2 && cross(hull[hull.length - 1], p, hull[hull.length - 2]) <= 0) {
|
|
||||||
hull.pop();
|
|
||||||
}
|
|
||||||
hull.push(p);
|
|
||||||
}
|
|
||||||
return hull;
|
|
||||||
};
|
|
||||||
|
|
||||||
const lower = buildChain(P);
|
|
||||||
const upper = buildChain([...P].reverse());
|
|
||||||
|
|
||||||
lower.pop();
|
|
||||||
upper.pop();
|
|
||||||
|
|
||||||
return [...lower, ...upper];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
|
||||||
if (s.length < 3) return s
|
|
||||||
|
|
||||||
const k = (a, b, o) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
|
||||||
const build = (list) => {
|
|
||||||
const stack = []
|
|
||||||
for (const p of list) {
|
|
||||||
while (stack.length > 1 && k(stack[stack.length - 1], p, stack[stack.length - 2]) <= 0) {
|
|
||||||
stack.pop()
|
|
||||||
}
|
|
||||||
stack.push(p)
|
|
||||||
}
|
|
||||||
return stack
|
|
||||||
}
|
|
||||||
|
|
||||||
const l = build(s)
|
|
||||||
const u = build([...s].reverse())
|
|
||||||
return [...l.slice(0, -1), ...u.slice(0, -1)]
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const findConvexHull = async (rawPoints) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const pts = _.sortBy(_.uniqWith(rawPoints, _.isEqual), ['x', 'y'])
|
|
||||||
if (pts.length < 3) return pts
|
|
||||||
|
|
||||||
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
|
|
||||||
const build = (list) => {
|
|
||||||
const h = []
|
|
||||||
list.forEach(p => {
|
|
||||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
})
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
const lower = build(pts)
|
|
||||||
const upper = build([...pts].reverse())
|
|
||||||
|
|
||||||
lower.pop(), upper.pop()
|
|
||||||
return [...lower, ...upper]
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
export const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
|
||||||
const S = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
|
||||||
if (S.length < 3) return S
|
|
||||||
|
|
||||||
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
const chain = (list) => {
|
|
||||||
const h = []
|
|
||||||
for (const p of list) {
|
|
||||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
}
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
const l = chain(S)
|
|
||||||
const u = chain([...S].reverse())
|
|
||||||
|
|
||||||
l.pop()
|
|
||||||
u.pop()
|
|
||||||
return l.concat(u)
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
const findConvexHull = async (points) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
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 scan = (list) => list.reduce((h, p) => {
|
|
||||||
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
return h.push(p), h;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const lower = scan(sorted);
|
|
||||||
const upper = scan([...sorted].reverse());
|
|
||||||
|
|
||||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
|
||||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
|
||||||
if (s.length < 3) return s
|
|
||||||
|
|
||||||
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
||||||
const f = (h, p) => {
|
|
||||||
while (h.length >= 2 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
|
||||||
h.push(p)
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
const l = _.reduce(s, f, [])
|
|
||||||
const u = _.reduceRight(s, f, [])
|
|
||||||
|
|
||||||
return [..._.dropRight(l), ..._.dropRight(u)]
|
|
||||||
}
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
const findConvexHull = async (points) => {
|
|
||||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
|
|
||||||
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 chain = (list) => {
|
|
||||||
const h = [];
|
|
||||||
for (const p of list) {
|
|
||||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
h.push(p);
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
const lower = chain(pts), upper = chain([...pts].reverse());
|
|
||||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
const findConvexHull = async (points) => {
|
|
||||||
if (!Array.isArray(points)) throw new Error('Input must be an array');
|
|
||||||
|
|
||||||
const { default: _ } = await import('https://esm.sh/lodash');
|
|
||||||
|
|
||||||
const uniq = _.uniqWith(points, _.isEqual);
|
|
||||||
if (uniq.length < 3) return uniq;
|
|
||||||
|
|
||||||
const sorted = _.sortBy(uniq, ['x', 'y']);
|
|
||||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
||||||
|
|
||||||
const build = (list) => {
|
|
||||||
const hull = [];
|
|
||||||
for (const p of list) {
|
|
||||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
|
||||||
hull.pop();
|
|
||||||
}
|
|
||||||
hull.push(p);
|
|
||||||
}
|
|
||||||
return hull;
|
|
||||||
};
|
|
||||||
|
|
||||||
const lower = build(sorted);
|
|
||||||
const upper = build([...sorted].reverse());
|
|
||||||
|
|
||||||
lower.pop();
|
|
||||||
upper.pop();
|
|
||||||
|
|
||||||
return [...lower, ...upper];
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const findConvexHull = async (pts) => {
|
|
||||||
const _ = (await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')).default;
|
|
||||||
const u = _.uniqWith(pts, _.isEqual);
|
|
||||||
if (u.length < 3) return u;
|
|
||||||
const s = _.sortBy(u, ['x', 'y']);
|
|
||||||
const k = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
||||||
const b = (list, h = []) => {
|
|
||||||
for (const p of list) {
|
|
||||||
while (h.length > 1 && k(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
|
||||||
h.push(p);
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
};
|
|
||||||
const l = b(s);
|
|
||||||
const r = b(s.reverse());
|
|
||||||
return l.slice(0, -1).concat(r.slice(0, -1));
|
|
||||||
};
|
|
||||||
export default findConvexHull;
|
|
||||||
Reference in New Issue
Block a user