Skip to content

Commit

Permalink
Test both directions when checking for segment equality
Browse files Browse the repository at this point in the history
  • Loading branch information
r-flash committed Oct 27, 2024
1 parent 2615b4a commit a435a3d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/path-boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ function findVertices(
}
break;
case "A":
// TODO: explain
if (edge.seg[5] === false) {
return [];
}
Expand All @@ -366,7 +367,6 @@ function findVertices(
}

const vertexPairId = `${getVertexId(startVertex)}:${getVertexId(endVertex)}`;
// TODO: check other direction
if (hasOwn(vertexPairIdToEdges, vertexPairId)) {
const existingEdge = vertexPairIdToEdges[vertexPairId].find(
(other) => segmentsEqual(other[0].seg, edge.seg, EPS.point),
Expand All @@ -378,6 +378,24 @@ function findVertices(
}
}

const vertexPairIdInv = `${getVertexId(endVertex)}:${getVertexId(startVertex)}`;
if (hasOwn(vertexPairIdToEdges, vertexPairIdInv)) {
const reversedSeg = reversePathSegment(edge.seg);
const existingEdge = vertexPairIdToEdges[vertexPairIdInv].find(
(other) => segmentsEqual(other[0].seg, reversedSeg, EPS.point),
);
if (existingEdge) {
if (existingEdge[0].parent === edge.parent) {
// discard "there and back" pairs
return [];
}

existingEdge[1].parent |= edge.parent;
existingEdge[2].parent |= edge.parent;
return [];
}
}

const fwdEdge: MajorGraphEdge = {
...edge,
incidentVertices: [startVertex, endVertex],
Expand Down

0 comments on commit a435a3d

Please sign in to comment.