Skip to content

Commit

Permalink
fix(geom-closest-point): update polyline & point array fns
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 9, 2019
1 parent 0d9b7cb commit c5b4757
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/geom-closest-point/src/index.ts
Expand Up @@ -128,6 +128,7 @@ export const closestPointPolyline = (
closed = false,
out: Vec = []
) => {
if (!pts.length) return;
const tmp: Vec = [];
const n = pts.length - 1;
let minD = Infinity,
Expand Down Expand Up @@ -185,7 +186,11 @@ export const farthestPointSegment = (
return [maxIdx, Math.sqrt(maxD)];
};

export const closestPointArray = (p: ReadonlyVec, pts: Vec[]) => {
export const closestPointArray = (
p: ReadonlyVec,
pts: Vec[],
out: Vec = []
) => {
let minD = Infinity;
let closest: Vec | undefined;
for (let i = pts.length; --i >= 0; ) {
Expand All @@ -195,7 +200,7 @@ export const closestPointArray = (p: ReadonlyVec, pts: Vec[]) => {
closest = pts[i];
}
}
return closest;
return closest ? set(out, closest) : undefined;
};

export const distToPlane = (p: ReadonlyVec, n: ReadonlyVec, w: number) =>
Expand Down

0 comments on commit c5b4757

Please sign in to comment.