Class: Rectangle

graphics.geom. Rectangle


new Rectangle( [x] [, y] [, width] [, height])

The Rectangle class is used to create and modify Rectangle objects.

The Rectangle class is used to create and modify Rectangle objects.

A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y), and by its width and its height.

The x, y, width, and height properties of the Rectangle class are independent of each other; changing the value of one property has no effect on the others.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x value of the object.

y number <optional>
0

The y value of the object.

width number <optional>
0

The width value of the object.

height number <optional>
0

The height value of the object.

Extends

Members


area :Number

The area of the rectangle.

Type:
  • Number
Default Value:
  • 0
Example
var rectangle = new Rectangle( 0 , 0 , 40 , 12 ) ;trace( rectangle.area ) ; // 480

bottom

The sum of the y and height properties.


bottomLeft

The location of the Rectangle object's bottom-left corner, determined by the values of the left and bottom properties.


bottomRight

The location of the Rectangle object's bottom-right corner, determined by the values of the right and bottom properties.


center

The location of the Rectangle object's center.


centerX

Indicates the x coordinate of the Rectangle center.


centerY

Indicates the y coordinate of the Rectangle center.


height :Number

The height of the rectangle, in pixels.

Type:
  • Number
Inherited From:
Default Value:
  • 0

left

The x coordinate of the top-left corner of the rectangle.


perimeter :Number

The perimeter of the rectangle.

Type:
  • Number
Default Value:
  • 0
Example
var rectangle = new Rectangle( 0 , 0 , 40 , 12 ) ;trace( rectangle.perimeter ) ; // 104

The sum of the x and width properties.


size

The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.


top

The y coordinate of the top-left corner of the rectangle.


topLeft

The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.


topRight

The location of the Rectangle object's top-right corner, determined by the x and y coordinates of the point.


width :Number

The width of the rectangle, in pixels.

Type:
  • Number
Inherited From:
Default Value:
  • 0

x :Number

Determinates the x value of this object.

Type:
  • Number
Default Value:
  • 0

x :Number

Determinates the x value of this object.

Type:
  • Number
Default Value:
  • 0

y :Number

Determinates the y value of this object.

Type:
  • Number
Default Value:
  • 0

y :Number

Determinates the y value of this object.

Type:
  • Number
Default Value:
  • 0

Methods


<static> aabb(points [, out])

Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.

Parameters:
Name Type Argument Default Description
points Array.<graphics.geom.Vector2D>

The array of one or more points.

out graphics.geom.Rectangle <optional>
null

Optional rectangle to store the value in, if not supplied a new Rectangle object will be created.

Returns:

The new Rectangle object.

Type
graphics.geom.Rectangle

centerOn(x, y)

Centers this Rectangle so that the center coordinates match the given x and y values.

Parameters:
Name Type Description
x number

The x coordinate to place the center of the Rectangle at.

y number

The y coordinate to place the center of the Rectangle at.

Returns:

The current reference of the object.


clone()

Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.

Overrides:
Returns:

a shallow copy of the object.


contains(x, y)

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.

Parameters:
Name Type Description
x number

The x position of the point to check.

y number

The y position of the point to check.


containsPoint(point)

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.

Parameters:
Name Type Description
point Object | graphics.geom.Point

The point to check.


containsRect(rec)

Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object.

Parameters:
Name Type Description
rec Object | graphics.geom.Rectangle

The rectangle area to check.


copyFrom(rec)

Copies all of rectangle data from the source Rectangle object into the calling Rectangle object.

Parameters:
Name Type Description
rec graphics.geom.Rectangle | Object

The rectangle object to copy.

Overrides:

decrease( [dWidth] [, dHeight])

Decreases the size by a specific width/height values and return its self(this).

Parameters:
Name Type Argument Default Description
dWidth number <optional>
0

A number value to descrease the width component of the object (default 0).

dHeight number <optional>
0

A number value to descrease the height component of the object (default 0).

Inherited From:

equals(toCompareThe [, strict])

Determines whether the object specified in the toCompare parameter is equal to this Rectangle object.

