![]() |
![]() |
![]() |
---|---|---|
The class GraphicsObject | The Document and Graphics Classes | The class HierarchyNode |
In Sketch, each graphics object has a bounding rectangle and a coordinate rectangle. The sides of both rectangles are parallel to the coordinate axes.
The bounding rectangle is a rectangle that contains the entire object. Any marks the object or its children leave on the paper when printed lie in it. Ideally it should be the smallest such rectangle, but in practice it is sometimes difficult and indeed not always desirable to get exactly the smallest one. In any case, the bounding rectangle must contain the entire object.
Sketch uses the bounding rect for three purposes: to decide, which parts of the screen to redraw, as an aid when deciding which objects to select and to compute the BoundingBox of an EPS-File.
The coordinate rectangle is the smallest rectangle that contains the entire object without taking the line width into account. Sketch uses this rectangle for layout purposes and as the reference for interactive resize- and transformation operations.
The coordinate rectangle of an object should always lie completely inside of the bounding rectangle. Both rectangles may be (and for many object types they are) identical.
Since Bounded's variables are used for layout calculations, it provides access to and default behaviour for the layout point. The layout point is the point of an object that should lie exactly on the grid or on other special points.
By default, the layout point is the lower left corner of the coordinate rectangle. For images this is the lower left corner of the image which is not identical to the default if the image was transformed. For text objects with default justification, the layout point is the origin of the first letter, which is on the baseline, whereas the coordinate rectangle takes the descender into account.
Bounded provides the following instance variables
bounding_rect
:the bounding rectangle
coord_rect
:the coordinate rectangle
These instance variables are public attributes. Sketch uses
bounding_rect
to speed up the search for the object a mouse click
has hit (when the point the user clicked on is outside of the bounding
rect, the object cannot be hit). This test is significantly faster when
the bounding rectangle is read directly from an attribute instead of
accessed through a method call.
Bounded implements lazy evaluation for its public instance
variables (bounding_rect
and coord_rect
). When one of these
variables is not defined, Bounded's __getattr__
method invokes the method update_rects to compute the
rectangles and set the variables. To force recomputation when these
variables are read next, a derived class may call del_lazy_attrs.
This lazy evaluation mechanism is not limited to the instance variables men