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
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { union } = require('./junction-polygon-ops');
|
||||||
|
|
||||||
function buildPedestrianIsland({ key, ring, crossingKeys, provenance = 'inferred' }) {
|
function buildPedestrianIsland({ key, ring, crossingKeys, provenance = 'inferred' }) {
|
||||||
if (!key || !Array.isArray(ring) || ring.length < 4) return null;
|
if (!key || !Array.isArray(ring) || ring.length < 4) return null;
|
||||||
const adjacentCrossings = [...new Set(crossingKeys || [])];
|
const adjacentCrossings = [...new Set(crossingKeys || [])];
|
||||||
@@ -173,9 +175,12 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options =
|
|||||||
// roundover is pushed away from that vertex so the island does not intrude
|
// roundover is pushed away from that vertex so the island does not intrude
|
||||||
// into the vehicle swept area behind the two perpendicular crossings.
|
// into the vehicle swept area behind the two perpendicular crossings.
|
||||||
const hypotenuseMidpoint = midpoint(contacts[1][1], contacts[2][0]);
|
const hypotenuseMidpoint = midpoint(contacts[1][1], contacts[2][0]);
|
||||||
const hypotenuseControl = hypotenuseMidpoint.map((value, axis) => value * 0.55 + corner[axis] * 0.45);
|
const hypotenuseControl = hypotenuseMidpoint.map((value, axis) => value * 1.45 - corner[axis] * 0.45);
|
||||||
const innerMidpoint = midpoint(contacts[2][1], contacts[0][0]);
|
const innerMidpoint = midpoint(contacts[2][1], contacts[0][0]);
|
||||||
const innerControl = innerMidpoint.map((value, axis) => value * 1.35 - corner[axis] * 0.35);
|
// Keep the right-angle roundover outside the crossing intersection. Its
|
||||||
|
// control point is deliberately beyond the contact chord, leaving the
|
||||||
|
// vehicle-side edge at least one crossing half-depth from the corner.
|
||||||
|
const innerControl = innerMidpoint.map((value, axis) => value * 4 - corner[axis] * 3);
|
||||||
const controls = [firstTip, hypotenuseControl, innerControl];
|
const controls = [firstTip, hypotenuseControl, innerControl];
|
||||||
const steps = 16;
|
const steps = 16;
|
||||||
contacts.forEach((contact, index) => {
|
contacts.forEach((contact, index) => {
|
||||||
@@ -191,11 +196,14 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options =
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
ring.push(ring[0]);
|
ring.push(ring[0]);
|
||||||
|
const greenRing = [...vertices, vertices[0]];
|
||||||
|
const merged = union(ring, greenRing);
|
||||||
|
if (merged.length === 1 && merged[0].length === 1) ring.splice(0, ring.length, ...merged[0][0]);
|
||||||
return {
|
return {
|
||||||
status: 'solved',
|
status: 'solved',
|
||||||
reason: null,
|
reason: null,
|
||||||
ring,
|
ring,
|
||||||
greenRing: [...vertices, vertices[0]],
|
greenRing,
|
||||||
contacts,
|
contacts,
|
||||||
thirdContact,
|
thirdContact,
|
||||||
thirdCenter,
|
thirdCenter,
|
||||||
|
|||||||
@@ -40,6 +40,24 @@ const cornerSideCross =
|
|||||||
(longEdgeEnd[0] - longEdgeStart[0]) * (0 - longEdgeStart[1]) -
|
(longEdgeEnd[0] - longEdgeStart[0]) * (0 - longEdgeStart[1]) -
|
||||||
(longEdgeEnd[1] - longEdgeStart[1]) * (0 - longEdgeStart[0]);
|
(longEdgeEnd[1] - longEdgeStart[1]) * (0 - longEdgeStart[0]);
|
||||||
assert.ok(longEdgeCross * cornerSideCross > 0, 'long edge must bow toward the right-angle vertex');
|
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 [
|
for (const crossing of [
|
||||||
[
|
[
|
||||||
[0, 0],
|
[0, 0],
|
||||||
|
|||||||
Reference in new issue
Block a user