diff --git a/packages/element/src/bounds.ts b/packages/element/src/bounds.ts index 0d57e39333..0f3970db80 100644 --- a/packages/element/src/bounds.ts +++ b/packages/element/src/bounds.ts @@ -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[] = []; - 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;