Forked from ryan-digbil/bounding rect zoom and pan compensation
Created
July 18, 2016 01:13
-
-
Save gastonambrogi/13bb3c1cfa15dcaa2bfd036727b13692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getZoomCompensatedBoundingRect(fabricObject){ | |
//fabricObject is the object you want to get the boundingRect from | |
fabricObject.setCoords(); | |
var boundingRect = fabricObject.getBoundingRect(); | |
var zoom = canvas.getZoom(); | |
var viewportMatrix = canvas.viewportTransform; | |
//there is a bug in fabric that causes bounding rects to not be transformed by viewport matrix | |
//this code should compensate for the bug for now | |
boundingRect.top = (boundingRect.top - viewportMatrix[5]) / zoom; | |
boundingRect.left = (boundingRect.left - viewportMatrix[4]) / zoom; | |
boundingRect.width /= zoom; | |
boundingRect.height /= zoom; | |
return boundingRect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment