Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSMutableRect

Inherits from
NSRect : Object
Package
com.apple.cocoa.foundation
Companion guide
Geometry and Range Utilities

Overview

An NSMutableRect is an object representing a rectangle that can be modified. The elemental attributes of a rectangle are its origin (its starting x coordinate and y coordinate) and its size (its width and height as measured from the origin). The methods of NSMutableRect allow you to change these elemental values. They also let you inset and offset rectangles by specific amounts and alter an NSMutableRect based on its union or intersection with another NSRect object.

The main purpose for NSMutableRects is to provide a way for methods to return rectangle values in an “out” parameter. A client creates and passes in one or more NSMutableRects to a method and gets back converted objects when the method returns. NSMutableRects are also useful for performance reasons; instead of creating multiple NSRects in a loop, you can create just one NSMutablePoint and reuse it.

Tasks

Constructors

Accessing and Setting Coordinate Values

Accessing and Setting Size Values

Transforming Mutable Rectangles

Copying

Constructors

NSMutableRect

public NSMutableRect()

Discussion

Initializes an empty mutable rectangle (that is, a rectangle with at least one dimension of 0).

public NSMutableRect(float x, float y, float w, float h)

Discussion

Initializes an NSMutableRect from a starting x coordinate (x), a starting y coordinate (y), a width value (w), and a height value (h). If either width and height is 0, it initializes an empty rectangle.

public NSMutableRect(NSPoint aPoint, NSSize aSize)

Discussion

Initializes an NSMutableRect from an NSPoint object, aPoint, and an NSSize object, aSize.

public NSMutableRect(NSPoint pointOne, NSPoint pointTwo)

Discussion

Initializes an NSMutableRect from two NSPoint objects, pointOne and pointTwo. Creates the smallest rectangle containing the two points.

public NSMutableRect(java.awt.Rectangle javaRectangle)

Discussion

Initializes an NSMutableRect from an AWT Rectangle object, javaRectangle.

public NSMutableRect(NSRect aRectangle)

Discussion

Initializes an NSMutableRect from an NSRect object, aRectangle; this constructor is used in cloning the receiver.

Instance Methods

clone

Creates and returns a copy of the receiver.

public Object clone()

height

Returns the height dimension of the receiver.

public float height()

Discussion

NSMutableRect overrides this method because implementation details make overriding necessary.

See Also

insetRect

Modifies the receiver to be inset from both upper and lower edges by vertDistance and from both left and right edges by horizDistance.

public void insetRect(float vertDistance, float horizDistance)

Discussion

The values vertDistance and horizDistance can be negative. An IllegalArgumentException is thrown if the resulting width or height would be negative.

See Also

intersectRect

Modifies the receiver to be the intersection of itself and otherRectangle.

public void intersectRect(NSRect otherRectangle)

Discussion

If either the receiver or otherRectangle has an empty dimension, it modifies the receiver to be an empty rectangle (all dimensions) at point {0.0f, 0.0f}.

See Also

makeIntegral

Changes the receiver so that its origin and size are rounded to the nearest integer, ensuring that the receiver completely contains the original rectangle.

public void makeIntegral()

Discussion

The x coordinate and the y coordinate are rounded down, and the height and width are rounded up. If the receiver has an empty dimension, it is modified to be an empty rectangle (all dimensions) at point {0.0f, 0.0f}.

offsetRect

Changes the receiver so that its x coordinate is moved by horizOffset and its y coordinate is moved by vertOffset.

public void offsetRect(float horizOffset, float vertOffset)

Discussion

Both arguments can be negative values.

See Also

setHeight

Sets the width of the receiver to newHeight.

public void setHeight(float newHeight)

Discussion

Throws an IllegalArgumentException if newHeight is NaN (an invalid float value) or is a negative value.

See Also

setOrigin

Sets the origin point of the receiver to newOrigin.

public void setOrigin(NSPoint newOrigin)

See Also

setSize

Sets the size of the receiver to newSize.

public void setSize(NSSize newSize)

See Also

setWidth

Sets the width of the receiver to newWidth.

public void setWidth(float newWidth)

Discussion

Throws an IllegalArgumentException if newWidth is NaN (an invalid float value) or is a negative value.

See Also

setX

Sets the x-coordinate of the receiver to newX.

public void setX(float newX)

Discussion

Throws an IllegalArgumentException if newX is NaN (an invalid float value) or is a negative value.

See Also

setY

Sets the y-coordinate of the receiver to newY.

public void setY(float newY)

Discussion

Throws an IllegalArgumentException if newY is NaN (an invalid float value) or is a negative value.

See Also

unionRect

Modifies the receiver to be the union of itself and otherRectangle.

public void unionRect(NSRect otherRectangle)

Discussion

If the receiver and otherRectangle both have an empty dimension, it modifies the receiver to be an empty rectangle (all dimensions) at point {0.0f, 0.0f}. If otherRectangle has an empty dimension, but the receiver doesn’t, the receiver is unchanged.

See Also

width

Returns the width of the receiver.

public float width()

Discussion

NSMutableRect overrides this method because implementation details make overriding necessary.

See Also

x

Returns the origin x coordinate of the receiver.

public float x()

Discussion

NSMutableRect overrides this method because implementation details make overriding necessary.

See Also

y

Returns the origin y coordinate of the receiver.

public float y()

Discussion

NSMutablePoint overrides this method because implementation details make overriding necessary.

See Also


Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


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.