Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 128x 128x | import type { Point2 } from '../../../types';
import type { CameraScaleMode } from '../ViewportCameraTypes';
export type PlanarScaleInput = number | Point2;
export type PlanarScale = Point2;
export const MIN_PLANAR_SCALE = 0.001;
const PLANAR_SCALE_MODES = new Set<string>([
'fit',
'fitAspect',
'fitWidth',
'fitHeight',
'absolute',
]);
function normalizeScaleValue(value: unknown): number {
return typeof value === 'number' && Number.isFinite(value)
? Math.max(value, MIN_PLANAR_SCALE)
: 1;
}
export function normalizePlanarScale(scale?: PlanarScaleInput): PlanarScale {
if (Array.isArray(scale)) {
return [normalizeScaleValue(scale[0]), normalizeScaleValue(scale[1])];
}
const scalarScale = normalizeScaleValue(scale);
return [scalarScale, scalarScale];
}
export function clonePlanarScale(scale?: PlanarScaleInput): PlanarScale {
return normalizePlanarScale(scale);
}
export function getPlanarScaleZoom(scale?: PlanarScaleInput): number {
return normalizePlanarScale(scale)[1];
}
export function normalizePlanarScaleMode(scaleMode?: string): CameraScaleMode {
return PLANAR_SCALE_MODES.has(scaleMode || '')
? (scaleMode as CameraScaleMode)
: 'fit';
}
export function getPlanarScaleRatio(scale?: PlanarScaleInput): number {
const [scaleX, scaleY] = normalizePlanarScale(scale);
return scaleX / scaleY;
}
|