Packagecom.yworks.bridge.geom
Classpublic class Rectangle
InheritanceRectangle Inheritance Rectangle2D Inheritance YObject Inheritance Object

A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-left point (x, y) in the coordinate space, its width, and its height.

The constructors that create a Rectangle, and the methods that can modify one, do not prevent setting a negative value for width or height.

A Rectangle whose width or height is negative is considered empty. If the Rectangle is empty, then the isEmpty method returns true. No point can be contained by or inside an empty Rectangle. The values of width and height, however, are still valid. An empty Rectangle still has a location in the coordinate space, and methods that change its size or location remain valid. The behavior of methods that operate on more than one Rectangle is undefined if any of the participating Rectangle objects has a negative width or height. These methods include intersects, intersection, and union.



Public Properties
 PropertyDefined By
  bounds : Rectangle
[override] [read-only] Gets the bounding Rectangle of this Rectangle.
Rectangle
  bounds2D : Rectangle2D
[override] [read-only] Return the high precision bounding box of this rectangle.
Rectangle
 InheritedcenterX : Number
[read-only] Returns the X coordinate of the center of this rectangle in double precision.
Rectangle2D
 InheritedcenterY : Number
[read-only] Returns the Y coordinate of the center of this rectangle in double precision.
Rectangle2D
  empty : Boolean
[override] [read-only] Determines whether or not this Rectangle is empty.
Rectangle
 Inheritedframe : Rectangle2D
Getter: Returns the framing Rectangle2D that defines the overall shape of this object.
Rectangle2D
  _height : int
Rectangle
  height : Number
[override] [read-only] Returns the height of the bounding Rectangle in double precision.
Rectangle
 InheritedmaxX : Number
[read-only] Returns the largest X coordinate of the upper left corner of this rectangle in double precision.
Rectangle2D
 InheritedmaxY : Number
[read-only] Returns the largest Y coordinate of the upper left corner of this rectangle in double precision.
Rectangle2D
 InheritedminX : Number
[read-only] Returns the smallest X coordinate of the upper left corner of this rectangle in double precision.
Rectangle2D
 InheritedminY : Number
[read-only] Returns the smallest Y coordinate of the upper left corner of this rectangle in double precision.
Rectangle2D
 Inheritedrect : Rectangle2D
[write-only] Sets this Rectangle2D to be the same as the specified Rectangle2D.
Rectangle2D
  size : Dimension
Rectangle
  _width : int
Rectangle
  width : Number
[override] [read-only] Returns the width of the bounding Rectangle in double precision.
Rectangle
  _x : int
Rectangle
  x : Number
[override] [read-only] Returns the X coordinate of the bounding Rectangle in double precision.
Rectangle
  _y : int
Rectangle
  y : Number
[override] [read-only] Returns the Y coordinate of the bounding Rectangle in double precision.
Rectangle
Public Methods
 MethodDefined By
  
Rectangle(x:int, y:int, width:int, height:int, init:Boolean = true)
Constructs a new Rectangle whose top-left corner is specified as (x, y) and whose width and height are specified by the arguments of the same name.
Rectangle
 Inherited
Adds the Point2D object p to this Rectangle2D.
Rectangle2D
 Inherited
addPoint2(x:Number, y:Number):void
Adds a point, specified by the double precision arguments px and py, to this Rectangle2D.
Rectangle2D
 Inherited
Adds a Rectangle2D object to this Rectangle2D.
Rectangle2D
  
Adds a Rectangle to this Rectangle.
Rectangle
  
clone():Object
[override]
Rectangle
 Inherited
containsPoint2(x:Number, y:Number):Boolean
Tests if a specified coordinate is inside the boundary of this Rectangle2D.
Rectangle2D
 Inherited
Tests if the interior of this Rectangle2D entirely contains the specified Rectangle2D.
Rectangle2D
 Inherited
containsRectangle2(x:Number, y:Number, width:Number, height:Number):Boolean
Tests if the interior of this Rectangle2D entirely contains the specified set of rectangular coordinates.
Rectangle2D
  
[override] Returns a new Rectangle2D object representing the intersection of this Rectangle with the specified Rectangle2D.
Rectangle
  
[override] Returns a new Rectangle2D object representing the union of this Rectangle with the specified Rectangle2D.
Rectangle
  
equals(obj:Object):Boolean
[override] Checks whether two rectangles are equal.
Rectangle
  
getClass():Class
[override]
Rectangle
  
grow(dx:int, dy:int):void
Resizes the Rectangle both horizontally and vertically.
Rectangle
 Inherited
hashCode():int
[override]
Rectangle2D
 Inherited
[static] Intersects the pair of specified source Rectangle2D objects and puts the result into the specified destination Rectangle2D object.
Rectangle2D
  
