-
Notifications
You must be signed in to change notification settings - Fork 490
fix(contour): fix intersect and subtract operations when one segment is fully inside another #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
8788ef7
120b11b
58bb2f5
c4544a7
bc166a0
63522aa
4fd731d
032920b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,14 +69,19 @@ export function checkIntersection( | |
| ): { | ||
| hasIntersection: boolean; | ||
| isContourHole: boolean; | ||
| isTargetInsideSource: boolean; | ||
| } { | ||
| const sourceAABB = math.polyline.getAABB(sourcePolyline); | ||
| const targetAABB = math.polyline.getAABB(targetPolyline); | ||
|
|
||
| const aabbIntersect = math.aabb.intersectAABB(sourceAABB, targetAABB); | ||
|
|
||
| if (!aabbIntersect) { | ||
| return { hasIntersection: false, isContourHole: false }; | ||
| return { | ||
| hasIntersection: false, | ||
| isContourHole: false, | ||
| isTargetInsideSource: false, | ||
| }; | ||
| } | ||
|
|
||
| const lineSegmentsIntersect = math.polyline.intersectPolyline( | ||
|
|
@@ -89,9 +94,15 @@ export function checkIntersection( | |
| !lineSegmentsIntersect && | ||
| math.polyline.containsPoints(targetPolyline, sourcePolyline); | ||
|
|
||
| // Target's points are all inside source -> target is a hole inside source | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is a little confusing to me. In this case target is not necessarily a hold inside source right? Would a better comment be // Target is fully contained inside source (no edge crossings)?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, comment updated. |
||
| const isTargetInsideSource = | ||
| !lineSegmentsIntersect && | ||
| !isContourHole && | ||
| math.polyline.containsPoints(sourcePolyline, targetPolyline); | ||
|
|
||
| const hasIntersection = lineSegmentsIntersect || isContourHole; | ||
|
|
||
| return { hasIntersection, isContourHole }; | ||
| return { hasIntersection, isContourHole, isTargetInsideSource }; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since addPolylinesToSegmentation is the main, exported function, let's move this one below it. It makes for a better diff in the PR too.