Created
November 5, 2014 02:46
-
-
Save ryan-digbil/21b6b0fc9974b3ab29be 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