From fb863f3183eaf9a46655eeefb1d3e7b787383c2a Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 18 Jun 2021 22:08:36 +0300 Subject: [PATCH] Filler: skip NaN points from end of segment (#9287) --- src/plugins/plugin.filler.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/plugins/plugin.filler.js b/src/plugins/plugin.filler.js index b8d0fed4bbd..4b70e2cf41f 100644 --- a/src/plugins/plugin.filler.js +++ b/src/plugins/plugin.filler.js @@ -172,13 +172,24 @@ function computeBoundary(source) { return computeLinearBoundary(source); } +function findSegmentEnd(start, end, points) { + for (;end > start; end--) { + const point = points[end]; + if (!isNaN(point.x) && !isNaN(point.y)) { + break; + } + } + return end; +} + function pointsFromSegments(boundary, line) { const {x = null, y = null} = boundary || {}; const linePoints = line.points; const points = []; - line.segments.forEach((segment) => { - const first = linePoints[segment.start]; - const last = linePoints[segment.end]; + line.segments.forEach(({start, end}) => { + end = findSegmentEnd(start, end, linePoints); + const first = linePoints[start]; + const last = linePoints[end]; if (y !== null) { points.push({x: first.x, y}); points.push({x: last.x, y}); @@ -406,7 +417,10 @@ function _segments(line, target, property) { const parts = []; for (const segment of segments) { - const bounds = getBounds(property, points[segment.start], points[segment.end], segment.loop); + let {start, end} = segment; + end = findSegmentEnd(start, end, points); + + const bounds = getBounds(property, points[start], points[end], segment.loop); if (!target.segments) { // Special case for boundary not supporting `segments` (simpleArc) @@ -414,8 +428,8 @@ function _segments(line, target, property) { parts.push({ source: segment, target: bounds, - start: points[segment.start], - end: points[segment.end] + start: points[start], + end: points[end] }); continue; }