@joeflateau/fit-rect
v2.0.1
Published
Fits one rectangle into another
Readme
fit-rect

Fits one rectangle into another
Usage
fitRect(rect: Size, target: Rect, mode: FitMode): RectParameters:
rect- array [ w, h ] or [ x, y, w, h ]target- array [ w, h ] or [ x, y, w, h ]mode- string 'contain' (default) or 'cover'
Returns:
- array [ x, y, w, h ]
import { fitRect } from "fit-rect";
const rect = [16, 9];
const target = [200, 200, 400, 400];
const containedRect = fitRect(rect, target, "contain"); //[ 200, 287.5, 400, 225 ]
const coveringRect = fitRect(rect, target, "cover"); //[ 44.4, 200, 711.1, 400 ]License
MIT, see LICENSE.md for details.

