An Objective-C/Perl Bridge

CamelBones::NSRect

A CamelBones::NSRect object represents a rectangle. It has four properties: x, y, width and height. The x and y properties describe the origin of the rectangle, and the width and height properties its size. All four properties are floating-point numbers.

Methods

getX()
Returns the value of the x property.
getY()
Returns the value of the y property.
getWidth()
Returns the value of the width property.
getHeight()
Returns the value of the height property.
setX($newX)
Stores the value of $newX in the x property.
setY($newY)
Stores the value of $newY in the y property.
setWidth($newWidth)
Stores the value of $newWidth in the width property.
setHeight($newHeight)
Stores the value of $newHeight in the height property.
setAll($newX, $newY, $newWidth, $newHeight)
Stores the value of $newX, $newY, $newWidth, and $newHeight in the x, y, width, and height properties, respectively.
$hr = getHashref()
Returns the rect data as a reference to a hash with keys 'x', 'y', 'width' and 'height'.
$ar = getArrayref()
Returns the rect data as an array reference. Properties are stored in the array in the order x, y, width, height.

Functions

$isContained = NSContainsRect($rect1, $rect2)
Returns true if $rect2 is completely enclosed in $rect2, false otherwise.
NSDivideRect(...)
Not supported in Perl.
$isEQ = NSEqualRects($rect1, $rect2)
Returns true if all properties are the same for both rects, false if not.
$height = NSHeight($rect)
Returns the height property of $rect.
$rect = NSInsetRect($rect1, $dX, $dY)
Returns a new NSRect that is inset from $rect by the specified amount in each dimension.
$rect = NSIntegralRect($rect1)
Returns a new NSRect that is expanded from $rect1. All properties that have fractional values in $rect1 are adjusted upwards to the nearest integer value in $rect.
$rect = NSIntersectionRect($rect1, $rect2)
Returns an NSRect that covers the intersection of $rect1 and $rect2. If no part of $rect1 and $rect2 overlap, the returned rect has x, y, width and height properties all of 0.
$doesIntersect = NSIntersectsRect($rect1, $rect2)
Returns true if any part of $rect1 overlaps $rect2, false if not.
$isEmpty = NSIsEmptyRect($rect)
Returns true if $rect is empty - i.e. if its height and width are 0. Returns false if not.
$rect = NSMakeRect($newX, $newY, $newWidth, $newHeight)
Creates a new NSRect structure with the specified properties.
$max = NSMaxX($rect)
Returns the largest x coordinate found in $rect.
$max = NSMaxY($rect)
Returns the largest y coordinate found in $rect.
$mid = NSMidX($rect)
Returns the x coordinate of the midpoint of $rect.
$mid = NSMidY($rect)
Returns the y coordinate of the midpoint of $rect.
$min = NSMinX($rect)
Returns the smallest x coordinate found in $rect.
$min = NSMinY($rect)
Returns the smallest y coordinate found in $rect.
$isIn = NSMouseInRect($point, $rect, $isFlipped)
Returns true if $point (an NSPoint) falls within $rect, with screen coordinates "flipped" or not as reflected by $isFlipped. Returns false otherwise.
$rect = NSOffsetRect($rect1, $dX, $dY)
Returns a new NSRect created by moving the origin of $rect by $dX and $dY along the X and Y axis, respectively.
$isIn = NSPointInRect($point, $rect)
Returns true if $point (an NSPoint) falls within $rect, false if not.
$rect = NSRectFromString($str)
Creates a new NSRect from the string representation in $str.
$str = NSStringFromRect($rect)
Returns a string representation of $rect
$rect = NSUnionRect($rect1, $rect2)
Returns the smallest rectangle that encloses $rect1 and $rect2.
$width = NSWidth($rect)
Returns the width property of $rect.

NSRect function and method arguments

Naturally, a function or method that is declared as taking an NSRect structure as an argument will also take a CamelBones::NSRect object. However, a hash or array reference may be passed as well, as illustrated by these examples:

# Create a CamelBones::NSRect object
my $rect = NSMakeRect(1.0, 1.0, 10.0, 10.0);

# Returns zero
my $isEQ = NSEqualRects($rect, { x=>5, y=>5, width=>10, height=>10 });

# Returns nonzero
my $isIn = NSPointInRect([1.0, 1.0], [5.0, 5.0, 20.0, 20.0]);

NSRect return values

Cocoa functions and methods that are declared as returning NSRect structures will return CamelBones::NSRect objects to Perl.

See also

NSRect

Managing Rectangles