Contents

CGGeometry

Various structures and associated functions for 2D geometric primitives.

Overview

The data structure CGPoint represents a point in a two-dimensional coordinate system. The data structure CGRect represents the location and dimensions of a rectangle. The data structure CGSize represents the dimensions of width and height.

A CGPoint, CGRect, or CGSize structure does not explicitly define the unit of measure for its member quantities. A point’s x- and y-coordinates or a size’s width and height are unitless quantities—whether such measurements are treated as pixels, scale-factor-independent points, texture elements (texels), or some other unit depends on the API using the measurement, and on the context in which that API is used. For example, a CGRect structure specifying the frame of an NSView or UIView object defines the view’s dimensions in points, not pixels. However, the effects of using a CGPoint structure in a CGContext drawing operation depend on the scale factor associated with that context. Where not otherwise specified, you can assume that a CGPoint, CGRect, or CGSize structure is defined in points, not pixels. (For details, see Drawing and Printing Guide for iOS or High Resolution Guidelines for OS X.)

The height and width stored in a CGRect data structure can be negative. For example, a rectangle with an origin of [0.0, 0.0] and a size of [10.0,10.0] is exactly equivalent to a rectangle with an origin of [10.0, 10.0] and a size of [-10.0,-10.0]. Your application can standardize a rectangle—that is, ensure that the height and width are stored as positive values—by calling the CGRectStandardize function. All functions described in this reference that take CGRect data structures as inputs implicitly standardize those rectangles before calculating their results. For this reason, your applications should avoid directly reading and writing the data stored in the CGRect data structure. Instead, use the functions described here to manipulate rectangles and to retrieve their characteristics.

Topics

Creating a Dictionary Representation from a Geometric Primitive

Creating a Geometric Primitive from a Dictionary Representation

Creating a Geometric Primitive from Values

Modifying Rectangles

Comparing Values

Checking for Membership

Getting Min, Mid, and Max Values

Getting Height and Width

Checking Rectangle Characteristics

Data Types

Constants

See Also

Related Documentation

  • Quartz 2D Programming Guide