Skip to content
Jesper Sørensen edited this page Sep 7, 2014 · 1 revision

Class: Rectangle

Rectangle

A class which is used for drawable non-rotated rectangles

new Rectangle(x, y, width, height, fillStyle, strokeStyle, lineWidth)

The constructor for the Rectangle class. Uses the set-function to set the properties of the rectangle.

Parameters:
Name Type Argument Default Description
x number

The x-coordinate for the rectangle's top left corner

y number

The y-coordinate for the rectangle's top left corner

width number <optional>
0

The width of the rectangle

height number <optional>
0

The height of the rectangle

fillStyle string <optional>
"#000"

The rectangle's fill color if added to a view (css color string)

strokeStyle string <optional>
"#000"

The rectangle's color if added to a view (css color string)

lineWidth number <optional>
1

The rectangle's width if added to a view (in px)

Properties:
Name Type Description
x number

The top left corner's x-coordinate

y number

The top left corner's y-coordinate

width number

The width of the rectangle

height number

The height of the rectangle

strokeStyle string

The rectangle's color if added to a view (css color string)

lineWidth number

The rectangle's width if added to a view (in px)

fillStyle string

The rectangle's fill color if added to a view (css color string)

Source:

Extends

Methods

add(vector) → {Math.Vector}(vector) → {Math.Vector}

Adds another vector to the Vector. Can by used for the same purpose as move, but takes a vector as argument.

Parameters:
Name Type Description
vector Math.Vector

A vector to add to the Vector

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

animate(properties, options)(properties, options)

Used for animating numeric properties of the owner of the function. Available easing functions are: "linear" "quadIn" "quadOut" "quadInOut" "powerIn" "powerOut" "powerInOut" "sinusInOut"

Parameters:
Name Type Description
properties object

An object containing key-value pairs in the following format: { "[property name]": "[end value]" }

options object

An object containing key-value pairs for the animation's option: { "duraton": "[animation duration (in ms)]", "callback": "[callback function]", "easing": "[easing function to use]" }

Inherited From:
Source:

ChildInitWithoutRedrawRegions()()

Inherited From:
Source:

contains(object) → {boolean}(object) → {boolean}

Checks whether or not the Rectangle contains another geometric object.

Parameters:
Name Type Description
object Math.Vector | Math.Line | Math.Circle | Math.Rectangle | Math.Polygon

A geometric object to check

Inherited From:
Source:
Returns:

True if the Rectangle contains the checked object, false if not

Type
boolean

copy() → {Math.Rectangle}() → {Math.Rectangle}

Copies the Rectangle object

Inherited From:
Source:
Returns:

A copy of the Rectangle object (which can be modified without changing the original object)

Type
Math.Rectangle

divide(vector) → {Math.Vector}(vector) → {Math.Vector}

Divides the Vector with another vector.

Parameters:
Name Type Description
vector Math.Vector

A vector to divide the Vector with

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

getAnimations() → {Object[]}() → {Object[]}

Fetches all current animations of the object.

Inherited From:
Source:
Returns:

An array of all the current animations of the object

Type
Object[]

getArea() → {number}() → {number}

Calculates the area of the Rectangle.

Inherited From:
Source:
Returns:

The area of the Rectangle

Type
number

getBoundingRectangle(rectangle) → {Math.Rectangle}(rectangle) → {Math.Rectangle}

Calculates the bounding rectangle of the of the two rectangles

Parameters:
Name Type Description
rectangle Math.Rectangle

The rectangle to use for the calculation

Inherited From:
Source:
Returns:

The bounding rectangle for the two rectangles

Type
Math.Rectangle

getCross(vector) → {number}(vector) → {number}

Calculates the cross product of the Vector and another vector

Parameters:
Name Type Description
vector Math.Vector

The vector to use for the calculation

Inherited From:
Source:
Returns:

The cross product

Type
number

getDiagonal() → {number}() → {number}

Calculates the diagonal length of the Rectangle

Inherited From:
Source:
Returns:

The diagonal length of the Rectangle

Type
number

getDirection() → {number}() → {number}

Calculates the direction of the Vector

Inherited From:
Source:
Returns:

The vector's direction (in radians)

Type
number

getDirectionTo(child) → {number}(child) → {number}

Calculates the direction to another child

Parameters:
Name Type Description
child View.Child

The object to calculate the direction to

Inherited From:
Source:
Returns:

The direction in radians

Type
number

getDirectionTo(point) → {number}(point) → {number}

Calculates the direction to another Vector

Parameters:
Name Type Description
point Math.Vector

A Vector to calculate the direction to

Inherited From:
Source:
Returns:

The direction to the object

Type
number

getDistance(object) → {number}(object) → {number}

Calculates the shortest distance from the Rectangle object to another geometric object

Parameters:
Name Type Description
object Math.Vector | Math.Line | Math.Circle | Math.Rectangle | Math.Polygon

The object to calculate the distance to

Inherited From:
Source:
Returns:

The distance

Type
number

getDistanceTo(child) → {number}(child) → {number}

Calculates the distance to another child (the distance between the object's positions)

Parameters:
Name Type Description
child View.Child

The object to calculate the distance to

Inherited From:
Source:
Returns:

The distance in pixels

Type
number

getDot(vector) → {number}(vector) → {number}

Calculates the cross product of the Vector and another vector

Parameters:
Name Type Description
vector Math.Vector

The vector to use for the calculation

Inherited From:
Source:
Returns:

The dot product

Type
number

getLength() → {number}() → {number}

Calculates the length of the Vector

Inherited From:
Source:
Returns:

The vector's length

Type
number

getOverlap(rectangle) → {Math.Rectangle|boolean}(rectangle) → {Math.Rectangle|boolean}

Calculates the overlapping area of the rectangle and another rectangle

Parameters:
Name Type Description
rectangle Math.Rectangle

The rectangle to use for the operation

Inherited From:
Source:
Returns:

The overlapping rectangle, or false if there is no overlap

Type
Math.Rectangle | boolean

getParents() → {View.Container[]}() → {View.Container[]}

Creates and returns and array of all the child's parents (from closest to farthest)

Inherited From:
Source:
Returns:

A list of all the child's parents

Type
View.Container[]

getPoints() → {Math.Vector[]}() → {Math.Vector[]}

Fetches the Rectangles points.

Inherited From:
Source:
Returns:

Array of points, in the following order: top left corner, top right corner, bottom right corner, bottom left corner

Type
Math.Vector[]

getPolygon() → {Object}() → {Object}

Creates a polygon with the same points as the rectangle.

Inherited From:
Source:
Returns:

The created Polygon object

Type
Object

<private> getRedrawRegion() → {Rectangle}

Calculates the region which the object will fill out when redrawn.

Source:
Returns:

The bounding rectangle of the redraw

Type
Rectangle

getRoom() → {View.Room|Boolean}() → {View.Room|Boolean}

Finds the room to which the object is currently added

Inherited From:
Source:
Returns:

The room to which the object is currently added, or false if the object is not added to a room

Type
View.Room | Boolean

getRoomPosition() → {Math.Vector|Boolean}() → {Math.Vector|Boolean}

Fetches the position of the child inside the room

Inherited From:
Source:
Returns:

The objects position in its room, or false if the object is not placed in any room.

Type
Math.Vector | Boolean

intersects(object) → {boolean}(object) → {boolean}

Checks whether or not the Rectangle intersects with another geometric object.

Parameters:
Name Type Description
object Math.Line | Math.Circle | Math.Rectangle | Math.Polygon

A geometric object to check

Inherited From:
Source:
Returns:

True if the Polygon intersects with the checked object, false if not

Type
boolean

isAnimated() → {boolean}() → {boolean}

Checks if the object is currently being animated.

Inherited From:
Source:
Returns:

Whether or not the object is being animated

Type
boolean

isDrawn() → {Boolean}() → {Boolean}

Checks if the child object is in a state where it will get drawn. For this function to return true, the child object has to be both visible and placed in a visible room.

Inherited From:
Source:
Returns:

Whether or not the child object is in a state where it will get drawn

Type
Boolean

isInVisibleRoom() → {Boolean}() → {Boolean}

Checks if the child object is inside a room that is currently visible

Inherited From:
Source:
Returns:

Whether or not the child object is currently in a visible room

Type
Boolean

isVisible() → {boolean}() → {boolean}

Checks if the objects is visible. This function runs before each draw to ensure that it is necessary

Inherited From:
Source:
Returns:

Whether or not the object is visible (based on its size and opacity vars)

Type
boolean

move(x, y) → {Math.Rectangle}(x, y) → {Math.Rectangle}

Moves the Rectangle by adding a value to its x-coordinate and another value to its y-coordinate.

Parameters:
Name Type Description
x number

The value to add to the x-coordinate (can be negative)

y number

The value to add to the y-coordinate (can be negative)

Inherited From:
Source:
Returns:

The resulting Rectangle object (itself)

Type
Math.Rectangle

moveTo(x, y)(x, y)

Sets the position of the object relative to its parent

Parameters:
Name Type Description
x number

The horisontal position

y number

The vertical position

Inherited From:
Source:

moveTo(x, y) → {Math.Rectangle}(x, y) → {Math.Rectangle}

Moves the Rectangle to a fixed position by setting its x- and y-coordinates.

Parameters:
Name Type Description
x number

The x-coordinate of the position to move the Rectangle to

y number

The y-coordinate of the position to move the Rectangle to

Inherited From:
Source:
Returns:

The resulting Rectangle object (itself)

Type
Math.Rectangle

multiply(vector) → {Math.Vector}(vector) → {Math.Vector}

Multiplies the Vector with another vector.

Parameters:
Name Type Description
vector Math.Vector

A vector to multiply the Vector with

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

parseOffsetGlobal(offset) → {Math.Vector}

Parses an offset global into an actual Math.Vector offset that fits the instance

Parameters:
Name Type Description
offset number

Offset global (OFFSET_TOP_LEFT, etc.)

Source:
Returns:

The offset vector the offset global corresponds to for the instance

Type
Math.Vector

propertyIsAnimated() → {boolean}() → {boolean}

Checks if a specific property is current being animated

Inherited From:
Source:
Returns:

Whether or not the property is being animated

Type
boolean

RectangleInitWithoutRedrawRegions()

Source:

rotate(direction) → {Math.Vector}(direction) → {Math.Vector}

Rotates the vector around the zero-vector.

Parameters:
Name Type Description
direction number

The number of radians to rotate the vector

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

scale(scaleH, scaleV) → {Math.Rectangle}(scaleH, scaleV) → {Math.Rectangle}

Scales the Rectangle by multiplying the width and height values. Please notice that, opposed to the Polygon and Line objects, the position of the Rectangle will not be changed by scaling it, since the position of the top left corner will not be scaled.

Parameters:
Name Type Description
scaleH number

A factor with which to scale the Rectangle horizontally. If scaleH is undefined, both width and height will be scaled after this factor

scaleV number

A factor with which to scale the Rectangle vertically

Inherited From:
Source:
Returns:

The resulting Rectangle object (itself)

Type
Math.Rectangle

set(x, y, width, height) → {Math.Rectangle}(x, y, width, height) → {Math.Rectangle}

Sets the properties of the rectangle.

Parameters:
Name Type Description
x number

The x-coordinate for the rectangle's top left corner

y number

The y-coordinate for the rectangle's top left corner

width number

The width of the rectangle

height number

The height of the rectangle

Inherited From:
Source:
Returns:

The resulting Rectangle object (itself)

Type
Math.Rectangle

setFromDirection(direction, length) → {Math.Vector}(direction, length) → {Math.Vector}

Calculates and sets the vector from a direction and a length.

Parameters:
Name Type Description
direction number

The direction (in radians)

length number

The length

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

setFromVectors(position, size) → {Math.Rectangle}(position, size) → {Math.Rectangle}

Sets the properties of the rectangle from two vectors: one representing the position of the top left corner, another representing the width and height of the rectangle.

Parameters:
Name Type Description
position Math.Vector

A Vector representing the position of the top left corner to set for the Rectangle

size Math.Vector

A Vector representing the size (width and height) to set for the Rectangle

Inherited From:
Source:
Returns:

The resulting Rectangle object (itself)

Type
Math.Rectangle

stopAnimations()()

Stops all current animations of the object.

Inherited From:
Source:

subtract(vector) → {Math.Vector}(vector) → {Math.Vector}

Subtracts another vector from the Vector.

Parameters:
Name Type Description
vector Math.Vector

A vector to subtract from the Vector

Inherited From:
Source:
Returns:

The resulting Vector object (itself)

Type
Math.Vector

Generated with wicked.
Clone this wiki locally