Files

54 lines
1.4 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
clampOverlayTransform,
fitDisplayDimensions,
positionInCorner,
} from '../src/utils/editorMath.ts'
test('fitDisplayDimensions keeps source coordinates independent from display size', () => {
assert.deepEqual(fitDisplayDimensions({ width: 4032, height: 3024 }, 900), {
width: 900,
height: 675,
})
assert.deepEqual(fitDisplayDimensions({ width: 800, height: 600 }, 1200), {
width: 800,
height: 600,
})
})
test('clampOverlayTransform keeps the full overlay inside the source image', () => {
const result = clampOverlayTransform(400, 200, 950, -50, 0.5, {
width: 1000,
height: 500,
})
assert.equal(result.scale, 0.5)
assert.equal(result.width, 200)
assert.equal(result.height, 100)
assert.equal(result.x, 800)
assert.equal(result.y, 0)
})
test('clampOverlayTransform limits oversized overlays without changing aspect ratio', () => {
const result = clampOverlayTransform(2000, 1000, 0, 0, 1, {
width: 1000,
height: 400,
})
assert.equal(result.scale, 0.4)
assert.equal(result.width, 800)
assert.equal(result.height, 400)
})
test('positionInCorner uses a proportional margin and does not clip the object', () => {
const position = positionInCorner(
'bottom-right',
{ width: 200, height: 100 },
{ width: 1000, height: 500 },
)
assert.equal(position.x, 787.5)
assert.equal(position.y, 387.5)
})