From 8d690edae7023d9b5911be3f7adc4cef73267e5a Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 13:26:04 +0100 Subject: [PATCH] fix(editor): ceil2 never returns negative zero --- apps/app/src/editor/annotations/frame.ts | 4 +++- apps/app/tests/unit/annotations.frameBox.test.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/app/src/editor/annotations/frame.ts b/apps/app/src/editor/annotations/frame.ts index f744dd8c..f63f950a 100644 --- a/apps/app/src/editor/annotations/frame.ts +++ b/apps/app/src/editor/annotations/frame.ts @@ -34,7 +34,9 @@ const EPSILON = 1e-9 export const round2 = (value: number): number => Math.round(value * 100) / 100 export const floor2 = (value: number): number => Math.floor(value * 100 + EPSILON) / 100 -export const ceil2 = (value: number): number => Math.ceil(value * 100 - EPSILON) / 100 +/** `+ 0`: Math.ceil of a tiny negative is -0, which must not reach a view_box. */ +export const ceil2 = (value: number): number => + Math.ceil(value * 100 - EPSILON) / 100 + 0 /** * F from the composed root's `viewBox` attribute TEXT (the property `baseVal` is held in diff --git a/apps/app/tests/unit/annotations.frameBox.test.ts b/apps/app/tests/unit/annotations.frameBox.test.ts index d55905dc..5936f88b 100644 --- a/apps/app/tests/unit/annotations.frameBox.test.ts +++ b/apps/app/tests/unit/annotations.frameBox.test.ts @@ -226,6 +226,12 @@ describe('frameBox', () => { }) }) + it('toViewBox never returns negative zero at the origin', () => { + const box = toViewBox({ x: 0, y: 0, w: 10, h: 5 }) + expect(Object.is(box.min_x, 0)).toBe(true) + expect(Object.is(box.min_y, 0)).toBe(true) + }) + it('toViewBox ignores float noise on the hundredth grid', () => { expect(toViewBox({ x: 0.07, y: 0.1 + 0.2, w: 1, h: 1 })).toEqual({ min_x: 0.07,