Class Rect
A Rect describes a rectangular two-dimensional area as a top-left point (x and y values) and a size (width and height values).
Use the static functions Rect.parse and Rect.stringify to convert to and from a standard string representation that is independent of the current locale.
When an instance of this class is the value of a property of a GraphObject class or Diagram or CommandHandler or a Tool class, you should treat the object as if it were frozen or read-only -- you cannot modify its properties. This allows the property to return a value without allocating a new instance. If you need to do your own calculations with the value, call copy to make a new instance with the same values that you can modify.
Many methods modify the object's properties and then return a reference to "this" object. The only instance method to allocate a new object is the copy method. The static Rect.parse method also allocates a new object. The center, position, and size properties all allocate and return a new object.
The "Debug" implementation of this class is significantly slower than the "Release" implementation, mostly due to additional error checking.
You cannot inherit from this class.
Constructor Summary Details
Name | Description |
---|---|
Rect(x, y, w, h)
|
There are four constructors: (), (Point, Point), (Point, Size), and four numbers for (x, y, width, height).More... The default constructor (no argument) results in a Rect(0,0,0,0). |
Properties Summary Details
Name, Value Type | Description |
---|---|
bottom
{number}
|
Gets or sets the y-axis value of the bottom of the Rect.More... This is equal to the sum of the y value and the height. |
center
{Point}
|
Gets or sets the Point at the center of this Rect.More... Setting this property just shifts the X and Y values. |
centerX
{number}
|
Gets or sets the horizontal center X coordinate of the Rect. |
centerY
{number}
|
Gets or sets the vertical center Y coordinate of the Rect. |
height
{number}
|
Gets or sets the height of the Rect.More... The value must not be negative. |
left
{number}
|
Gets or sets the leftmost value of the Rect.More... This is the same as the X value. |
position
{Point}
|
Gets or sets the x- and y-axis position of the Rect as a Point. |
right
{number}
|
Gets or sets the x-axis value of the right of the Rect.More... This is equal to the sum of the x value and the width. |
size
{Size}
|
Gets or sets the width and height of the Rect as a Size. |
top
{number}
|
Gets or sets the topmost value of the Rect.More... This is the same as the Y value. |
width
{number}
|
Gets or sets the width of the Rect.More... The value must not be negative. |
x
{number}
|
Gets or sets the top-left x coordinate of the Rect. |
y
{number}
|
Gets or sets the top-left y coordinate of the Rect. |
Method Summary Details
Name, Return Type | Description |
---|---|
addMargin(m)
{Rect}
|
|
contains(x, y, w, h)
{boolean}
|
Indicates whether this Rect contains the given Point/Rect.More... See also:
|
<static>
Rect.contains(rx, ry, rw, rh, x, y, w, h)
{boolean}
|
This static function indicates whether a Rect contains the given Point/Rect.More...
|
containsPoint(p)
{boolean}
|
|
containsRect(r)
{boolean}
|
|
copy()
{Rect}
|
Create a copy of this Rect, with the same values.
|
equals(r)
{boolean}
|
|
equalTo(x, y, w, h)
{boolean}
|
|
grow(t, r, b, l)
{Rect}
|
Modifies this Rect by adding some distance to each side of the Rect.More... See also:
|
inflate(w, h)
{Rect}
|
Modify this Rect so that its width and height are changed on all four sides, equally on the left and right sides, and equally on the top and bottom sides.More... When the arguments are negative, this operation deflates this Rect, but not beyond zero. See also:
|
intersect(x, y, w, h)
{Rect}
|
|
intersectRect(r)
{Rect}
|
|
<static>
Rect.intersects(rx, ry, rw, rh, x, y, w, h)
{boolean}
|
This static function indicates whether a Rect partly or wholly overlaps the given Rect.More...
|
intersects(x, y, w, h)
{boolean}
|
Determine if this Rect partly or wholly overlaps the rectangle defined by x, y, w, h.More... See also:
|
intersectsRect(r)
{boolean}
|
|
isEmpty()
{boolean}
|
True if this Rect has a Width and Height of zero.
|
isReal()
{boolean}
|
True if this Rect has X, Y, Width, and Height values that are real numbers and not infinity.
|
offset(dx, dy)
{Rect}
|
|
<static>
Rect.parse(str)
{Rect}
|
This static function can be used to read in a Rect from a string that was produced by Rect.stringify.More...
|
set(r)
{Rect}
|
|
setPoint(p)
{Rect}
|
|
setSize(s)
{Rect}
|
|
setSpot(x, y, spot)
{Rect}
|
Modify this Rect so that a given Spot is at a given (x,y) point using this Rect's size.More... Return this rectangle for which the spot is at that point, without modifying the size. The result is meaningless if Spot.isNoSpot is true.
|
setTo(x, y, w, h)
{Rect}
|
|
<static>
Rect.stringify(val)
{string}
|
This static function can be used to write out a Rect as a string that can be read by Rect.parse.More...
|
subtractMargin(m)
{Rect}
|
|
union(x, y, w, h)
{Rect}
|
Modify this Rect to be exactly big enough to contain both the original Rect and the given rectangular area.More... See also:
|
unionPoint(p)
{Rect}
|
|
unionRect(r)
{Rect}
|