Question
[JS] Page item (rectangle frame) width and height
Following is my attempt at writing a function for width and height. It appears to work on rotated and sheared objects. Can anyone tell me if I'm on the right track?
>function WidthAndHeight(myRectangle) // Returns an array [width,height]
{
]var myRectangleTopLeft = myRectangle.resolve(AnchorPoint.topLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);
var myRectangleTopRight = myRectangle.resolve(AnchorPoint.topRightAnchor, CoordinateSpaces.pasteboardCoordinates, true);
var myRectangleBottomLeft = myRectangle.resolve(AnchorPoint.bottomLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);
]var d1x = (myRectangleTopRight[0][0] - myRectangleTopLeft[0][0]);
var d1y = (myRectangleTopRight[0][1] - myRectangleTopLeft[0][1]);
var myWidth = hypotenuse(d1x,d1y);
var d2x = (myRectangleTopLeft[0][0] - myRectangleBottomLeft[0][0]);
var d2y = (myRectangleTopLeft[0][1] - myRectangleBottomLeft[0][1]);
var myHeight = hypotenuse(d2x,d2y);
]return [myWidth,myHeight];
]function hypotenuse(d1,d2)
{
]]return Math.sqrt ( Math.pow(d1,2) + Math.pow(d2,2) );
]}
}
>function WidthAndHeight(myRectangle) // Returns an array [width,height]
{
]var myRectangleTopLeft = myRectangle.resolve(AnchorPoint.topLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);
var myRectangleTopRight = myRectangle.resolve(AnchorPoint.topRightAnchor, CoordinateSpaces.pasteboardCoordinates, true);
var myRectangleBottomLeft = myRectangle.resolve(AnchorPoint.bottomLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);
]var d1x = (myRectangleTopRight[0][0] - myRectangleTopLeft[0][0]);
var d1y = (myRectangleTopRight[0][1] - myRectangleTopLeft[0][1]);
var myWidth = hypotenuse(d1x,d1y);
var d2x = (myRectangleTopLeft[0][0] - myRectangleBottomLeft[0][0]);
var d2y = (myRectangleTopLeft[0][1] - myRectangleBottomLeft[0][1]);
var myHeight = hypotenuse(d2x,d2y);
]return [myWidth,myHeight];
]function hypotenuse(d1,d2)
{
]]return Math.sqrt ( Math.pow(d1,2) + Math.pow(d2,2) );
]}
}