Skip to content

Commit

Permalink
1.1.1 fix regression in paperClipperSimplify
Browse files Browse the repository at this point in the history
  • Loading branch information
northamerican committed Apr 19, 2022
1 parent aab6b11 commit 90ae086
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paper-clipper",
"version": "1.1.0",
"version": "1.1.1",
"description": "Use Clipper's boolean and offsetting operations in paper.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
24 changes: 23 additions & 1 deletion src/paperClipperSimplify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,29 @@ const recursiveSimplify = (tolerance: number) => (targetPathPart: paper.Path) =>
return hasMoreSegments ? targetPathPart : pathPart
}

const removeDuplicateAdjacentSegments = (path: paper.Path): paper.Path => {
const { segments } = path
const segmentsBefore = segments.length

segments.forEach(segment => {
const { next } = segment

if (!next) return

const duplicateSegment = segment.point.isClose(next.point, geomEpsilon)

if (duplicateSegment) {
next.handleIn = segment.handleIn.clone()

segment.remove()
}
})

return segmentsBefore > segments.length ? removeDuplicateAdjacentSegments(path) : path
}

const paperClipperSimplify = (tolerance: number = paperClipperSimplifyTolerance) => (targetPath: paper.Path): paper.Path => {
const path = targetPath
const path = removeDuplicateAdjacentSegments(targetPath)
const { closed } = path

if (path.length === 0) return targetPath
Expand All @@ -127,6 +148,7 @@ const paperClipperSimplify = (tolerance: number = paperClipperSimplifyTolerance)
)

const pathParts = splitAtOffsets(path)(angledSegmentOffsets)
.map(removeDuplicateAdjacentSegments)
.map(recursiveSimplify(tolerance))

const joinedPath = joinPaths(pathParts)
Expand Down

0 comments on commit 90ae086

Please sign in to comment.