Units correctness: exact imperial entry, garden grid at dimension scale (#47) (#60)
Build image / build-and-push (push) Successful in 6s
Build image / build-and-push (push) Successful in 6s
Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #60.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
snapLocalToBedGrid,
|
||||
snapPoint,
|
||||
snapValue,
|
||||
visibleGridStepCm,
|
||||
worldToLocal,
|
||||
worldToScreen,
|
||||
zoomToFitRect,
|
||||
@@ -128,3 +129,34 @@ describe('grid snapping', () => {
|
||||
expect(p.x).toBeGreaterThanOrEqual(-60)
|
||||
})
|
||||
})
|
||||
|
||||
describe('visibleGridStepCm', () => {
|
||||
it('draws the true grid when its cells are already legible', () => {
|
||||
expect(visibleGridStepCm(30.48, 1, 6)).toBe(30.48)
|
||||
expect(visibleGridStepCm(10, 0.6, 6)).toBe(10) // exactly at the minimum
|
||||
})
|
||||
|
||||
it('coarsens to a multiple rather than fading out', () => {
|
||||
// The #47 failure: a 3cm grid at 0.84 px/cm is 2.5px per cell. Instead of
|
||||
// drawing nothing while snapping stays on, draw every 5th line (12.6px).
|
||||
expect(visibleGridStepCm(3, 0.84, 6)).toBe(15)
|
||||
expect(visibleGridStepCm(1, 0.84, 6)).toBe(10)
|
||||
})
|
||||
|
||||
it('only ever returns a whole multiple of the true grid', () => {
|
||||
for (const scale of [0.05, 0.3, 0.84, 1, 4]) {
|
||||
const step = visibleGridStepCm(7, scale, 6)
|
||||
expect(step).not.toBeNull()
|
||||
expect(Math.round(step! / 7) * 7).toBeCloseTo(step!, 9)
|
||||
expect(step! * scale).toBeGreaterThanOrEqual(6)
|
||||
}
|
||||
})
|
||||
|
||||
it('reports null for a degenerate grid rather than drawing nothing silently', () => {
|
||||
expect(visibleGridStepCm(0, 1, 6)).toBeNull()
|
||||
expect(visibleGridStepCm(-5, 1, 6)).toBeNull()
|
||||
expect(visibleGridStepCm(NaN, 1, 6)).toBeNull()
|
||||
expect(visibleGridStepCm(30, 0, 6)).toBeNull()
|
||||
expect(visibleGridStepCm(1e-9, 1, 6)).toBeNull() // beyond the coarsening cap
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user