Skip to content

Commit

Permalink
#5237 Fix for weird line intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Aug 22, 2024
1 parent 53bff11 commit 19d46fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 16 additions & 13 deletions packages/mermaid/src/rendering-util/rendering-elements/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,22 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
const tail = startNode;
var head = endNode;

if (head.intersect && tail.intersect) {
points = points.slice(1, edge.points.length - 1);
points.unshift(tail.intersect(points[0]));
log.debug(
'Last point APA12',
edge.start,
'-->',
edge.end,
points[points.length - 1],
head,
head.intersect(points[points.length - 1])
);
points.push(head.intersect(points[points.length - 1]));
if (head.intersect && tail.intersect && points.length > 2) {
const initialStartPoint = Object.assign({}, points[0]);
const newEnd = head.intersect(points[points.length - 2]);

const newStart = tail.intersect(points[1]);
if (newStart.x && newStart.y) {
points.unshift(newStart);
} else {
points.unshift(initialStartPoint);
}
if (newEnd.x && newEnd.y) {
const lastPoint = points[points.length - 1];
if (lastPoint.x !== newEnd.x && lastPoint.y !== newEnd.y) {
points.push(newEnd);
}
}
}
if (edge.toCluster) {
log.info('to cluster abc88', clusterDb.get(edge.toCluster));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ export const question = async (parent: SVGAElement, node: Node): Promise<SVGAEle
updateNodeBounds(node, polygon);

node.intersect = function (point) {
log.info('Intersect called SPLIT');
log.debug(
'APA12 Intersect called SPLIT\npoint:',
point,
'\nnode:\n',
node,
'\nres:',
intersect.polygon(node, points, point)
);
return intersect.polygon(node, points, point);
};

Expand Down

0 comments on commit 19d46fc

Please sign in to comment.