Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Manipulating Geometric Types

The Foundation framework includes numerous functions for manipulating geometric values and for performing various calculations using those values. In addition to basic equality checks, you can perform more complex operations, such as the union and intersection of rectangles or the inclusion of a point in a rectangle’s boundaries.

Table 5-3 lists some of the more commonly used functions and their behaviors. The function syntax is provided in a shorthand notation, with parameter types omitted to demonstrate the calling convention. For a complete list of available functions, and their full syntax, see the Functions section in Foundation Framework Reference.

Table 5-3  Commonly used geometry functions

Operation

Function

Description

Creation

NSPoint NSMakePoint(x, y)

Returns a properly formatted NSPoint data structure with the specified x and y values.

NSSize NSMakeSize(w, h)

Returns a properly formatted NSSize data structure with the specified width and height.

NSRect NSMakeRect(x, y, w, h)

Returns a properly formatted NSRect data structure with the specified origin (x, y) and size (width, height).

Equality

BOOL NSEqualPoints(p1, p2)

Returns YES if the two points are the same.

BOOL NSEqualSizes(s1, s2)

Returns YES if the two size types have identical widths and heights.

BOOL NSEqualRects(r1, r2)

Returns YES, if the two rectangles have the same origins and the same widths and heights.

Rectangle manipulations

BOOL NSContainsRect(r1, r2)

Returns YES if rectangle 1 completely encloses rectangle 2.

NSRect NSInsetRect(r, dX, dY)

Returns a copy of the specified rectangle with its sides moved inward by the specified delta values. Negative delta values move the sides outward. Does not modify the original rectangle.

NSRect NSIntersectionRect(r1, r2)

Returns the intersection of the two rectangles.

NSRect NSUnionRect(r1, r2)

Returns the union of the two rectangles.

BOOL NSMouseInRect(p, r, flipped)

Tests whether the point lies within the specified view rectangle. Adjusts the hit-detection algorithm to provide consistent behavior from the user’s perspective.

BOOL NSPointInRect(p, r)

Tests whether the point lies within the specified rectangle. This is a basic mathematical comparison.



< Previous PageNext Page > Hide TOC


Last updated: 2007-10-31




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice