Skip to content

Commit 42705ad

Browse files
committed
avoid duplicate ClipperUnion calls
1 parent 0579d21 commit 42705ad

1 file changed

Lines changed: 7 additions & 26 deletions

File tree

src/common/boundary.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const boundaryAlgorithm = (vertices) => {
195195
return {
196196
algorithm: "expand",
197197
reason: "too few vertices",
198+
boundary: [],
198199
boundaryPaths: 0,
199200
ratio: 0,
200201
pointsPerPath: 0,
@@ -224,6 +225,7 @@ export const boundaryAlgorithm = (vertices) => {
224225
return {
225226
algorithm: "expand",
226227
reason: "no boundary",
228+
boundary: [],
227229
boundaryPaths: 0,
228230
ratio: 0,
229231
pointsPerPath: 0,
@@ -336,6 +338,7 @@ export const boundaryAlgorithm = (vertices) => {
336338
return {
337339
algorithm,
338340
reason,
341+
boundary,
339342
boundaryPaths: boundary.length,
340343
ratio: Math.round(ratio * 100) / 100,
341344
pointsPerPath: Math.round(pointsPerPath * 10) / 10,
@@ -633,20 +636,10 @@ export const traceBoundary = (vertices, scale = 0, algorithm = null) => {
633636
}
634637

635638
const detection = boundaryAlgorithm(vertices)
636-
const { isFillPattern, largestDominates } = detection
639+
const { boundary, isFillPattern, largestDominates } = detection
637640
const useFootprint =
638641
algorithm === 2 ||
639642
(algorithm === null && detection.algorithm === "footprint")
640-
const bounds = findBounds(vertices)
641-
const inputWidth = bounds[1].x - bounds[0].x
642-
const inputHeight = bounds[1].y - bounds[0].y
643-
const path = new Path64()
644-
645-
for (const v of vertices) {
646-
path.push({ x: Math.round(v.x * SCALE), y: Math.round(v.y * SCALE) })
647-
}
648-
649-
let boundary = Clipper.Union([path], null, FillRule.NonZero)
650643

651644
if (boundary.length === 0) {
652645
// Fallback to convex hull when Clipper fails (e.g., twisted tessellation)
@@ -668,22 +661,10 @@ export const traceBoundary = (vertices, scale = 0, algorithm = null) => {
668661
return fallbackHull.map((v) => new Victor(v.x, v.y))
669662
}
670663

671-
// Filter out degenerate paths
672-
const inputArea = inputWidth * inputHeight * SCALE * SCALE
673-
const minArea = inputArea * MIN_AREA_RATIO
674-
const maxPathArea = Math.max(
675-
...boundary.map((p) => Math.abs(Clipper.area(p))),
676-
)
677-
678-
if (maxPathArea > 0) {
679-
const filtered = boundary.filter((p) => Math.abs(Clipper.area(p)) > minArea)
680-
681-
if (filtered.length > 0) {
682-
boundary = filtered
683-
}
684-
}
685-
686664
// Determine which boundary paths to use
665+
const bounds = findBounds(vertices)
666+
const inputWidth = bounds[1].x - bounds[0].x
667+
const inputHeight = bounds[1].y - bounds[0].y
687668
const pathAreas = boundary.map((p) => Math.abs(Clipper.area(p)))
688669
const sortedAreas = [...pathAreas].sort((a, b) => b - a)
689670
const maxArea = sortedAreas[0]

0 commit comments

Comments
 (0)