fit-rect

stable

Fits one rectangle into another

Usage

NPM

fitRect(rect, target, mode)

Parameters:
rect - array [x,y,w,h]
target - array [x,y,w,h]
mode - string 'contain' (default) or 'cover'

Returns rectangle [x,y,w,h]

var fitRect = require('fit-rect');

var rect = [0, 0, 16, 9];
var target = [200, 200, 400, 400];
var containedRect = fitRect(rect, target, 'contain'); //[ 200, 287.5, 400, 225 ]
var coveringRect = fitRect(rect, target, 'cover');     //[ 44.4, 200, 711.1, 400 ]

License

MIT, see LICENSE.md for details.