mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Docs: Update benchmark for minimax/minimax-m2.1
This commit is contained in:
32
tests/2_convex_hull/outputs/minimax_minimax-m2.1.js
Normal file
32
tests/2_convex_hull/outputs/minimax_minimax-m2.1.js
Normal file
@@ -0,0 +1,32 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm");
|
||||
|
||||
const sortedPoints = _.sortBy([...points], ["x", "y"]);
|
||||
const uniquePoints = _.uniqWith(sortedPoints, (a, b) => a.x === b.x && a.y === b.y);
|
||||
|
||||
if (uniquePoints.length <= 2) return uniquePoints;
|
||||
|
||||
const crossProduct = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const lower = [];
|
||||
for (const point of uniquePoints) {
|
||||
while (lower.length >= 2 && crossProduct(lower[lower.length - 2], lower[lower.length - 1], point) <= 0) {
|
||||
lower.pop();
|
||||
}
|
||||
lower.push(point);
|
||||
}
|
||||
|
||||
const upper = [];
|
||||
for (let i = uniquePoints.length - 1; i >= 0; i--) {
|
||||
const point = uniquePoints[i];
|
||||
while (upper.length >= 2 && crossProduct(upper[upper.length - 2], upper[upper.length - 1], point) <= 0) {
|
||||
upper.pop();
|
||||
}
|
||||
upper.push(point);
|
||||
}
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 11.859s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user