rect-zoom-transforms

1.0.1 • Public • Published

rect-zoom-transforms

Calculate the scaling and translations required to zoom and pan from one rectangle to another rectangle within the first.

Usage

var rectZoomTransforms = require('rect-zoom-transforms');

// originalRect and targetRect are expected to have the properties `x`, `y`, `width`, `height`.
rectZoomTransforms(originalRect, targetRect);

Returns an object:

{
  scale: {
    // x and y are numbers between 0 and 1
    x,
    y
  },
  translate: {
    // x and y are numeric translation distances in pixels
    x,
    y,
    // xPercent and yPercent are values between 0 and 100
    xPercent,
    yPercent 
  }
}

License

MIT

Package Sidebar

Install

npm i rect-zoom-transforms

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • cheapsteak