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