User Tools

Site Tools


en:code:core:rect

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

  • (ParameterTypeError) incorrect parameter type
  • (ParameterCountError) incorrect parameter count

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

  • (Rect) a copy of this Rect

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

  • (bool) true if other is referencing the same rectangle

Example

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

toString

Returns a string representing this Rect.

Syntax

myObject.toString();

Returns

  • (string) a string representing this Rect

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

  • (Rect) this Rect

setTop

Sets the top value of this Rect.

Syntax

myObject.setTop(top);

Arguments

  1. top - (integer) the top value

Returns

  • (Rect) this Rect

setBottom

Sets the bottom value of this Rect.

Syntax

myObject.setBottom(bottom);

Arguments

  1. bottom - (integer) the bottom value

Returns

  • (Rect) this Rect

setLeft

Sets the left value of this Rect.

Syntax

myObject.setLeft(left);

Arguments

  1. left - (integer) the left value

Returns

  • (Rect) this Rect

setRight

Sets the right value of this Rect.

Syntax

myObject.setRight(right);

Arguments

  1. right - (integer) the right value

Returns

  • (Rect) this Rect

setX

Sets the x value of this Rect.

Syntax

myObject.setX(x);

Arguments

  1. x - (integer) the x value

Returns

  • (Rect) this Rect

setY

Sets the y value of this Rect.

Syntax

myObject.setY(y);

Arguments

  1. y - (integer) the y value

Returns

  • (Rect) this Rect

setWidth

Sets the width of this Rect.

Syntax

myObject.setWidth(width);

Arguments

  1. width - (integer) the width

Returns

  • (Rect) this Rect

setHeight

Sets the height of this Rect.

Syntax

myObject.setHeight(height);

Arguments

  1. height - (integer) the height

Returns

  • (Rect) this Rect

setSize

Sets the size of this Rect.

Syntax

myObject.setSize(size);

Arguments

  1. size - (Size) the new size

Returns

  • (Rect) this Rect

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

  • (Rect) this Rect

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

  • (Rect) this Rect

translate

Translates this Rect using a Point.

Syntax

myObject.translate(point);

Arguments

  1. point - (Point) the translate distance

Returns

  • (Rect) this Rect

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

  • (Rect) this Rect

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

  • (Rect) a new Rect

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

  • (Rect) a new Rect

intersects

Returns true if this Rect intersects another.

Syntax

myObject.intersects(rect);

Arguments

  1. rect - (Rect) the rectangle to check

Returns

  • (boolean) true if this Rect intersects another

isEmpty

Returns true if this Rect is empty.

Syntax

myObject.isEmpty();

Returns

  • (boolean) true if this Rect is empty

center

Returns a Point representing the center of this Rect.

Syntax

myObject.center();

Returns

  • (Point) the center of this Rect

size

Returns a Size representing the size of this Rect.

Syntax

myObject.size();

Returns

  • (Size) the size of this Rect

width

Returns the width of this Rect.

Syntax

myObject.width();

Returns

  • (integer) the width of this Rect

height

Returns the height of this Rect.

Syntax

myObject.height();

Returns

  • (integer) the height of this Rect

x

Returns the x coordinate of this Rect.

Syntax

myObject.x();

Returns

  • (integer) the x coordinate of this Rect

y

Returns the y coordinate of this Rect.

Syntax

myObject.y();

Returns

  • (integer) the y coordinate of this Rect

left

Returns the left coordinate of this Rect.

Syntax

myObject.left();

Returns

  • (integer) the left coordinate of this Rect

Returns the right coordinate of this Rect.

Syntax

myObject.right();

Returns

  • (integer) the top coordinate of this Rect

top

Returns the top coordinate of this Rect.

Syntax

myObject.top();

Returns

  • (integer) the top coordinate of this Rect

bottom

Returns the bottom coordinate of this Rect.

Syntax

myObject.bottom();

Returns

  • (integer) the bottom coordinate of this Rect

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)

en/code/core/rect.txt · Last modified: 2021/02/13 11:23 by 127.0.0.1