SceneNode.boundsInParent & SceneNode.topLeftInParent for a layer inside a Group are incorrect. XD Version 44.0.12.7


See the attached screenshot.
BUG: The boundsInParent for Rectangle should have X = 0 and Y= 0 as the rectangle starts at the top left its parent layer i.e. the Group. Same issue with SceneNode.topLeftInParent

XD Version 44.0.12.7. macOS Catalina.

I am not sure if this is inconsistency or expected behaviour but the X, Y values in the transform panel are confusing also. X, Y for a layers are always in Artboard’s co-ordinate system, irrespective of the layer’s parent but the X,Y for Artboard are in Scene’s co-ordinate system. One would expect it either in Scene’s or parent’s co-ordinate system.

I believe this is working as expected. XD’s coordinate system can be confusing, and there is this document to help explain:

https://www.adobe.io/xd/uxp/develop/plugin-development/xd-concepts/coordinate-spaces-and-units/

Part of the confusion is that the “parent” in the boundsInParent and topLeftInParent properties are not referring to the SceneNode’s parent SceneNode (which in your example is the group containing the rectangles). Rather the “parent” being referred to is the rectangle’s path bounding box. And the bounds are not relative to the rectangle’s path bounding box. Instead they are relative to the containing artboard.

Thanks for the reply. Of Course this is confusing. The concept of node’s parent and the parent when calculating bounds is different. This should be documented with a clear example. Probably the API should be named boundsInBoundingPath(…)

1 Like

I wrote a utility class (log.getBoundsInGroup()) to get the specific bounds you are looking for:

Disclaimer: There are a few issues with it in some cases when things like lines have no height or width. You’ll have to verify it for your use case but it should give you a starting point.

I’ll add that I wouldn’t mind an update of the native SceneNode.getBounds() with a bit more scopes for cases like the ones you mentioned.

1 Like