mirror of
https://github.com/excalidraw/excalidraw.git
synced 2024-11-02 03:25:53 +01:00
fix: Yet more patching of intersect code (#8352)
* Yet more patching of intersect code
This commit is contained in:
parent
1ea5b26f25
commit
99b91c46f7
@ -41,6 +41,7 @@ import {
|
||||
isElbowArrow,
|
||||
isFrameLikeElement,
|
||||
isLinearElement,
|
||||
isRectangularElement,
|
||||
isTextElement,
|
||||
} from "./typeChecks";
|
||||
import type { ElementUpdate } from "./mutateElement";
|
||||
@ -751,7 +752,7 @@ export const bindPointToSnapToElementOutline = (
|
||||
const aabb = bindableElement && aabbForElement(bindableElement);
|
||||
|
||||
if (bindableElement && aabb) {
|
||||
// TODO: Dirty hack until tangents are properly calculated
|
||||
// TODO: Dirty hacks until tangents are properly calculated
|
||||
const intersections = [
|
||||
...intersectElementWithLine(
|
||||
bindableElement,
|
||||
@ -759,24 +760,32 @@ export const bindPointToSnapToElementOutline = (
|
||||
[point[0], point[1] + 2 * bindableElement.height],
|
||||
FIXED_BINDING_DISTANCE,
|
||||
elementsMap,
|
||||
).map((i) =>
|
||||
distanceToBindableElement(bindableElement, i, elementsMap) >=
|
||||
bindableElement.height / 2
|
||||
).map((i) => {
|
||||
if (!isRectangularElement(bindableElement)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
const d = distanceToBindableElement(bindableElement, i, elementsMap);
|
||||
return d >= bindableElement.height / 2 || d < FIXED_BINDING_DISTANCE
|
||||
? ([point[0], -1 * i[1]] as Point)
|
||||
: ([point[0], i[1]] as Point),
|
||||
),
|
||||
: ([point[0], i[1]] as Point);
|
||||
}),
|
||||
...intersectElementWithLine(
|
||||
bindableElement,
|
||||
[point[0] - 2 * bindableElement.width, point[1]],
|
||||
[point[0] + 2 * bindableElement.width, point[1]],
|
||||
FIXED_BINDING_DISTANCE,
|
||||
elementsMap,
|
||||
).map((i) =>
|
||||
distanceToBindableElement(bindableElement, i, elementsMap) >=
|
||||
bindableElement.width / 2
|
||||
).map((i) => {
|
||||
if (!isRectangularElement(bindableElement)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
const d = distanceToBindableElement(bindableElement, i, elementsMap);
|
||||
return d >= bindableElement.width / 2 || d < FIXED_BINDING_DISTANCE
|
||||
? ([-1 * i[0], point[1]] as Point)
|
||||
: ([i[0], point[1]] as Point),
|
||||
),
|
||||
: ([i[0], point[1]] as Point);
|
||||
}),
|
||||
];
|
||||
|
||||
const heading = headingForPointFromElement(bindableElement, aabb, point);
|
||||
|
@ -176,6 +176,23 @@ export const isRectanguloidElement = (
|
||||
);
|
||||
};
|
||||
|
||||
// TODO: Remove this when proper distance calculation is introduced
|
||||
// @see binding.ts:distanceToBindableElement()
|
||||
export const isRectangularElement = (
|
||||
element?: ExcalidrawElement | null,
|
||||
): element is ExcalidrawBindableElement => {
|
||||
return (
|
||||
element != null &&
|
||||
(element.type === "rectangle" ||
|
||||
element.type === "image" ||
|
||||
element.type === "text" ||
|
||||
element.type === "iframe" ||
|
||||
element.type === "embeddable" ||
|
||||
element.type === "frame" ||
|
||||
element.type === "magicframe")
|
||||
);
|
||||
};
|
||||
|
||||
export const isTextBindableContainer = (
|
||||
element: ExcalidrawElement | null,
|
||||
includeLocked = true,
|
||||
|
Loading…
Reference in New Issue
Block a user