mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
Fix for issue with incorrect calculations of which edge a line intersects with
This commit is contained in:
@@ -30,16 +30,21 @@ let nodeDB = new Map();
|
|||||||
|
|
||||||
const calcIntersectionPoint = (node, point) => {
|
const calcIntersectionPoint = (node, point) => {
|
||||||
const intersection = node.intersect(point);
|
const intersection = node.intersect(point);
|
||||||
const dx = intersection.x - node.x;
|
|
||||||
const dy = intersection.y - node.y;
|
|
||||||
|
|
||||||
let pos = 'l';
|
const dx = point.x - node.x;
|
||||||
|
const dy = point.y - node.y;
|
||||||
|
|
||||||
// Determine the position of the intersection relative to the node
|
const angle = Math.atan2(dy, dx) * (180 / Math.PI);
|
||||||
if (Math.abs(dx) > Math.abs(dy)) {
|
|
||||||
pos = dx > 0 ? 'r' : 'l'; // Right or left
|
let pos;
|
||||||
|
if (angle > -30 && angle <= 30) {
|
||||||
|
pos = 'r'; // Right
|
||||||
|
} else if (angle > 30 && angle <= 150) {
|
||||||
|
pos = 'b'; // Bottom
|
||||||
|
} else if (angle <= -30 && angle > -150) {
|
||||||
|
pos = 't'; // Top
|
||||||
} else {
|
} else {
|
||||||
pos = dy > 0 ? 'b' : 't'; // Bottom or top
|
pos = 'l'; // Left
|
||||||
}
|
}
|
||||||
|
|
||||||
return { x: intersection.x, y: intersection.y, pos };
|
return { x: intersection.x, y: intersection.y, pos };
|
||||||
|
Reference in New Issue
Block a user