Fix findUsages/undo/node-lookup bugs, split Viewport and Editor, share command and inspector helpers
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1eb28314cf
commit
f140c2fd77
58 files changed
+1969
-1171
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { clamp, centreY, zoomFactor } from '../../src/ui/math';
|
||||
|
||||
describe('clamp', () => {
|
||||
it('keeps a value inside the range', () => {
|
||||
expect(clamp(5, 0, 10)).toBe(5);
|
||||
expect(clamp(-1, 0, 10)).toBe(0);
|
||||
expect(clamp(11, 0, 10)).toBe(10);
|
||||
});
|
||||
|
||||
it('lets the lower bound win when the range is inverted', () => {
|
||||
// A popup wider than the screen: pinning it to the left edge beats pinning it to the right.
|
||||
expect(clamp(5, 10, 0)).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('centreY', () => {
|
||||
it('centres on whole pixels', () => {
|
||||
expect(centreY(30, 20)).toBe(5);
|
||||
expect(centreY(31, 20)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('zoomFactor', () => {
|
||||
it('zooms in for a negative delta and out for a positive one', () => {
|
||||
expect(zoomFactor(-100)).toBeGreaterThan(1);
|
||||
expect(zoomFactor(100)).toBeLessThan(1);
|
||||
expect(zoomFactor(0)).toBe(1);
|
||||
});
|
||||
|
||||
it('returns exactly to the starting zoom after scrolling back', () => {
|
||||
// Why exponential: the scene view and the graph editor both rely on this cancelling out.
|
||||
expect(1 * zoomFactor(-120) * zoomFactor(120)).toBeCloseTo(1, 12);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user