fix: keep island contact polygon inside boundary
This commit is contained in:
1 parent
95b8f068aa
commit
3ed503a986
2 files changed
+29
-3
No files matched your search
@@ -40,6 +40,24 @@ const cornerSideCross =
|
||||
(longEdgeEnd[0] - longEdgeStart[0]) * (0 - longEdgeStart[1]) -
|
||||
(longEdgeEnd[1] - longEdgeStart[1]) * (0 - longEdgeStart[0]);
|
||||
assert.ok(longEdgeCross * cornerSideCross > 0, 'long edge must bow toward the right-angle vertex');
|
||||
const islandContains = (point) => {
|
||||
let inside = false;
|
||||
for (let i = 0, j = sketchIsland.length - 1; i < sketchIsland.length; j = i++) {
|
||||
const a = sketchIsland[i],
|
||||
b = sketchIsland[j];
|
||||
if (a[1] > point[1] !== b[1] > point[1] && point[0] < ((b[0] - a[0]) * (point[1] - a[1])) / (b[1] - a[1]) + a[0])
|
||||
inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
};
|
||||
assert.ok(
|
||||
sketchIsland
|
||||
.slice(0, -1)
|
||||
.every(
|
||||
(point) => islandContains(point) || sketchIsland.some((item) => item[0] === point[0] && item[1] === point[1]),
|
||||
),
|
||||
'green contact points must stay inside island',
|
||||
);
|
||||
for (const crossing of [
|
||||
[
|
||||
[0, 0],
|
||||
|
||||
Reference in new issue
Block a user