Graphics functions

All 2D graphics classes have bounds. The bounds of a graphic are defined by the smallest TGRect that encloses the geometry of the graphic. Figure 27 shows the MGraphic pure virtual functions for finding the bounds. GetGeometricBounds does not take into account the attribute information when calculating the bounds, but GetLooseFitBounds does. These functions are described below.

NOTE For a loop or curve geometry, the bounds enclose the control points.

Computing the bounds of a graphic can occur frequently and use a lot of resources. You may want to cache these graphics for efficiency. (Caching is described in Chapter 9.) You might use these functions for a number of reasons depending upon your program requirements. The most common use is to determine whether a graphic is selected (hit or picked).


GetGeometricBounds

GetGeometricBounds returns the smallest TGRect that fully encloses the geometry. It uses only the geometry information to compute the bounding rectangle (the bundle information is not taken into account).

    TGRect MGraphic::GetGeometricBounds() const = 0;

GetLooseFitBounds

GetLooseFitBounds takes the drawing port as a parameter and
returns a TGRect that encloses the entire graphic taking into account the bundle information. Bundle attributes are described in Chapter 7. It uses the drawing attribute information to compute the bounding rectangle. GetLooseFitBounds returns a bounding rectangle that is either the same or larger than the GetGeometricBounds bounding rectangle.

    TGRect MGraphic::GetLooseFitBounds( const TGrafPort* = NIL ) const;
Because the implementation for GetLooseFitBounds calls GetBounds on the geometry first, there can be a small amount of inaccuracy. The returned TGRect might enclose extra points beyond the graphic and its bundle information.

Speed and accuracy

GetGeometricBounds and GetLooseFitBounds are fast and suitable when speed is more important than accuracy. For example, you could use either one for quick rejection during clipping operations. However, if accuracy is more important than speed, use TBoundsMaker (described below) to compute the bounds with bundle information taken into account.

Figure 28 shows the difference between the amount of information enclosed in the returned TGRect (bounding rectangle) when you use GetGeometricBounds and GetLooseFitBounds. The triangle in the figure has an attribute bundle that specifies a fill, a wide pen width, and an outset frame. The outset frame means that the frame sits along the outside edge of the fill. See Chapter 7 for more information on fills and frames.

The figure shows that GetGeometricBounds returns a TGRect that does not include the line width, and GetLooseFitBounds returns a TGRect that includes the line width and extra points beyond the line width.

NOTE The fill and any cap or joint styles that might be specified in the attribute bundle are not taken into account when GetLooseFitBounds is used.



[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker