/**
 * ---- Common bounding box utility ------------------------------------------
 */ import { RectangleSize } from "./dataTypes" ; param size export const getAspectRatio = ( size ) => size . width / size . height ; param size export const getArea = ( size ) => size . width * size . height ; /**
 * Parameter for `getScaleFactor()`.
 * `FIT_TO_BOX` checks both width and height and returns the smaller scale factor.
 */ export const enum FittingOption { FIT_TO_BOX = "FIT_TO_BOX" , FIT_WIDTH = "FIT_WIDTH" , FIT_HEIGHT = "FIT_HEIGHT" } param nonScaledSize param targetSize param fittingOption export const getScaleFactor = ( nonScaledSize , targetSize , fittingOption ? ) => { switch ( fittingOption ) { default : case FittingOption . FIT_TO_BOX : return Math . min ( targetSize . width / nonScaledSize . width , targetSize . height / nonScaledSize . height ) ; case FittingOption . FIT_WIDTH : return targetSize . width / nonScaledSize . width ; case FittingOption . FIT_HEIGHT : return targetSize . height / nonScaledSize . height ; } } ;