Parameters:
Name Type Argument Default Description
toCompareThe object

object to evaluates.

strict boolean <optional>
true

If true the method accept only a toCompare Rectangle, else any object with the x, y, width and height properties (default true).

Overrides:
Returns:

true if the the specified object is equal with this object.

Type
boolean

increase( [dWidth] [, dHeight])

Increases the size by a specific width/height values and return its self(this).

Parameters:
Name Type Argument Default Description
dWidth number <optional>
0

A number value to increase the width component of the object (default 0).

dHeight number <optional>
0

A number value to inscrease the height component of the object (default 0).

Inherited From:
Returns:

the current reference of this object.


inflate(dx, dy)

Increases the size of the Rectangle object by the specified amounts, in pixels. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.

Parameters:
Name Type Description
dx number

The value to be added to the left and the right of the Rectangle object. The following equation is used to calculate the new width and position of the rectangle: x -= dx; width += 2 * dx;

dy number

The value to be added to the top and the bottom of the Rectangle. The following equation is used to calculate the new height and position of the rectangle: y -= dy; height += 2 * dy;


inflatePoint(point)

Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.

Parameters:
Name Type Description
point graphics.geom.Point

The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.

Example
var rect  = new Rectangle(0,0,2,5);var point = new Point(2,2);rect.inflatePoint(point) ;

intersection(toIntersect)

If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.

Parameters:
Name Type Description
toIntersect graphics.geom.Rectangle

The Rectangle object to compare against to see if it intersects with this Rectangle object.

Returns:

A Rectangle object that equals the area of intersection. If the rectangles do not intersect, this method returns an empty Rectangle object; that is, a rectangle with its x, y, width, and height properties set to 0.

Type
graphics.geom.Rectangle

intersects(toIntersect)

Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object. This method checks the x, y, width, and height properties of the specified Rectangle object to see if it intersects with this Rectangle object.

Parameters:
Name Type Description
toIntersect graphics.geom.Rectangle

The Rectangle object to compare against this Rectangle object.

Returns:

A value of true if the specified object intersects with this Rectangle object; otherwise false.

Type
boolean

isEmpty()

Determines whether or not this Rectangle object is empty.

Inherited From:
Returns:

A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.

Type
boolean

offset( [dx] [, dy])

Adjusts the location of the object, as determined by its top-left corner, by the specified amounts.

Parameters:
Name Type Argument Default Description
dx number <optional>
0

Moves the x value of the Rectangle object by this amount.

dy number <optional>
0

Moves the y value of the Rectangle object by this amount.


offsetPoint(point)

Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.

Parameters:
Name Type Description
point graphics.geom.Point

A Point object to use to offset this Rectangle object.


resize( [width] [, height])

Sets the width and heigth members of Rectangle to the specified values.

Parameters:
Name Type Argument Default Description
width number <optional>
0

The width of the rectangle, in pixels (default 0).

height number <optional>
0

The height of the rectangle, in pixels (default 0).

Returns:

The object reference.

Type
Rectangle

setTo( [x] [, y] [, width] [, height])

Sets the members of Rectangle to the specified values.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x coordinate of the top-left corner of the rectangle (default 0).

y number <optional>
0

The y coordinate of the top-left corner of the rectangle (default 0).

width number <optional>
0

The width of the rectangle, in pixels (default 0).

height number <optional>
0

The height of the rectangle, in pixels (default 0).

Overrides:
Returns:

The object reference.

Type
Rectangle

toObject()

Returns the Object representation of this object.

Overrides:
Returns:

the Object representation of this object.


toString()

Returns the string representation of this instance.

Overrides:
Returns:

the string representation of this instance.


union(toUnion)

Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles. Note: The union() method ignores rectangles with 0 as the height or width value, such as: var rect2 = new Rectangle(300,300,50,0);

Parameters:
Name Type Description
toUnion Rectangle

A Rectangle object to add to this Rectangle object.

Returns:

A new Rectangle object that is the union of the two rectangles.

Type
Rectangle