Computes the intersection of this Rectangle with the specified Rectangle.
Rectangle
 Inherited
intersectsLine(x1:Number, y1:Number, x2:Number, y2:Number):Boolean
Tests if the specified line segment intersects the interior of this Rectangle2D.
Rectangle2D
 Inherited
Tests if the interior of this Rectangle2D intersects the specified Rectangle2D.
Rectangle2D
 Inherited
intersectsRectangle2(x:Number, y:Number, width:Number, height:Number):Boolean
Tests if the interior of this Rectangle2D intersects the interior of a specified set of rectangular coordinates.
Rectangle2D
  
Determines whether or not this Rectangle and the specified Rectangle intersect.
Rectangle
  
move(x:int, y:int):void
Rectangle
  
[static] Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.
Rectangle
  
[static]
Rectangle
  
[static] Constructs a new Rectangle, initialized to match the values of the specified Rectangle.
Rectangle
  
newRectangle4(width:int, height:int):Rectangle
[static] Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.
Rectangle
  
newRectangle5(x:int, y:int, width:int, height:int):Rectangle
[static] Constructs a new Rectangle whose top-left corner is specified as (x, y) and whose width and height are specified by the arguments of the same name.
Rectangle
 Inherited
Determines where the specified Point2D lies with respect to this Rectangle2D.
Rectangle2D
  
outcode2(px:Number, py:Number):int
[override] Determines where the specified coordinates lie with respect to this Rectangle.
Rectangle
  
reshape(x:int, y:int, width:int, height:int):void
Rectangle
  
resize(width:int, height:int):void
Rectangle
  
Rectangle
  
setBounds2(x:int, y:int, width:int, height:int):void
Sets the bounding Rectangle of this Rectangle to the specified x, y, width, and height.
Rectangle
 Inherited
setFrame(x:Number, y:Number, width:Number, height:Number):void
Sets the location and size of the outer bounds of this Rectangle2D to the specified rectangular values.
Rectangle2D
 Inherited
setFrame2(loc:Point2D, size:Dimension):void
Rectangle2D
 Inherited
setFrameFromCenter(center:Point2D, corner:Point2D):void
Sets the framing rectangle of this Shape based on a specified center Point2D and corner Point2D.
Rectangle2D
 Inherited
setFrameFromCenter2(centerX:Number, centerY:Number, cornerX:Number, cornerY:Number):void
Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates.
Rectangle2D
 Inherited
Sets the diagonal of the framing rectangle of this Shape based on the two specified coordinates.
Rectangle2D
 Inherited
setFrameFromDiagonal2(x1:Number, y1:Number, x2:Number, y2:Number):void
Sets the diagonal of the framing rectangle of this Shape based on the two specified coordinates.
Rectangle2D
  
setLocation(x:int, y:int):void
Moves this Rectangle to the specified location.
Rectangle
  
setRect(x:Number, y:Number, width:Number, height:Number):void
[override] Sets the bounds of this Rectangle to the specified x, y, width, and height.
Rectangle
  
setSize(width:int, height:int):void
Sets the size of this Rectangle to the specified width and height.
Rectangle
  
toString():String
Rectangle
  
translate(mx:int, my:int):void
Translates this Rectangle the indicated distance, to the right along the x coordinate axis, and downward along the y coordinate axis.
Rectangle
 Inherited
[static] Unions the pair of specified source Rectangle2D objects and puts the result into the specified destination Rectangle2D object.
Rectangle2D
  
Computes the union of this Rectangle with the specified Rectangle.
Rectangle
Protected Methods
 MethodDefined By
  
cloneImpl(o:Object):void
[override]
Rectangle
  
Initializes this object.
Rectangle
  
Initializes this object.
Rectangle
 Inherited
Rectangle2D
  
Initializes this object.
Rectangle
  
initRectangle4(width:int, height:int):void
Initializes this object.
Rectangle
  
initRectangle5(x:int, y:int, width:int, height:int):void
Initializes this object.
Rectangle
Public Constants
 ConstantDefined By
 InheritedOUT_BOTTOM : int = 8
[static] The bitmask that indicates that a point lies below this Rectangle2D.
Rectangle2D
 InheritedOUT_LEFT : int = 1
[static] The bitmask that indicates that a point lies to the left of this Rectangle2D.
Rectangle2D
 InheritedOUT_RIGHT : int = 4
[static] The bitmask that indicates that a point lies to the right of this Rectangle2D.
Rectangle2D
 InheritedOUT_TOP : int = 2
[static] The bitmask that indicates that a point lies above this Rectangle2D.
Rectangle2D
Property Detail
_heightproperty
public var _height:int

_widthproperty 
public var _width:int

_xproperty 
public var _x:int

_yproperty 
public var _y:int

boundsproperty 
bounds:Rectangle  [read-only] [override]

