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 froma 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 Diagramor CommandHandler or a Tool class, you should treat the objectas 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 makea 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).

Parameters:
{Point|number=} x
Top-left Point, or x value.
{Point|Size|number=} y
Bottom-right Point or Size or y value.
{number=} w
Width to be used if x,y are specified;must be non-negative.
{number=} h
Height to be used if x,y are specified;must be non-negative.

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.

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}

Modify this Rect by adding the given Margin to each side of the Rect.More...

Parameters:
{Margin} m
The Margin to add to the Rect.
Returns:
{Rect} this bigger Rect.
contains(x, y, w, h)
{boolean}

Indicates whether this Rect contains the given Point/Rect.More...

Parameters:
{number} x
The X coordinate of the Point or Rect to include in the new bounds.
{number} y
The Y coordinate of the Point or Rect to include in the new bounds.
{number=} w
The Width of the Rect to include in the new bounds, defaults to zero.
{number=} h
The Height of the Rect to include in the new bounds, defaults to zero.
Returns:
{boolean} True if the Point/Rect is contained within this Rect,false otherwise.
<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...

Parameters:
{number} rx
The X coordinate of a Rect.
{number} ry
The Y coordinate of a Rect.
{number} rw
The Width of a Rect.
{number} rh
The Height of a Rect.
{number} x
The X coordinate of the Point or Rect that might be in the bounds (RX, RY, RW, RH).
{number} y
The Y coordinate of the Point or Rect that might be in the bounds (RX, RY, RW, RH).
{number=} w
The Width of the Rect to include in the new bounds, defaults to zero.
{number=} h
The Height of the Rect to include in the new bounds, defaults to zero.
Returns:
{boolean} True if the Point/Rect is contained within this Rect,false otherwise.
containsPoint(p)
{boolean}

Indicates whether this Rect contains the given Point.More...

Parameters:
{Point} p
The Point to check.
Returns:
{boolean} True if the Point is contained within this Rect,false otherwise.
containsRect(r)
{boolean}

Indicates whether this Rect contains the given Rect.More...

Parameters:
{Rect} r
The Rect to check.
Returns:
{boolean} True if the Rect is contained within this Rect,false otherwise.
copy()
{Rect}

Create a copy of this Rect, with the same values.

Returns:
{Rect}
equals(r)
{boolean}

Indicates whether the given Rect is equal to the current Rect.More...

See also:
Parameters:
{Rect} r
The rectangle to compare to the current rectangle.
Returns:
{boolean} True if the Rects are equivalent in x, y, width,and height.
equalTo(x, y, w, h)
{boolean}

Indicates whether the given Rect is equal to the current Rect.More...

See also:
Parameters:
{number} x
{number} y
{number} w
the width.
{number} h
the height.
Returns:
{boolean} True if the Rects are equivalent in x, y, width, and height.
grow(t, r, b, l)
{Rect}

Modifies this Rect by adding some distance to each side of the Rect.More...

Parameters:
{number} t
the amount to move the top side upwards; may be negative.
{number} r
the amount to move the right side rightwards; may be negative.
{number} b
the amount to move the bottom side downwards; may be negative.
{number} l
the amount to move the left side leftwards; may be negative.
Returns:
{Rect} this modified Rect.
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.

Parameters:
{number} w
The additional width on each side, left and right; may be negative.
{number} h
The additional height on each side, top and bottom; may be negative.
Returns:
{Rect} this.
intersect(x, y, w, h)
{Rect}

Modify this Rect so that it is the intersection of this Rect and the rectangledefined by x, y, w, h.More...

Parameters:
{number} x
{number} y
{number} w
{number} h
Returns:
{Rect} this.
intersectRect(r)
{Rect}

Modify this Rect so that it is the intersection of this Rect and the given Rect.More...

Parameters:
{Rect} r
Rect to intersect with.
Returns:
{Rect} this.
<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...

Parameters:
{number} rx
The X coordinate of a Rect.
{number} ry
The Y coordinate of a Rect.
{number} rw
The Width of a Rect.
{number} rh
The Height of a Rect.
{number} x
The X coordinate of the Point or Rect that might overlap the bounds (RX, RY, RW, RH).
{number} y
The Y coordinate of the Point or Rect that might overlap the bounds (RX, RY, RW, RH).
{number} w
{number} h
Returns:
{boolean} true if there is any overlap.
intersects(x, y, w, h)
{boolean}

Determine if this Rect partly or wholly overlaps the rectangledefined by x, y, w, h.More...

Parameters:
{number} x
{number} y
{number} w
{number} h
Returns:
{boolean} true if there is any overlap.
intersectsRect(r)
{boolean}

Determine if a given Rect is partly or wholly inside of this Rect.More...

Parameters:
{Rect} r
Rect to test intersection with.
Returns:
{boolean} true if there is an intersection.
isEmpty()
{boolean}

True if this Rect has a Width and Height of zero.

Returns:
{boolean}
isReal()
{boolean}

True if this Rect has X, Y, Width, and Height values that are real numbers and not infinity.

Returns:
{boolean}
offset(dx, dy)
{Rect}

Modify this Rect by shifting its values with the given DX and DY offsets.More...

Parameters:
{number} dx
{number} dy
Returns:
{Rect} this.
<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...

go.Rect.parse("1 2 3 4") produces the Rect new go.Rect(1, 2, 3, 4).

Parameters:
{string} str
Returns:
{Rect}
set(r)
{Rect}

Modify this Rect so that its X, Y, Width, and Height values are the same as the given Rect.More...

Parameters:
{Rect} r
the given Rect.
Returns:
{Rect} this.
setPoint(p)
{Rect}

Modify this Rect so that its X and Y values are the same as the given Point.More...

Parameters:
{Point} p
the given Point.
Returns:
{Rect} this.
setSize(s)
{Rect}

Modify this Rect so that its Width and Height values are the same as the given Size.More...

Parameters:
{Size} s
the given Size.
Returns:
{Rect} this.
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.

Parameters:
{number} x
the point where the spot should be.
{number} y
the point where the spot should be.
{Spot} spot
a Spot; Spot.isSpot must be true.
Returns:
{Rect} this.
setTo(x, y, w, h)
{Rect}

Modify this Rect with new X, Y, Width, and Height values.More...

Parameters:
{number} x
{number} y
{number} w
the width.
{number} h
the height.
Returns:
{Rect} this.
<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...

go.Rect.stringify(new go.Rect(1, 2, 3, 4)) produces the string "1 2 3 4".

Parameters:
{Rect} val
Returns:
{string}
subtractMargin(m)
{Rect}

Modify this Rect by subtracting the given Margin from each side of the Rect.More...

Parameters:
{Margin} m
The Margin to subtract from the Rect.
Returns:
{Rect} this smaller 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...

Parameters:
{number} x
The X coordinate of the Point or Rect to include in the new bounds.
{number} y
The Y coordinate of the Point or Rect to include in the new bounds.
{number=} w
The Width of the Rect to include in the new bounds, defaults to zero.
{number=} h
The Height of the Rect to include in the new bounds, defaults to zero.
Returns:
{Rect} this.
unionPoint(p)
{Rect}

Modify this Rect to be exactly big enough to contain both the original Rect and the given Point.More...

See also:
Parameters:
{Point} p
The Point to include in the new bounds.
Returns:
{Rect} this.
unionRect(r)
{Rect}

Modify this Rect to be exactly big enough to contain this Rect and the given Rect.More...

See also:
Parameters:
{Rect} r
The Rect to include in the new bounds.
Returns:
{Rect} this.