utils.ts 332 B

123456789101112
  1. export function getMiddle(value: number, [min, max]) {
  2. return Math.min(Math.max(value, min), max);
  3. }
  4. export function getAspectHW(width: number, height: number, aspect: number) {
  5. if (width / height > aspect) {
  6. width = height * aspect;
  7. } else {
  8. height = width / aspect;
  9. }
  10. return [width, height];
  11. }