Files
mtdb_movie/common/resources/client/ui/interactions/utils/center-within-boundary.ts
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

31 lines
842 B
TypeScript
Executable File

import {InteractableRect} from '../interactable-event';
import {calcNewSizeFromAspectRatio} from './calc-new-size-from-aspect-ratio';
export function centerWithinBoundary(
boundary: Omit<InteractableRect, 'angle'>,
aspectRatio: number | null = null
): InteractableRect {
// set rect to the size of specified boundary
const rect: InteractableRect = {
width: boundary.width,
height: boundary.height,
top: 0,
left: 0,
angle: 0,
};
// maybe resize rect based on aspect ratio
if (aspectRatio) {
const newSize = calcNewSizeFromAspectRatio(
aspectRatio,
rect.width,
rect.height
);
rect.width = newSize.width;
rect.height = newSize.height;
}
// center the rect
rect.left = (boundary.width - rect.width) / 2;
rect.top = (boundary.height - rect.height) / 2;
return rect;
}