From 4d0dd59fcbbf8f9eb04de4089d09b7a3d818c65f Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Thu, 3 Dec 2026 23:35:10 +0100 Subject: [PATCH] fix(editor): keep the dashed remainder of a wedge's ellipse still when its arc changes --- .../excalidraw/renderer/interactiveScene.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/excalidraw/renderer/interactiveScene.ts b/packages/excalidraw/renderer/interactiveScene.ts index 9f64cbdbc2..23aa966518 100644 --- a/packages/excalidraw/renderer/interactiveScene.ts +++ b/packages/excalidraw/renderer/interactiveScene.ts @@ -952,26 +952,38 @@ const renderEllipseArcRemainder = ( ) => { const { start, sweep } = element.arc; const zoom = appState.zoom.value; + const rx = element.width / 2; + const ry = element.height / 2; + + // a whole number of dashes around the ellipse, so that the pattern has no + // seam where it wraps (Ramanujan's approximation of the perimeter) + const h = rx + ry > 0 ? ((rx - ry) / (rx + ry)) ** 2 : 0; + const perimeter = + Math.PI * (rx + ry) * (1 + (3 * h) / (10 + Math.sqrt(4 - 3 * h))); + const dashCount = Math.max(1, Math.round((perimeter * zoom) / 14)); + const dashPeriod = perimeter / dashCount; context.save(); context.translate( - appState.scrollX + element.x + element.width / 2, - appState.scrollY + element.y + element.height / 2, + appState.scrollX + element.x + rx, + appState.scrollY + element.y + ry, ); context.rotate(element.angle); + + // The dashes belong to the whole ellipse and the wedge only hides its share + // of them. Stroking just the remainder would start the pattern at the + // wedge's end, and the dashes would crawl as the arc changes. + context.beginPath(); + context.moveTo(0, 0); + context.ellipse(0, 0, rx * 2, ry * 2, 0, start + sweep, start + Math.PI * 2); + context.closePath(); + context.clip(); + context.lineWidth = 1 / zoom; - context.setLineDash([8 / zoom, 6 / zoom]); + context.setLineDash([(dashPeriod * 8) / 14, (dashPeriod * 6) / 14]); context.strokeStyle = getThemedColor("rgba(0, 0, 0, 0.35)", appState.theme); context.beginPath(); - context.ellipse( - 0, - 0, - element.width / 2, - element.height / 2, - 0, - start + sweep, - start + Math.PI * 2, - ); + context.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2); context.stroke(); context.restore(); };