mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-10-19 16:15:56 +00:00
fix(editor): Diamond hit test shortcut (#11631)
--------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
@@ -75,9 +75,7 @@ const distanceToRectanguloidElement = (
|
||||
|
||||
return Math.min(
|
||||
...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
|
||||
...corners
|
||||
.map((a) => curvePointDistance(a, rotatedPoint))
|
||||
.filter((d): d is number => d !== null),
|
||||
...corners.map((a) => curvePointDistance(a, rotatedPoint)),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -104,9 +102,7 @@ const distanceToDiamondElement = (
|
||||
|
||||
return Math.min(
|
||||
...sides.map((s) => distanceToLineSegment(rotatedPoint, s)),
|
||||
...curves
|
||||
.map((a) => curvePointDistance(a, rotatedPoint))
|
||||
.filter((d): d is number => d !== null),
|
||||
...curves.map((a) => curvePointDistance(a, rotatedPoint)),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -431,10 +431,20 @@ export function deconstructDiamondElement(
|
||||
|
||||
const baseCorners = getDiamondBaseCorners(element, offset);
|
||||
|
||||
const corners = baseCorners.map(
|
||||
(corner) =>
|
||||
curveCatmullRomCubicApproxPoints(curveOffsetPoints(corner, offset))!,
|
||||
);
|
||||
const corners =
|
||||
offset > 0
|
||||
? baseCorners.map(
|
||||
(corner) =>
|
||||
curveCatmullRomCubicApproxPoints(
|
||||
curveOffsetPoints(corner, offset),
|
||||
)!,
|
||||
)
|
||||
: [
|
||||
[baseCorners[0]],
|
||||
[baseCorners[1]],
|
||||
[baseCorners[2]],
|
||||
[baseCorners[3]],
|
||||
];
|
||||
|
||||
const sides = [
|
||||
lineSegment<GlobalPoint>(
|
||||
|
||||
@@ -267,7 +267,10 @@ export function curveClosestPoint<Point extends GlobalPoint | LocalPoint>(
|
||||
pointDistance(p, bezierEquation(c, t)),
|
||||
);
|
||||
|
||||
if (!solution) {
|
||||
// `solution` is only nullish when the search window is narrower than the
|
||||
// tolerance (e.g. a caller-supplied tolerance larger than the window). A
|
||||
// legitimate solution of `t = 0` must not be treated as a failure.
|
||||
if (solution == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -287,8 +290,10 @@ export function curvePointDistance<Point extends GlobalPoint | LocalPoint>(
|
||||
) {
|
||||
const closest = curveClosestPoint(c, p);
|
||||
|
||||
// No closest point found: report an "infinitely far" distance so this curve
|
||||
// is never mistaken for the nearest component when fed into `Math.min`.
|
||||
if (!closest) {
|
||||
return 0;
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return pointDistance(p, closest);
|
||||
|
||||
Reference in New Issue
Block a user