fix(editor): ceil2 never returns negative zero
This commit is contained in:
1 parent
755375a243
commit
8d690edae7
2 files changed
+9
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user