66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { preserveAnnotationScreenPositions } from '../src/utils/annotationGeometry.ts'
|
|
|
|
test('keeps annotation points at the same screen position when the origin moves', () => {
|
|
const annotations = [
|
|
{ points: [{ x: 30, y: 40 }, { x: 80, y: 90 }] },
|
|
{ points: [{ x: 12, y: 18 }] },
|
|
]
|
|
|
|
preserveAnnotationScreenPositions(
|
|
annotations,
|
|
{ x: 100, y: 200 },
|
|
{ x: 125, y: 230 }
|
|
)
|
|
|
|
assert.deepEqual(annotations, [
|
|
{ points: [{ x: 5, y: 10 }, { x: 55, y: 60 }] },
|
|
{ points: [{ x: -13, y: -12 }] },
|
|
])
|
|
assert.deepEqual(
|
|
annotations[0].points.map((point) => ({
|
|
x: 125 + point.x,
|
|
y: 230 + point.y,
|
|
})),
|
|
[{ x: 130, y: 240 }, { x: 180, y: 290 }]
|
|
)
|
|
})
|
|
|
|
test('does not move annotations when only the right or bottom edge changes', () => {
|
|
const annotations = [{ points: [{ x: 30, y: 40 }] }]
|
|
|
|
preserveAnnotationScreenPositions(
|
|
annotations,
|
|
{ x: 100, y: 200 },
|
|
{ x: 100, y: 200 }
|
|
)
|
|
|
|
assert.deepEqual(annotations, [{ points: [{ x: 30, y: 40 }] }])
|
|
})
|
|
|
|
test('preserves screen positions across repeated drags and an edge crossover', () => {
|
|
const annotations = [{ points: [{ x: 50, y: 60 }] }]
|
|
|
|
preserveAnnotationScreenPositions(
|
|
annotations,
|
|
{ x: 100, y: 100 },
|
|
{ x: 140, y: 130 }
|
|
)
|
|
preserveAnnotationScreenPositions(
|
|
annotations,
|
|
{ x: 140, y: 130 },
|
|
{ x: 300, y: 150 }
|
|
)
|
|
|
|
assert.deepEqual(annotations, [{ points: [{ x: -150, y: 10 }] }])
|
|
assert.deepEqual(
|
|
{
|
|
x: 300 + annotations[0].points[0].x,
|
|
y: 150 + annotations[0].points[0].y,
|
|
},
|
|
{ x: 150, y: 160 }
|
|
)
|
|
})
|