Skip to content

Commit

Permalink
refactor(geom-hull): minor update findMin()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 28, 2019
1 parent adfec26 commit b6145e3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/geom-hull/src/graham-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const atan2 = Math.atan2;
export const grahamScan2 = (pts: ReadonlyVec[], eps = EPS) => {
const num = pts.length;
if (num <= 3) return pts.slice();
let h = 1,
i,
p,
q,
r,
rx,
ry;
let h = 1;
let i;
let p;
let q;
let r;
let rx;
let ry;
// find min YX index
const min = findMin(pts);
[rx, ry] = pts[min];
Expand Down Expand Up @@ -84,13 +84,14 @@ const notCCW = (
const findMin = (pts: ReadonlyVec[]) => {
let n = pts.length - 1;
let minID = n;
let min = pts[n][1];
let [minX, minY] = pts[n];
let p, y;
for (; --n >= 0; ) {
p = pts[n];
y = p[1];
if (y < min || (y === min && p[0] < pts[minID][0])) {
min = y;
if (y < minY || (y === minY && p[0] < minX)) {
minX = p[0];
minY = y;
minID = n;
}
}
Expand Down

0 comments on commit b6145e3

Please sign in to comment.