From cb297eae57373b92d98392925421c0fa60a226d3 Mon Sep 17 00:00:00 2001 From: u8array Date: Sun, 10 May 2026 10:13:49 +0200 Subject: [PATCH] fix(ruler): round display mm on rotated labels to drop float noise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the ruler is reversed for 180°/270° rotated labels, computing `labelXxxMm - mm` reintroduces IEEE-754 artefacts (e.g. 100 - 30 = 70.00000000000001) on top of the already-rounded `mm`. The result rendered as tick labels with up to 12 trailing decimals. Re-round at the subtraction site, mirroring the existing rounding on the `mm` accumulator. `rulerLabel` stays a neutral formatter. --- src/components/Canvas/Ruler.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Canvas/Ruler.tsx b/src/components/Canvas/Ruler.tsx index 3f968231..bf496cca 100644 --- a/src/components/Canvas/Ruler.tsx +++ b/src/components/Canvas/Ruler.tsx @@ -64,7 +64,12 @@ export function Ruler({ strokeWidth={isMajor ? 1 : 0.5} listening={false} />, ); - const displayMm = horizontalReversed ? labelWidthMm - mm : mm; + // `mm` was rounded above; subtraction reintroduces IEEE-754 artefacts + // (e.g. 100 - 30 = 70.00000000000001), so re-round to keep tick labels + // free of trailing-decimal noise on rotated labels. + const displayMm = horizontalReversed + ? Math.round((labelWidthMm - mm) * 1000) / 1000 + : mm; if (isMajor && displayMm > 0 && displayMm <= labelWidthMm) { els.push( , ); - const displayMm = verticalReversed ? labelHeightMm - mm : mm; + const displayMm = verticalReversed + ? Math.round((labelHeightMm - mm) * 1000) / 1000 + : mm; if (isMajor && displayMm > 0 && displayMm <= labelHeightMm) { els.push(