2.0.1 • Published 3 years ago
@joeflateau/fit-rect v2.0.1
fit-rect
Fits one rectangle into another
Usage
fitRect(rect: Size, target: Rect, mode: FitMode): Rect
Parameters:
rect
- array w, h or x, y, w, htarget
- array w, h or x, y, w, hmode
- 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.