Gets the bounding Rectangle of this Rectangle.


Implementation
    public function get bounds():Rectangle
bounds2Dproperty 
bounds2D:Rectangle2D  [read-only] [override]

Return the high precision bounding box of this rectangle.


Implementation
    public function get bounds2D():Rectangle2D
emptyproperty 
empty:Boolean  [read-only] [override]

Determines whether or not this Rectangle is empty. A Rectangle is empty if its width or its height is less than or equal to zero.


Implementation
    public function get empty():Boolean
heightproperty 
height:Number  [read-only] [override]

Returns the height of the bounding Rectangle in double precision.


Implementation
    public function get height():Number
sizeproperty 
size:Dimension


Implementation
    public function get size():Dimension
    public function set size(value:Dimension):void
widthproperty 
width:Number  [read-only] [override]

Returns the width of the bounding Rectangle in double precision.


Implementation
    public function get width():Number
xproperty 
x:Number  [read-only] [override]

Returns the X coordinate of the bounding Rectangle in double precision.


Implementation
    public function get x():Number
yproperty 
y:Number  [read-only] [override]

Returns the Y coordinate of the bounding Rectangle in double precision.


Implementation
    public function get y():Number
Constructor Detail
Rectangle()Constructor
public function Rectangle(x:int, y:int, width:int, height:int, init:Boolean = true)

Constructs a new Rectangle whose top-left corner is specified as (x, y) and whose width and height are specified by the arguments of the same name.

Parameters
x:int — the specified x coordinate.
 
y:int — the specified y coordinate.
 
width:int — the width of the Rectangle.
 
height:int — the height of the Rectangle.
 
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.
Method Detail
addRectangle2()method
public function addRectangle2(r:Rectangle):void

Adds a Rectangle to this Rectangle. The resulting Rectangle is the union of the two rectangles.

Parameters

r:Rectangle — the specified Rectangle.

clone()method 
override public function clone():Object

Returns
Object
cloneImpl()method 
override protected function cloneImpl(o:Object):void

Parameters

o:Object

createIntersection()method 
override public function createIntersection(r:Rectangle2D):Rectangle2D

Returns a new Rectangle2D object representing the intersection of this Rectangle with the specified Rectangle2D.

Parameters

r:Rectangle2D — the Rectangle2D to be intersected with this Rectangle.

Returns
Rectangle2D — the largest Rectangle2D contained in both the specified Rectangle2D and in this Rectangle.
createUnion()method 
override public function createUnion(r:Rectangle2D):Rectangle2D

Returns a new Rectangle2D object representing the union of this Rectangle with the specified Rectangle2D.

Parameters

r:Rectangle2D — the Rectangle2D to be combined with this Rectangle.

Returns
Rectangle2D — the smallest Rectangle2D containing both the specified Rectangle2D and this Rectangle.
equals()method 
override public function equals(obj:Object):Boolean

Checks whether two rectangles are equal. The result is true if and only if the argument is not null and is a Rectangle object that has the same top-left corner, width, and height as this Rectangle.

Parameters

obj:Object — the Object to compare with this Rectangle

Returns
Boolean — true if the objects are equal; false otherwise.
getClass()method 
override public function getClass():Class

Returns
Class
grow()method 
public function grow(dx:int, dy:int):void

Resizes the Rectangle both horizontally and vertically.

This method modifies the Rectangle so that it is dx units larger on both the left and right side, and dy units larger at both the top and bottom.

The new Rectangle has (x - dx, y - dy) as its top-left corner, a width of width + 2dx, and a height of height + 2dy.

If negative values are supplied for dx and dy, the size of the Rectangle decreases accordingly. The grow method does not check whether the resulting values of width and height are non-negative.

Parameters

dx:int — the horizontal expansion
 
dy:int — the vertical expansion

initRectangle1()method 
protected final function initRectangle1():void

Initializes this object. See the documentation of the corresponding factory method newRectangle1() for details.

See also

initRectangle2()method 
protected final function initRectangle2(d:Dimension):void

Initializes this object. See the documentation of the corresponding factory method newRectangle2() for details.

Parameters

d:Dimension

See also

initRectangle3()method 
protected final function initRectangle3(r:Rectangle):void

Initializes this object. See the documentation of the corresponding factory method newRectangle3() for details.

Parameters

r:Rectangle

See also

initRectangle4()method 
protected final function initRectangle4(width:int, height:int):void

Initializes this object. See the documentation of the corresponding factory method newRectangle4() for details.

Parameters

width:int
 
height:int

See also

initRectangle5()method 
protected final function initRectangle5(x:int, y:int, width:int, height:int):void

Initializes this object. See the documentation of the corresponding factory method newRectangle5() for details.

Parameters

x:int
 
y:int
 
width:int
 
