Table of Contents

Rect

This object represents a rectangle in a 2D space.

Functions

Rect

Constructor function.

Syntax

var myObject = new Rect();
var myObject = new Rect(otherRect);
var myObject = new Rect(left, top, width, height);

Arguments

  1. otherRect - (Rect) other Rect to copy
  2. left - (integer) left position of the Rect
  3. top - (integer) top position of the Rect
  4. width - (integer) width of the Rect
  5. height - (integer) height of the Rect

Exceptions

Example

Create a Rect representing an empty rectangle.

var myObject = new Rect();

Create a Rect representing a copy of otherRect.

var myObject = new Rect(otherRect);

Create a Rect representing a rectangle.

var myObject = new Rect(50, 75, 100, 100);

Methods

clone

Returns a copy of this Rect.

Syntax

myObject.clone();

Returns

Example

var copyOfMyObject = myObject.clone();

equals

Returns true if this Rect and another are referencing the same rectangle.

Syntax

myObject.equals(other);

Arguments

  1. other - (Rect) another Rect

Returns

Example

if(myFirstObject.equals(mySecondObject))
	//Do something

toString

Returns a string representing this Rect.

Syntax

myObject.toString();

Returns

Example

Console.print(myObject.toString());

Notes

This method is automatically called when trying to convert a Rect to a string.

normalize

Normalizes this Rect; sets it to a Rect that has a non-negative width and height.

Syntax

myObject.normalize();

Returns

setTop

Sets the top value of this Rect.

Syntax

myObject.setTop(top);

Arguments

  1. top - (integer) the top value

Returns

setBottom

Sets the bottom value of this Rect.

Syntax

myObject.setBottom(bottom);

Arguments

  1. bottom - (integer) the bottom value

Returns

setLeft

Sets the left value of this Rect.

Syntax

myObject.setLeft(left);

Arguments

  1. left - (integer) the left value

Returns

setRight

Sets the right value of this Rect.

Syntax

myObject.setRight(right);

Arguments

  1. right - (integer) the right value

Returns

setX

Sets the x value of this Rect.

Syntax

myObject.setX(x);

Arguments

  1. x - (integer) the x value

Returns

setY

Sets the y value of this Rect.

Syntax

myObject.setY(y);

Arguments

  1. y - (integer) the y value

Returns

setWidth

Sets the width of this Rect.

Syntax

myObject.setWidth(width);

Arguments

  1. width - (integer) the width

Returns

setHeight

Sets the height of this Rect.

Syntax

myObject.setHeight(height);

Arguments

  1. height - (integer) the height

Returns

setSize

Sets the size of this Rect.

Syntax

myObject.setSize(size);

Arguments

  1. size - (Size) the new size

Returns

setCoords

Sets the coordinates of the rectangle's top-left corner to (x1, y1) and the coordinates of its bottom-right corner to (x2, y2).

Syntax

myObject.setCoords(x1, y1, x2, y2);

Arguments

  1. x1 - (integer) the x coordinate of the top-left corner
  2. x2 - (integer) the x coordinate of the bottom-right corner
  3. y1 - (integer) the y coordinate of the top-left corner
  4. y2 - (integer) the y coordinate of the bottom-right corner

Returns

setRect

Sets the rectangle of this Rect.

Syntax

myObject.setRect(x, y, width, height);

Arguments

  1. x - (integer) the x coordinate of the top-left corner
  2. y - (integer) the y coordinate of the top-left corner
  3. width - (integer) the width of this Rect
  4. height - (integer) the height of this Rect

Returns

translate

Translates this Rect using a Point.

Syntax

myObject.translate(point);

Arguments

  1. point - (Point) the translate distance

Returns

contains

Returns true if a Point or a Rect is contained within this Rect.

Syntax

myObject.contains(point);
myObject.contains(rect);
myObject.contains(x, y);
myObject.contains(left, top, width, height);

Arguments

  1. point - (Point) the point to check
  2. rect - (Rect) the rectangle to check
  3. x - (integer) the x coordinate of the point to check
  4. y - (integer) the y coordinate of the point to check
  5. left - (integer) left position of the rectangle to check
  6. top - (integer) top position of the rectangle to check
  7. width - (integer) width of the rectangle to check
  8. height - (integer) height of the rectangle to check

Returns

united

Returns the bounding rectangle of this Rect united with another Rect.

Syntax

myObject.united(rect);

Arguments

  1. rect - (Rect) the rectangle to unite

Returns

intersected

Returns the bounding rectangle of this Rect intersected with another Rect.

Syntax

myObject.intersected(rect);

Arguments

  1. rect - (Rect) the rectangle to intersect

Returns

intersects

Returns true if this Rect intersects another.

Syntax

myObject.intersects(rect);

Arguments

  1. rect - (Rect) the rectangle to check

Returns

isEmpty

Returns true if this Rect is empty.

Syntax

myObject.isEmpty();

Returns

center

Returns a Point representing the center of this Rect.

Syntax

myObject.center();

Returns

size

Returns a Size representing the size of this Rect.

Syntax

myObject.size();

Returns

width

Returns the width of this Rect.

Syntax

myObject.width();

Returns

height

Returns the height of this Rect.

Syntax

myObject.height();

Returns

x

Returns the x coordinate of this Rect.

Syntax

myObject.x();

Returns

y

Returns the y coordinate of this Rect.

Syntax

myObject.y();

Returns

left

Returns the left coordinate of this Rect.

Syntax

myObject.left();

Returns

Returns the right coordinate of this Rect.

Syntax

myObject.right();

Returns

top

Returns the top coordinate of this Rect.

Syntax

myObject.top();

Returns

bottom

Returns the bottom coordinate of this Rect.

Syntax

myObject.bottom();

Returns

Attributes

width

The width of this Point. (integer)

height

The height of this Point. (integer)

x

The x coordinate of this Point. (integer)

y

The y coordinate of this Point. (integer)

left

The left coordinate of this Point. (integer)

right

The right coordinate of this Point. (integer)

top

The top coordinate of this Point. (integer)

bottom

The bottom coordinate of this Point. (integer)