mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix a particular routing issue
This commit is contained in:
parent
bc9f34e71e
commit
52445aeb68
2 changed files with 65 additions and 21 deletions
|
@ -66,6 +66,8 @@ import type {
|
||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
|
import { debugDrawBounds } from "@excalidraw/utils/visualdebug";
|
||||||
|
|
||||||
type GridAddress = [number, number] & { _brand: "gridaddress" };
|
type GridAddress = [number, number] & { _brand: "gridaddress" };
|
||||||
|
|
||||||
type Node = {
|
type Node = {
|
||||||
|
@ -1418,9 +1420,15 @@ const getElbowArrowData = (
|
||||||
BASE_PADDING,
|
BASE_PADDING,
|
||||||
),
|
),
|
||||||
boundsOverlap,
|
boundsOverlap,
|
||||||
hoveredStartElement && aabbForElement(hoveredStartElement),
|
hoveredStartElement
|
||||||
hoveredEndElement && aabbForElement(hoveredEndElement),
|
? aabbForElement(hoveredStartElement)
|
||||||
|
: startPointBounds,
|
||||||
|
hoveredEndElement ? aabbForElement(hoveredEndElement) : endPointBounds,
|
||||||
);
|
);
|
||||||
|
debugDrawBounds(endElementBounds);
|
||||||
|
// dynamicAABBs.forEach((aabb) => {
|
||||||
|
// debugDrawBounds(aabb);
|
||||||
|
// });
|
||||||
const startDonglePosition = getDonglePosition(
|
const startDonglePosition = getDonglePosition(
|
||||||
dynamicAABBs[0],
|
dynamicAABBs[0],
|
||||||
startHeading,
|
startHeading,
|
||||||
|
@ -1691,11 +1699,11 @@ const generateDynamicAABBs = (
|
||||||
a: Bounds,
|
a: Bounds,
|
||||||
b: Bounds,
|
b: Bounds,
|
||||||
common: Bounds,
|
common: Bounds,
|
||||||
startDifference?: [number, number, number, number],
|
startDifference: [number, number, number, number],
|
||||||
endDifference?: [number, number, number, number],
|
endDifference: [number, number, number, number],
|
||||||
disableSideHack?: boolean,
|
disableSideHack: boolean,
|
||||||
startElementBounds?: Bounds | null,
|
startElementBounds: Bounds,
|
||||||
endElementBounds?: Bounds | null,
|
endElementBounds: Bounds,
|
||||||
): Bounds[] => {
|
): Bounds[] => {
|
||||||
const startEl = startElementBounds ?? a;
|
const startEl = startElementBounds ?? a;
|
||||||
const endEl = endElementBounds ?? b;
|
const endEl = endElementBounds ?? b;
|
||||||
|
@ -1775,15 +1783,24 @@ const generateDynamicAABBs = (
|
||||||
(second[0] + second[2]) / 2,
|
(second[0] + second[2]) / 2,
|
||||||
(second[1] + second[3]) / 2,
|
(second[1] + second[3]) / 2,
|
||||||
];
|
];
|
||||||
if (b[0] > a[2] && a[1] > b[3]) {
|
if (
|
||||||
|
endElementBounds[0] > startElementBounds[2] &&
|
||||||
|
startElementBounds[1] > endElementBounds[3]
|
||||||
|
) {
|
||||||
// BOTTOM LEFT
|
// BOTTOM LEFT
|
||||||
const cX = first[2] + (second[0] - first[2]) / 2;
|
const cX = first[2] + (second[0] - first[2]) / 2;
|
||||||
const cY = second[3] + (first[1] - second[3]) / 2;
|
const cY = second[3] + (first[1] - second[3]) / 2;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
vectorCross(
|
vectorCross(
|
||||||
vector(a[2] - endCenterX, a[1] - endCenterY),
|
vector(
|
||||||
vector(a[0] - endCenterX, a[3] - endCenterY),
|
startElementBounds[2] - endCenterX,
|
||||||
|
startElementBounds[1] - endCenterY,
|
||||||
|
),
|
||||||
|
vector(
|
||||||
|
startElementBounds[0] - endCenterX,
|
||||||
|
startElementBounds[3] - endCenterY,
|
||||||
|
),
|
||||||
) > 0
|
) > 0
|
||||||
) {
|
) {
|
||||||
return [
|
return [
|
||||||
|
@ -1796,15 +1813,24 @@ const generateDynamicAABBs = (
|
||||||
[first[0], cY, first[2], first[3]],
|
[first[0], cY, first[2], first[3]],
|
||||||
[second[0], second[1], second[2], cY],
|
[second[0], second[1], second[2], cY],
|
||||||
];
|
];
|
||||||
} else if (a[2] < b[0] && a[3] < b[1]) {
|
} else if (
|
||||||
|
startElementBounds[2] < endElementBounds[0] &&
|
||||||
|
startElementBounds[3] < endElementBounds[1]
|
||||||
|
) {
|
||||||
// TOP LEFT
|
// TOP LEFT
|
||||||
const cX = first[2] + (second[0] - first[2]) / 2;
|
const cX = first[2] + (second[0] - first[2]) / 2;
|
||||||
const cY = first[3] + (second[1] - first[3]) / 2;
|
const cY = first[3] + (second[1] - first[3]) / 2;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
vectorCross(
|
vectorCross(
|
||||||
vector(a[0] - endCenterX, a[1] - endCenterY),
|
vector(
|
||||||
vector(a[2] - endCenterX, a[3] - endCenterY),
|
startElementBounds[0] - endCenterX,
|
||||||
|
startElementBounds[1] - endCenterY,
|
||||||
|
),
|
||||||
|
vector(
|
||||||
|
startElementBounds[2] - endCenterX,
|
||||||
|
startElementBounds[3] - endCenterY,
|
||||||
|
),
|
||||||
) > 0
|
) > 0
|
||||||
) {
|
) {
|
||||||
return [
|
return [
|
||||||
|
@ -1817,15 +1843,24 @@ const generateDynamicAABBs = (
|
||||||
[first[0], first[1], cX, first[3]],
|
[first[0], first[1], cX, first[3]],
|
||||||
[cX, second[1], second[2], second[3]],
|
[cX, second[1], second[2], second[3]],
|
||||||
];
|
];
|
||||||
} else if (a[0] > b[2] && a[3] < b[1]) {
|
} else if (
|
||||||
|
startElementBounds[0] > endElementBounds[2] &&
|
||||||
|
startElementBounds[3] < endElementBounds[1]
|
||||||
|
) {
|
||||||
// TOP RIGHT
|
// TOP RIGHT
|
||||||
const cX = second[2] + (first[0] - second[2]) / 2;
|
const cX = second[2] + (first[0] - second[2]) / 2;
|
||||||
const cY = first[3] + (second[1] - first[3]) / 2;
|
const cY = first[3] + (second[1] - first[3]) / 2;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
vectorCross(
|
vectorCross(
|
||||||
vector(a[2] - endCenterX, a[1] - endCenterY),
|
vector(
|
||||||
vector(a[0] - endCenterX, a[3] - endCenterY),
|
startElementBounds[2] - endCenterX,
|
||||||
|
startElementBounds[1] - endCenterY,
|
||||||
|
),
|
||||||
|
vector(
|
||||||
|
startElementBounds[0] - endCenterX,
|
||||||
|
startElementBounds[3] - endCenterY,
|
||||||
|
),
|
||||||
) > 0
|
) > 0
|
||||||
) {
|
) {
|
||||||
return [
|
return [
|
||||||
|
@ -1838,15 +1873,24 @@ const generateDynamicAABBs = (
|
||||||
[first[0], first[1], first[2], cY],
|
[first[0], first[1], first[2], cY],
|
||||||
[second[0], cY, second[2], second[3]],
|
[second[0], cY, second[2], second[3]],
|
||||||
];
|
];
|
||||||
} else if (a[0] > b[2] && a[1] > b[3]) {
|
} else if (
|
||||||
|
startElementBounds[0] > endElementBounds[2] &&
|
||||||
|
startElementBounds[1] > endElementBounds[3]
|
||||||
|
) {
|
||||||
// BOTTOM RIGHT
|
// BOTTOM RIGHT
|
||||||
const cX = second[2] + (first[0] - second[2]) / 2;
|
const cX = second[2] + (first[0] - second[2]) / 2;
|
||||||
const cY = second[3] + (first[1] - second[3]) / 2;
|
const cY = second[3] + (first[1] - second[3]) / 2;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
vectorCross(
|
vectorCross(
|
||||||
vector(a[0] - endCenterX, a[1] - endCenterY),
|
vector(
|
||||||
vector(a[2] - endCenterX, a[3] - endCenterY),
|
startElementBounds[0] - endCenterX,
|
||||||
|
startElementBounds[1] - endCenterY,
|
||||||
|
),
|
||||||
|
vector(
|
||||||
|
startElementBounds[2] - endCenterX,
|
||||||
|
startElementBounds[3] - endCenterY,
|
||||||
|
),
|
||||||
) > 0
|
) > 0
|
||||||
) {
|
) {
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -296,8 +296,8 @@ describe("elbow arrow ui", () => {
|
||||||
|
|
||||||
expect(arrow.points).toCloselyEqualPoints([
|
expect(arrow.points).toCloselyEqualPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[34.9292, 0],
|
[34.7084, 0],
|
||||||
[34.48768, 164.6246],
|
[34.7084, 164.6246],
|
||||||
[104.333, 164.6246],
|
[104.333, 164.6246],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue