- Inherits
from:
- Object
- Implements:
- Cloneable
- Package:
- com.apple.yellow.foundation
Class Description
An NSRect object represents a rectangle. The
elemental attributes of a rectangle are its origin (its starting
x-coordinate and y-coordinate) and its size (width and height as
measured from the origin). An NSRect with height or width of zero
or less is considered an "empty" rectangle. The methods of NSRect give
you access to these values and to computed values, and they allow
you to compare rectangles and perform various tests, such as determining
whether a point falls in a rectangle. They also convert NSRects
between string objects and AWT Rectangles, and they yield new NSRects
based on intersection, union, inset, offset, and other operations.
NSRect provides the following constant as a convenience; you
can use it to compare values returned by many NSRect methods:
Constant |
Type |
Description |
ZeroRect |
NSRect |
An NSRect set to zero in width and height. |
Method Types
- Constructors
- NSRect
- Accessing elemental values
- height
- origin
- size
- width
- x
- y
- Accessing computed values
- maxX
- maxY
- midX
- midY
- Testing and comparing
rectangles
- containsPoint
- equals
- hashCode
- intersectsRect
- isEmpty
- isEqualToRect
- isSubrectOfRect
- Deriving rectangles
- rectByInsettingRect
- rectByIntersectingRect
- rectByMakingIntegral
- rectByOffsettingRect
- rectByUnioningRect
- sliceRect
- Transforming NSRects
- fromString
- toString
- toAWTRectangle
Constructors
public NSRect()
Initializes an empty rectangle (that is, a rectangle
with at least one dimension of zero)
public NSRect(
float x,
float y,
float w,
float h)
Initializes an NSRect 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
zero, it initializes an empty rectangle. Throws an IllegalArgumentException
if any argument is not a valid float value (NaN).
public NSRect(
NSPoint aPoint,
NSSize aSize)
Initializes an NSRect from an NSPoint object
and an NSSize object.
public NSRect(
NSPoint pointOne,
NSPoint pointTwo)
Initializes an NSRect from two NSPoint objects,
creating the smallest rectangle whose opposite corners touch the
two points.
public NSRect(java.awt.Rectangle aRectangle)
Initializes an NSRect from an AWT Rectangle
object.
public NSRect(NSRect aRectangle)
Initializes an NSRect from another NSRect object;
this constructor is used in cloning the receiver.
Static Methods
public static NSRect fromString(String rectAsString)
Creates an NSRect from the string rectAsString,
which must be of the form "{{x,y},{w,h}}" where x is
a float representation of the origin x-coordinate, y is
a float representation of the origin y-coordinate, w is
a float representation of the width and h is
a float representation of the height. Throws an IllegalArgumentException
if the string is improperly formatted.See
Also: toString
Instance Methods
public Object clone()
Description forthcoming.
public boolean containsPoint(
NSPoint aPoint,
boolean isFlipped)
Returns whether the receiver contains the point aPoint.
If isFlipped is true, the measurements occur
in a flipped coordinate system (where the y-axis extends down instead
of up). If aPoint occurs inside or
coincides with the receiver's x-axis or y-axis, and falls within
the opposite edges of the rectangle, it is considered to be contained
by the rectangle.See Also: intersectsRect, isSubrectOfRect
public boolean equals(Object otherObject)
Returns whether otherObject is
an NSRect and is equal in origin and size to the receiver.See
Also: isEqualToRect
public int hashCode()
Provides an appropriate hash code useful for
storing the receiver in any hash-based data structure. This value
is the sum of the receiver's origin x-coordinate, its origin y-coordinate,
half of its width, and half of its height, rounded to the nearest
integer.
public float height()
Returns the height dimension of the receiver.See
Also: maxY, midY, size, width
public boolean intersectsRect(NSRect aRect)
Returns whether the receiver intersects rectangle aRect.
Alignment of outer edges is not considered an intersection. Returns false if
either NSRect is an empty rectangle.See Also: containsPoint, isSubrectOfRect, rectByIntersectingRect
public boolean isEmpty()
Returns whether either dimension (width or height)
of the receiver is zero.
public boolean isEqualToRect(NSRect aRect)
Returns whether the NSRect aRect is
equal in origin and size to the receiver.See
Also: equals
public boolean isSubrectOfRect(NSRect aRect)
Returns whether the receiver is entirely enclosed
by rectangle aRect. Coincidence of
x-axes and y-axes, or the edges opposite the x-axis or y-axis is
acceptable. Returns false if either NSRect is an empty rectangle.
By reversing receiver and argument, you can use this method as a
virtual "containsRect".See Also: containsPoint, intersectsRect
public float maxX()
Returns the farthest extent of the receiver
along the x-axis in the current coordinate system; or, to put it
another way, the x-coordinate value of the receiver's right edge.
This value is the sum of the receiver's origin x-coordinate and
its width.See Also: maxY
public float maxY()
Returns the farthest extent of the receiver
along the y-axis in the current coordinate system; or, to put it
another way, the y-coordinate value of the receiver's top edge
(or bottom, if the coordinate system is flipped). This value is
the sum of the receiver's origin y-coordinate and its heightSee
Also: maxX
.public float midX()
Returns the extent of the receiver along the
x-axis halfway between its origin x-coordinate and the x-coordinate
of its right edge.See Also: midY
public float midY()
Returns the extent of the receiver along the
y-axis halfway between its origin y-coordinate and the y-coordinate
of its upper edge (or bottom edge, if used in a flipped coordinate
system).See Also: midX
public NSPoint origin()
Returns the origin of the receiver, the point
from which the dimensions of the receiver are measured.See
Also: x, y
public NSRect rectByInsettingRect(
float horizInset,
float vertInset)
Returns an NSRect that is the result of insetting
the receiver horizInset units horizontally
and vertInset units vertically from all edges.See
Also: rectByOffsettingRect
public NSRect rectByIntersectingRect(NSRect otherRect)
Returns an NSRect that is the result of the
intersection of the receiver with otherRect.
Returns ZeroRect
if either receiver
or otherRect is an empty rectangle
or the two NSRects do not intersect at all.See
Also: rectByUnioningRect
public NSRect rectByMakingIntegral()
Returns an NSRect that is the result of rounding
down the receiver's x-coordinate and y-coordinate to the nearest
integer and rounding up the receiver's height and width to the
nearest integer. The resulting rectangle thus completely encloses
the original. Returns ZeroRect
if
the receiver is an empty rectangle.See Also: toAWTRectangle
public NSRect rectByOffsettingRect(
float horizOffset,
float vertOffset)
Returns an NSRect that is the result of offsetting
the receiver horizInset units horizontally
and vertInset units vertically. This method affects the origin only,
while the rectByInsettingRect method affects
all edges.
public NSRect rectByUnioningRect(NSRect otherRect)
Returns an NSRect that is the result of the
union of the receiver with otherRect,
which is a rectangle that contains the two NSRects combined. Returns ZeroRect
if
both receiver and otherRect are empty rectangles.
If the receiver or otherRect is an
empty rectangle but the other isn't, this method returns an NSRect
that is equal to the rectangle that isn't empty.See
Also: rectByIntersectingRect
public NSSize size()
Returns the size of the receiver. The NSSize
object encapsulates the width and height of the receiver.See
Also: height, origin, width
public void sliceRect(
float thickness,
int edge,
NSMutableRect rect1,
NSMutableRect rect2)
Makes two smaller rectangles from the receiver
and returns them by modifying two mutable rectangles passed in as
arguments. One of these NSMutableRectangles has the width or height thickness
as determined by the constant edge.
One modified rectangle is returned in rect1 and
the other in rect2; which rectangle
goes where is also determined by edge.
Here is a summary of how the edge constant
and the other arguments interact:
Constant |
Type |
Description |
MinXEdge |
int |
The rectangle is sliced vertically and the rectangle
with the width of thickness is placed in rect1. |
MaxXEdge |
int |
The rectangle is sliced horizontally and the rectangle with
the height of thickness is placed in rect2. |
MinYEdge |
int |
The rectangle is sliced horizontally and the rectangle with
the height of thickness is placed in rect1. |
MaxYEdge |
int |
The rectangle is sliced vertically and the rectangle
with the width of thickness is placed in rect2. |
If thickness is greater than the width or height of
the receiver (as determined by edge),
it is made the same width or height as the receiver. This method
does not affect the receiver.
public java.awt.Rectangle toAWTRectangle()
Returns the receiver as a AWT Rectangle object.
This method calls rectByMakingIntegral to
round the receiver's float values to appropriate integers.See
Also: toString
public String toString()
Returns the receiver as converted to a string
object in the form of "{{x,y},{w,h}}"
where x is the origin x-coordinate, y is
the origin y-coordinate, w is the width,
and h is the height.See
Also: fromString
public float width()
Returns the width of the receiver.See
Also: height, size
public float x()
Returns the origin x-coordinate of the receiver.See
Also: origin, y
public float y()
Returns the origin y-coordinate of the receiver.See
Also: origin, x