mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Restore collision optimization
This commit is contained in:
parent
fdd7420e65
commit
6e520fdbb9
1 changed files with 39 additions and 40 deletions
|
@ -212,10 +212,9 @@ const intersectRectanguloidWithLineSegment = (
|
||||||
const [sides, corners] = deconstructRectanguloidElement(element, offset);
|
const [sides, corners] = deconstructRectanguloidElement(element, offset);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
[
|
|
||||||
// Test intersection against the sides, keep only the valid
|
// Test intersection against the sides, keep only the valid
|
||||||
// intersection points and rotate them back to scene space
|
// intersection points and rotate them back to scene space
|
||||||
...sides
|
sides
|
||||||
.map((s) =>
|
.map((s) =>
|
||||||
lineSegmentIntersectionPoints(
|
lineSegmentIntersectionPoints(
|
||||||
lineSegment<GlobalPoint>(rotatedA, rotatedB),
|
lineSegment<GlobalPoint>(rotatedA, rotatedB),
|
||||||
|
@ -223,17 +222,18 @@ const intersectRectanguloidWithLineSegment = (
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.filter((x) => x != null)
|
.filter((x) => x != null)
|
||||||
.map((j) => pointRotateRads<GlobalPoint>(j!, center, element.angle)),
|
.map((j) => pointRotateRads<GlobalPoint>(j!, center, element.angle))
|
||||||
// Test intersection against the corners which are cubic bezier curves,
|
// Test intersection against the corners which are cubic bezier curves,
|
||||||
// keep only the valid intersection points and rotate them back to scene
|
// keep only the valid intersection points and rotate them back to scene
|
||||||
// space
|
// space
|
||||||
...corners
|
.concat(
|
||||||
|
corners
|
||||||
.flatMap((t) =>
|
.flatMap((t) =>
|
||||||
curveIntersectLineSegment(t, lineSegment(rotatedA, rotatedB)),
|
curveIntersectLineSegment(t, lineSegment(rotatedA, rotatedB)),
|
||||||
)
|
)
|
||||||
.filter((i) => i != null)
|
.filter((i) => i != null)
|
||||||
.map((j) => pointRotateRads(j, center, element.angle)),
|
.map((j) => pointRotateRads(j, center, element.angle)),
|
||||||
]
|
)
|
||||||
// Remove duplicates
|
// Remove duplicates
|
||||||
.filter(
|
.filter(
|
||||||
(p, idx, points) => points.findIndex((d) => pointsEqual(p, d)) === idx,
|
(p, idx, points) => points.findIndex((d) => pointsEqual(p, d)) === idx,
|
||||||
|
@ -266,8 +266,7 @@ const intersectDiamondWithLineSegment = (
|
||||||
const [sides, curves] = deconstructDiamondElement(element, offset);
|
const [sides, curves] = deconstructDiamondElement(element, offset);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
[
|
sides
|
||||||
...sides
|
|
||||||
.map((s) =>
|
.map((s) =>
|
||||||
lineSegmentIntersectionPoints(
|
lineSegmentIntersectionPoints(
|
||||||
lineSegment<GlobalPoint>(rotatedA, rotatedB),
|
lineSegment<GlobalPoint>(rotatedA, rotatedB),
|
||||||
|
@ -276,19 +275,19 @@ const intersectDiamondWithLineSegment = (
|
||||||
)
|
)
|
||||||
.filter((p): p is GlobalPoint => p != null)
|
.filter((p): p is GlobalPoint => p != null)
|
||||||
// Rotate back intersection points
|
// Rotate back intersection points
|
||||||
.map((p) => pointRotateRads<GlobalPoint>(p!, center, element.angle)),
|
.map((p) => pointRotateRads<GlobalPoint>(p!, center, element.angle))
|
||||||
...curves
|
.concat(
|
||||||
|
curves
|
||||||
.flatMap((p) =>
|
.flatMap((p) =>
|
||||||
curveIntersectLineSegment(p, lineSegment(rotatedA, rotatedB)),
|
curveIntersectLineSegment(p, lineSegment(rotatedA, rotatedB)),
|
||||||
)
|
)
|
||||||
.filter((p) => p != null)
|
.filter((p) => p != null)
|
||||||
// Rotate back intersection points
|
// Rotate back intersection points
|
||||||
.map((p) => pointRotateRads(p, center, element.angle)),
|
.map((p) => pointRotateRads(p, center, element.angle)),
|
||||||
]
|
)
|
||||||
// Remove duplicates
|
// Remove duplicates
|
||||||
.filter(
|
.filter(
|
||||||
(p, idx, points) =>
|
(p, idx, points) => points.findIndex((d) => pointsEqual(p, d)) === idx,
|
||||||
points.findIndex((d) => pointsEqual(p, d, 1e-3)) === idx,
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue