<!--
{
  "documentType" : "article",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/cggeometry",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "CGGeometry"
}
-->

# CGGeometry

Various structures and associated functions for 2D geometric primitives.

## Discussion

The data structure <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> represents a point in a two-dimensional coordinate system. The data structure <doc://com.apple.documentation/documentation/CoreFoundation/CGRect> represents the location and dimensions of a rectangle. The data structure <doc://com.apple.documentation/documentation/CoreFoundation/CGSize> represents the dimensions of width and height.

A <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint>, <doc://com.apple.documentation/documentation/CoreFoundation/CGRect>, or <doc://com.apple.documentation/documentation/CoreFoundation/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 <doc://com.apple.documentation/documentation/CoreFoundation/CGRect> structure specifying the frame of an <doc://com.apple.documentation/documentation/AppKit/NSView> or <doc://com.apple.documentation/documentation/UIKit/UIView> object defines the view’s dimensions in points, not pixels. However, the effects of using a <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> structure in a [`CGContext`](/documentation/CoreGraphics/CGContext) drawing operation depend on the scale factor associated with that context. Where not otherwise specified, you can assume that a <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint>, <doc://com.apple.documentation/documentation/CoreFoundation/CGRect>, or <doc://com.apple.documentation/documentation/CoreFoundation/CGSize> structure is defined in points, not pixels. (For details, see [Drawing and Printing Guide for iOS](https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010156) or [High Resolution Guidelines for OS X](https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302).)

The height and width stored in a <doc://com.apple.documentation/documentation/CoreFoundation/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 <doc://com.apple.documentation/documentation/CoreFoundation/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 <doc://com.apple.documentation/documentation/CoreFoundation/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

[`CGPointCreateDictionaryRepresentation`](/documentation/CoreGraphics/CGPointCreateDictionaryRepresentation(_:))

Returns a dictionary representation of the specified point.

[`CGSizeCreateDictionaryRepresentation`](/documentation/CoreGraphics/CGSizeCreateDictionaryRepresentation(_:))

Returns a dictionary representation of the specified size.

[`CGRectCreateDictionaryRepresentation`](/documentation/CoreGraphics/CGRectCreateDictionaryRepresentation(_:))

Returns a dictionary representation of the provided rectangle.

### Creating a Geometric Primitive from a Dictionary Representation

[`CGPointMakeWithDictionaryRepresentation`](/documentation/CoreGraphics/CGPointMakeWithDictionaryRepresentation(_:_:))

Fills in a point using the contents of the specified dictionary.

[`CGSizeMakeWithDictionaryRepresentation`](/documentation/CoreGraphics/CGSizeMakeWithDictionaryRepresentation(_:_:))

Fills in a size using the contents of the specified dictionary.

[`CGRectMakeWithDictionaryRepresentation`](/documentation/CoreGraphics/CGRectMakeWithDictionaryRepresentation(_:_:))

Fills in a rectangle using the contents of the specified dictionary.

### Creating a Geometric Primitive from Values

[`CGPointMake`](/documentation/CoreGraphics/CGPointMake(_:_:))

Returns a point with the specified coordinates.

[`CGRectMake`](/documentation/CoreGraphics/CGRectMake(_:_:_:_:))

Returns a rectangle with the specified coordinate and size values.

[`CGSizeMake`](/documentation/CoreGraphics/CGSizeMake(_:_:))

Returns a size with the specified dimension values.

[`CGVectorMake`](/documentation/CoreGraphics/CGVectorMake(_:_:))

Returns a vector with the specified dimension values.

### Modifying Rectangles

[`CGRectDivide`](/documentation/CoreGraphics/CGRectDivide)

Divides a source rectangle into two component rectangles.

[`CGRectInset`](/documentation/CoreGraphics/CGRectInset(_:_:_:))

Returns a rectangle that is smaller or larger than the source rectangle, with the same center point.

[`CGRectIntegral`](/documentation/CoreGraphics/CGRectIntegral(_:))

Returns the smallest rectangle that results from converting the source rectangle values to integers.

[`CGRectIntersection`](/documentation/CoreGraphics/CGRectIntersection(_:_:))

Returns the intersection of two rectangles.

[`CGRectOffset`](/documentation/CoreGraphics/CGRectOffset(_:_:_:))

Returns a rectangle with an origin that is offset from that of the source rectangle.

[`CGRectStandardize`](/documentation/CoreGraphics/CGRectStandardize(_:))

Returns a rectangle with a positive width and height.

[`CGRectUnion`](/documentation/CoreGraphics/CGRectUnion(_:_:))

Returns the smallest rectangle that contains the two source rectangles.

### Comparing Values

[`CGPointEqualToPoint`](/documentation/CoreGraphics/CGPointEqualToPoint-c.macro)

Returns whether two points are equal.

[`CGSizeEqualToSize`](/documentation/CoreGraphics/CGSizeEqualToSize-c.macro)

Returns whether two sizes are equal.

[`CGRectEqualToRect`](/documentation/CoreGraphics/CGRectEqualToRect(_:_:))

Returns whether two rectangles are equal in size and position.

[`CGRectIntersectsRect`](/documentation/CoreGraphics/CGRectIntersectsRect(_:_:))

Returns whether two rectangles intersect.

### Checking for Membership

[`CGRectContainsPoint`](/documentation/CoreGraphics/CGRectContainsPoint(_:_:))

Returns whether a rectangle contains a specified point.

[`CGRectContainsRect`](/documentation/CoreGraphics/CGRectContainsRect(_:_:))

Returns whether the first rectangle contains the second rectangle.

### Getting Min, Mid, and Max Values

[`CGRectGetMinX`](/documentation/CoreGraphics/CGRectGetMinX(_:))

Returns the smallest value for the x-coordinate of the rectangle.

[`CGRectGetMinY`](/documentation/CoreGraphics/CGRectGetMinY(_:))

Returns the smallest value for the y-coordinate of the rectangle.

[`CGRectGetMidX`](/documentation/CoreGraphics/CGRectGetMidX(_:))

Returns the x- coordinate that establishes the center of a rectangle.

[`CGRectGetMidY`](/documentation/CoreGraphics/CGRectGetMidY(_:))

Returns the y-coordinate that establishes the center of the rectangle.

[`CGRectGetMaxX`](/documentation/CoreGraphics/CGRectGetMaxX(_:))

Returns the largest value of the x-coordinate for the rectangle.

[`CGRectGetMaxY`](/documentation/CoreGraphics/CGRectGetMaxY(_:))

Returns the largest value for the y-coordinate of the rectangle.

### Getting Height and Width

[`CGRectGetHeight`](/documentation/CoreGraphics/CGRectGetHeight(_:))

Returns the height of a rectangle.

[`CGRectGetWidth`](/documentation/CoreGraphics/CGRectGetWidth(_:))

Returns the width of a rectangle.

### Checking Rectangle Characteristics

[`CGRectIsEmpty`](/documentation/CoreGraphics/CGRectIsEmpty(_:))

Returns whether a rectangle has zero width or height, or is a null rectangle.

[`CGRectIsNull`](/documentation/CoreGraphics/CGRectIsNull(_:))

Returns whether the rectangle is equal to the null rectangle.

[`CGRectIsInfinite`](/documentation/CoreGraphics/CGRectIsInfinite(_:))

Returns whether a rectangle is infinite.

### Data Types

  <doc://com.apple.documentation/documentation/CoreFoundation/CGFloat-swift.struct>

  <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint>

  <doc://com.apple.documentation/documentation/CoreFoundation/CGRect>

  <doc://com.apple.documentation/documentation/CoreFoundation/CGSize>

  <doc://com.apple.documentation/documentation/CoreFoundation/CGVector>

### Constants

[`CGRectInfinite`](/documentation/CoreGraphics/CGRectInfinite)

A rectangle that has infinite extent.

[Geometric Zeros](/documentation/CoreGraphics/geometric-zeros)

A zero point, zero rectangle, or zero size.

[`CGRectNull`](/documentation/CoreGraphics/CGRectNull)

The null rectangle, representing an invalid value.

  <doc://com.apple.documentation/documentation/CoreFoundation/CGRectEdge>

[CGFloat Informational Macros](/documentation/CoreGraphics/cgfloat-informational-macros)

Informational macros for the `CGFloat` type.

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)