fix(editor): Diamond hit test shortcut (#11631)

---------

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Márk Tolmács
2026-07-22 22:39:16 +02:00
committed by GitHub
parent 91b78903ab
commit e6ae6bf057
3 changed files with 23 additions and 12 deletions
+2 -6
View File
@@ -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)),
);
};
+14 -4
View File
@@ -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>(
+7 -2
View File
@@ -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);