Geometry

Authors

Quentin Mathe (qmathe@club-internet.fr)
Geometry utility functions and constants.

Copyright: (C) 2008 Quentin Mathe


Contents -

  1. ETGeometry constants
  2. ETGeometry functions

ETGeometry constants

ETNullPoint

const NSPoint ETNullPoint;

The null point which is not equal to NSZeroPoint. It can be returned when a point value is undefined and is a nil-like marker for NSPoint primitive.


ETNullRect

const NSRect ETNullRect;

The null rectangle which is not equal to NSZeroRect. It can be returned when a rect value is undefined and is a nil-like marker for NSRect primitive.


ETNullSize

const NSSize ETNullSize;

The null size which is not equal to NSZeroSize. It can be returned when a size value is undefined and is a nil-like marker for NSSize primitive.


ETGeometry functions

ETAutoresize

void ETAutoresize(CGFloat* position, CGFloat* size, BOOL minMarginFlexible, BOOL sizeFlexible, BOOL maxMarginFlexible, CGFloat newContainerSize, CGFloat oldContainerSize);
Description forthcoming.

ETCenteredRect

NSRect ETCenteredRect(NSSize aSize, NSRect inRect);

Returns a rect that uses aSize as its size and centered inside the given rect.

The returned rect is expressed relative the given rect parent coordinate space.
To get a rect expressed relative the the given rect itself, pass a rect with a zero origin: NSRect inRect = NSMakeRect(40, 50, 100, 200); NSRect centeredRectSize = NSMakeSize(50, 100); NSRect rect = ETCenteredRect(centeredRectSize, ETMakeRect(NSZeroPoint, inRect.size)); The resulting rect is equal to {25, 50, 50, 100}.

The returned rect origin is valid whether or not your coordinate space is flipped.


ETIsNullPoint

BOOL ETIsNullPoint(NSPoint aPoint);

Returns whether the given point is equal to ETNullPoint.


ETIsNullRect

BOOL ETIsNullRect(NSRect rect);

Returns whether rect is equal to ETNullRect.


ETMakeRect

NSRect ETMakeRect(NSPoint origin, NSSize size);

Returns a rect with the given origin and size.


ETPointInsideRect

BOOL ETPointInsideRect(NSPoint aPoint, NSRect rect);

Returns whether rect contains a point expressed in coordinates relative to the rect origin.


ETScaleRect

NSRect ETScaleRect(NSRect frame, CGFloat factor);

Returns a rect with a width and height multiplied by the given factor and by shifting the origin to retain the original rect center location.


ETScaleSize

NSSize ETScaleSize(NSSize size, CGFloat factor);

Returns a size with a width and height multiplied by the given factor.


ETScaledRect

NSRect ETScaledRect(NSSize aSize, NSRect inRect, ETContentAspect anAspect);

Returns a rect that uses aSize scaled based on the content aspect rule and then centered inside the given rect.

The returned rect is expressed relative the given rect parent coordinate space.
To get a rect expressed relative the the given rect itself, see ETCenteredRect() .

The returned rect origin is valid whether or not your coordinate space is flipped.


ETSizeEqualToSize

BOOL ETSizeEqualToSize(NSSize size1, NSSize size2);

Returns whether the sizes are equal or precisely almost equal. To be considered equal, the size variation must remain smaller than FLT_EPSILON. On Mac OS X, NSEqualsSize tests exact equality unlike GNUstep implementation.


ETStandardizeRect

NSRect ETStandardizeRect(NSRect rect);

Returns a rect with a positive width and height by shifting the origin as needed.


ETSumPoint

NSPoint ETSumPoint(NSPoint aPoint, NSPoint otherPoint);

Returns a new point by summing the x and y coordinates of two points.


ETSumPointAndSize

NSPoint ETSumPointAndSize(NSPoint aPoint, NSSize aSize);

Returns a new point by summing the point x and y coordinates with the size width and height.


ETUnionRectWithObjectsAndSelector

NSRect ETUnionRectWithObjectsAndSelector(NSArray* itemArray, SEL rectSelector);

Returns an union rect computed by iterating over itemArray and unionning the rects returned by the objects which must all respond to rectSelector.

itemArray must only contain objects of the same type.

A zero rect is returned when itemArray is empty.