====== 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 === - otherRect - (Rect) other Rect to copy - left - (integer) left position of the Rect - top - (integer) top position of the Rect - width - (integer) width of the Rect - 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 === - 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 === - top - (integer) the top value === Returns === * (Rect) this Rect ==== setBottom ==== Sets the bottom value of this Rect. === Syntax === myObject.setBottom(bottom); === Arguments === - bottom - (integer) the bottom value === Returns === * (Rect) this Rect ==== setLeft ==== Sets the left value of this Rect. === Syntax === myObject.setLeft(left); === Arguments === - left - (integer) the left value === Returns === * (Rect) this Rect ==== setRight ==== Sets the right value of this Rect. === Syntax === myObject.setRight(right); === Arguments === - right - (integer) the right value === Returns === * (Rect) this Rect ==== setX ==== Sets the x value of this Rect. === Syntax === myObject.setX(x); === Arguments === - x - (integer) the x value === Returns === * (Rect) this Rect ==== setY ==== Sets the y value of this Rect. === Syntax === myObject.setY(y); === Arguments === - y - (integer) the y value === Returns === * (Rect) this Rect ==== setWidth ==== Sets the width of this Rect. === Syntax === myObject.setWidth(width); === Arguments === - width - (integer) the width === Returns === * (Rect) this Rect ==== setHeight ==== Sets the height of this Rect. === Syntax === myObject.setHeight(height); === Arguments === - height - (integer) the height === Returns === * (Rect) this Rect ==== setSize ==== Sets the size of this Rect. === Syntax === myObject.setSize(size); === Arguments === - size - (Size) the new [[en:code:core: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 === - x1 - (integer) the x coordinate of the top-left corner - x2 - (integer) the x coordinate of the bottom-right corner - y1 - (integer) the y coordinate of the top-left corner - 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 === - x - (integer) the x coordinate of the top-left corner - y - (integer) the y coordinate of the top-left corner - width - (integer) the width of this Rect - height - (integer) the height of this Rect === Returns === * (Rect) this Rect ==== translate ==== Translates this Rect using a [[en:code:core:point|Point]]. === Syntax === myObject.translate(point); === Arguments === - point - ([[en:code:core:point|Point]]) the translate distance === Returns === * (Rect) this Rect ==== contains ==== Returns true if a [[en:code:core:point|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 === - point - ([[en:code:core:point|Point]]) the point to check - rect - (Rect) the rectangle to check - x - (integer) the x coordinate of the point to check - y - (integer) the y coordinate of the point to check - left - (integer) left position of the rectangle to check - top - (integer) top position of the rectangle to check - width - (integer) width of the rectangle to check - 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 === - 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 === - rect - (Rect) the rectangle to intersect === Returns === * (Rect) a new Rect ==== intersects ==== Returns true if this Rect intersects another. === Syntax === myObject.intersects(rect); === Arguments === - 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 [[en:code:core:point|Point]] representing the center of this Rect. === Syntax === myObject.center(); === Returns === * ([[en:code:core:point|Point]]) the center of this Rect ==== size ==== Returns a [[en:code:core:size|Size]] representing the size of this Rect. === Syntax === myObject.size(); === Returns === * ([[en:code:core:size|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 ==== right ==== 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)