mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-05 18:55:28 +03:00
fix(editor): keep the dashed remainder of a wedge's ellipse still when its arc changes
This commit is contained in:
1 file changed
+24
-12
@@ -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();
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user