Skip to content

cheapsteak/rect-zoom-transforms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published