height:int

See also

intersection()method 
public function intersection(r:Rectangle):Rectangle

Computes the intersection of this Rectangle with the specified Rectangle. Returns a new Rectangle that represents the intersection of the two rectangles. If the two rectangles do not intersect, the result will be an empty rectangle.

Parameters

r:Rectangle — the specified Rectangle

Returns
Rectangle — the largest Rectangle contained in both the specified Rectangle and in this Rectangle; or if the rectangles do not intersect, an empty rectangle.
intersectsRectangle3()method 
public function intersectsRectangle3(r:Rectangle):Boolean

Determines whether or not this Rectangle and the specified Rectangle intersect. Two rectangles intersect if their intersection is nonempty.

Parameters

r:Rectangle — the specified Rectangle

Returns
Boolean — true if the specified Rectangle and this Rectangle intersect; false otherwise.
move()method 
public function move(x:int, y:int):void

Parameters

x:int
 
y:int

newRectangle1()method 
public static function newRectangle1():Rectangle

Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.

Returns
Rectangle
newRectangle2()method 
public static function newRectangle2(d:Dimension):Rectangle

Parameters

d:Dimension

Returns
Rectangle
newRectangle3()method 
public static function newRectangle3(r:Rectangle):Rectangle

Constructs a new Rectangle, initialized to match the values of the specified Rectangle.

Parameters

r:Rectangle — the Rectangle from which to copy initial values to a newly constructed Rectangle.

Returns
Rectangle
newRectangle4()method 
public static function newRectangle4(width:int, height:int):Rectangle

Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.

Parameters

width:int — the width of the Rectangle.
 
height:int — the height of the Rectangle.

Returns
Rectangle
newRectangle5()method 
public static function newRectangle5(x:int, y:int, width:int, height:int):Rectangle

Constructs a new Rectangle whose top-left corner is specified as (x, y) and whose width and height are specified by the arguments of the same name.

Parameters

x:int — the specified x coordinate.
 
y:int — the specified y coordinate.
 
width:int — the width of the Rectangle.
 
height:int — the height of the Rectangle.

Returns
Rectangle
outcode2()method 
override public function outcode2(px:Number, py:Number):int

Determines where the specified coordinates lie with respect to this Rectangle. This method computes a binary OR of the appropriate mask values indicating, for each side of this Rectangle, whether or not the specified coordinates are on the same side of the edge as the rest of this Rectangle.

Parameters

px:Number — the specified x coordinate.
 
py:Number — the specified y coordinate.

Returns
int — the logical OR of all appropriate out codes.
reshape()method 
public function reshape(x:int, y:int, width:int, height:int):void

Parameters

x:int
 
y:int
 
width:int
 
height:int

resize()method 
public function resize(width:int, height:int):void

Parameters

width:int
 
height:int

setBounds()method 
public function setBounds(r:Rectangle):void

Parameters

r:Rectangle

setBounds2()method 
public function setBounds2(x:int, y:int, width:int, height:int):void

Sets the bounding Rectangle of this Rectangle to the specified x, y, width, and height.

Parameters

x:int — the new x coordinate for the top-left corner of this Rectangle
 
y:int — the new y coordinate for the top-left corner of this Rectangle
 
width:int — the new width for this Rectangle
 
height:int — the new height for this Rectangle

setLocation()method 
public function setLocation(x:int, y:int):void

Moves this Rectangle to the specified location.

Parameters

x:int — the x coordinate of the new location.
 
y:int — the y coordinate of the new location.

setRect()method 
override public function setRect(x:Number, y:Number, width:Number, height:Number):void

Sets the bounds of this Rectangle to the specified x, y, width, and height.

Parameters

x:Number — the new x coordinate for the top-left corner of this Rectangle
 
y:Number — the new y coordinate for the top-left corner of this Rectangle
 
width:Number — the new width for this Rectangle
 
height:Number — the new height for this Rectangle

setSize()method 
public function setSize(width:int, height:int):void

Sets the size of this Rectangle to the specified width and height.

Parameters

width:int — the new width for this Rectangle.
 
height:int — the new height for this Rectangle.

toString()method 
public function toString():String

Returns
String
translate()method 
public function translate(mx:int, my:int):void

Translates this Rectangle the indicated distance, to the right along the x coordinate axis, and downward along the y coordinate axis.

Parameters

mx:int — - the distance to move this Rectangle along the x axis
 
my:int — - the distance to move this Rectangle along the y axis

unionWith()method 
public function unionWith(r:Rectangle):Rectangle

Computes the union of this Rectangle with the specified Rectangle. Returns a new Rectangle that represents the union of the two rectangles .

Parameters

r:Rectangle — the specified Rectangle

Returns
Rectangle — the smallest Rectangle containing both the specified Rectangle and this Rectangle.