Fix for issue with incorrect calculations of which edge a line intersects with

This commit is contained in:
Knut Sveidqvist
2024-09-13 08:37:07 +02:00
parent d964893a5d
commit 05989d06fa

View File

@@ -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 };