mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-23 17:30:44 +02:00
fix: Actual segments not approximations
This commit is contained in:
@@ -322,38 +322,42 @@ export const getElementLineSegments = (
|
||||
|
||||
if (shape.type === "polycurve") {
|
||||
const curves = shape.data;
|
||||
const points = curves
|
||||
.map((curve) => pointsOnBezierCurves(curve, 10))
|
||||
.flat();
|
||||
const pointsOnCurves = curves.map((curve) =>
|
||||
pointsOnBezierCurves(curve, 10),
|
||||
);
|
||||
|
||||
const segments: LineSegment<GlobalPoint>[] = [];
|
||||
|
||||
let i = 0;
|
||||
if (
|
||||
(isLineElement(element) && !element.polygon) ||
|
||||
isArrowElement(element)
|
||||
) {
|
||||
for (const points of pointsOnCurves) {
|
||||
let i = 0;
|
||||
|
||||
while (i < points.length - 1) {
|
||||
const p1 = pointFrom(points[i + 1][0], points[i][1]);
|
||||
const p2 = pointFrom(points[i][0], points[i + 1][1]);
|
||||
const alignsWithStart = pointDistance(p1, points[0] as GlobalPoint) < 1;
|
||||
const alignsWithEnd =
|
||||
pointDistance(p2, points[points.length - 1] as GlobalPoint) < 1;
|
||||
|
||||
// Avoid closing the polycurve for non-polygon lines and arrows
|
||||
if (
|
||||
((isLineElement(element) && !element.polygon) ||
|
||||
isArrowElement(element)) &&
|
||||
alignsWithStart &&
|
||||
alignsWithEnd
|
||||
) {
|
||||
i++;
|
||||
continue;
|
||||
while (i < points.length - 1) {
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const points = pointsOnCurves.flat();
|
||||
let i = 0;
|
||||
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
while (i < points.length - 1) {
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return segments;
|
||||
|
Reference in New Issue
Block a user