|
|
@ -8,6 +8,10 @@ import {
|
|
|
|
getLinePoints
|
|
|
|
getLinePoints
|
|
|
|
} from "./bounds";
|
|
|
|
} from "./bounds";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isElementDraggableFromInside(element: ExcalidrawElement): boolean {
|
|
|
|
|
|
|
|
return element.backgroundColor !== "transparent" || element.isSelected;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function hitTest(
|
|
|
|
export function hitTest(
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
element: ExcalidrawElement,
|
|
|
|
x: number,
|
|
|
|
x: number,
|
|
|
@ -51,7 +55,7 @@ export function hitTest(
|
|
|
|
ty /= t;
|
|
|
|
ty /= t;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (element.backgroundColor !== "transparent") {
|
|
|
|
if (isElementDraggableFromInside(element)) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
a * tx - (px - lineThreshold) >= 0 && b * ty - (py - lineThreshold) >= 0
|
|
|
|
a * tx - (px - lineThreshold) >= 0 && b * ty - (py - lineThreshold) >= 0
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -61,7 +65,7 @@ export function hitTest(
|
|
|
|
} else if (element.type === "rectangle") {
|
|
|
|
} else if (element.type === "rectangle") {
|
|
|
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
|
|
|
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
|
|
|
|
|
|
|
|
|
|
|
|
if (element.backgroundColor !== "transparent") {
|
|
|
|
if (isElementDraggableFromInside(element)) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
x > x1 - lineThreshold &&
|
|
|
|
x > x1 - lineThreshold &&
|
|
|
|
x < x2 + lineThreshold &&
|
|
|
|
x < x2 + lineThreshold &&
|
|
|
@ -94,7 +98,7 @@ export function hitTest(
|
|
|
|
leftY
|
|
|
|
leftY
|
|
|
|
] = getDiamondPoints(element);
|
|
|
|
] = getDiamondPoints(element);
|
|
|
|
|
|
|
|
|
|
|
|
if (element.backgroundColor !== "transparent") {
|
|
|
|
if (isElementDraggableFromInside(element)) {
|
|
|
|
// TODO: remove this when we normalize coordinates globally
|
|
|
|
// TODO: remove this when we normalize coordinates globally
|
|
|
|
if (topY > bottomY) [bottomY, topY] = [topY, bottomY];
|
|
|
|
if (topY > bottomY) [bottomY, topY] = [topY, bottomY];
|
|
|
|
if (rightX < leftX) [leftX, rightX] = [rightX, leftX];
|
|
|
|
if (rightX < leftX) [leftX, rightX] = [rightX, leftX];
|
|
|
|