From 7898810244a7a4e4cba43c7ec0bedc095e1f4be4 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Sun, 15 Aug 2021 22:43:08 +0200 Subject: [PATCH] fix(geom-clip-line): off-by-one error in clipLinePoly() --- packages/geom-clip-line/src/clip-poly.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/geom-clip-line/src/clip-poly.ts b/packages/geom-clip-line/src/clip-poly.ts index 68628e0b3b..a2c4c33dd1 100644 --- a/packages/geom-clip-line/src/clip-poly.ts +++ b/packages/geom-clip-line/src/clip-poly.ts @@ -19,11 +19,15 @@ export const clipLinePoly = ( b: ReadonlyVec, pts: ReadonlyVec[] ) => { - const isecs = intersectRayPolylineAll(a, direction([], a, b), pts, true) - .isec; + const isecs = intersectRayPolylineAll( + a, + direction([], a, b), + pts, + true + ).isec; if (!isecs) return; const segments: Vec[][] = []; - for (let i = 0; i < isecs.length; i += 2) { + for (let i = 0, n = isecs.length - 1; i < n; i += 2) { segments.push([isecs[i], isecs[i + 1]]); } return segments;