Shaku

Shaku JS

Back To Table of Content

Rectangle

Rectangle

Implement a simple 2d Rectangle.

Kind: global class

new Rectangle(x, y, width, height)

Create the Rect.

Param Type Description
x Number Rect position X (top left corner).
y Number Rect position Y (top left corner).
width Number Rect width.
height Number Rect height.

rectangle.left ⇒ Number

Get left value.

Kind: instance property of Rectangle
Returns: Number - rectangle left.

rectangle.right ⇒ Number

Get right value.

Kind: instance property of Rectangle
Returns: Number - rectangle right.

rectangle.top ⇒ Number

Get top value.

Kind: instance property of Rectangle
Returns: Number - rectangle top.

rectangle.bottom ⇒ Number

Get bottom value.

Kind: instance property of Rectangle
Returns: Number - rectangle bottom.

rectangle.set(x, y, width, height) ⇒ Rectangle

Set rectangle values.

Kind: instance method of Rectangle
Returns: Rectangle - this.

Param Type Description
x Number Rectangle x position.
y Number Rectangle y position.
width Number Rectangle width.
height Number Rectangle height.

rectangle.copy(other) ⇒ Rectangle

Copy another rectangle.

Kind: instance method of Rectangle
Returns: Rectangle - this.

Param Type Description
other other Rectangle to copy.

rectangle.getPosition() ⇒ Vector2

Get position as Vector2.

Kind: instance method of Rectangle
Returns: Vector2 - Position vector.

rectangle.getSize() ⇒ Vector2

Get size as Vector2.

Kind: instance method of Rectangle
Returns: Vector2 - Size vector.

rectangle.getCenter() ⇒ Vector2

Get center position.

Kind: instance method of Rectangle
Returns: Vector2 - Position vector.

rectangle.clone() ⇒ Rectangle

Return a clone of this rectangle.

Kind: instance method of Rectangle
Returns: Rectangle - Cloned rectangle.

rectangle.getTopLeft() ⇒ Vector2

Get top-left corner.

Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.

rectangle.getTopRight() ⇒ Vector2

Get top-right corner.

Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.

rectangle.getBottomLeft() ⇒ Vector2

Get bottom-left corner.

Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.

rectangle.getBottomRight() ⇒ Vector2

Get bottom-right corner.

Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.

rectangle.string()

Convert to string.

Kind: instance method of Rectangle

rectangle.containsVector(p) ⇒ Boolean

Check if this rectangle contains a Vector2.

Kind: instance method of Rectangle
Returns: Boolean - if point is contained within the rectangle.

Param Type Description
p Vector2 Point to check.

rectangle.collideRect(other) ⇒ Boolean

Check if this rectangle collides with another rectangle.

Kind: instance method of Rectangle
Returns: Boolean - if rectangles collide.

Param Type Description
other Rectangle Rectangle to check collision with.

rectangle.collideLine(line) ⇒ Boolean

Check if this rectangle collides with a line.

Kind: instance method of Rectangle
Returns: Boolean - if rectangle collides with line.

Param Type Description
line Line Line to check collision with.

rectangle.collideCircle(circle) ⇒ Boolean

Checks if this rectangle collides with a circle.

Kind: instance method of Rectangle
Returns: Boolean - if rectangle collides with circle.

Param Type Description
circle Circle Circle to check collision with.

rectangle.getBoundingCircle() ⇒ Circle

Get the smallest circle containing this rectangle.

Kind: instance method of Rectangle
Returns: Circle - Bounding circle.

rectangle.resize(amount) ⇒ Rectangle

Return a resized rectangle with the same center point.

Kind: instance method of Rectangle
Returns: Rectangle - resized rectangle.

Param Type Description
amount Number | Vector2 Amount to resize.

rectangle.equals(other)

Check if equal to another rectangle.

Kind: instance method of Rectangle

Param Type Description
other Rectangle Other rectangle to compare to.

rectangle.toDict(minimized) ⇒ \*

Convert to dictionary.

Kind: instance method of Rectangle
Returns: \* - Dictionary with {x,y,width,height}

Param Type Description
minimized Boolean If true, will not include keys that their values are 0. You can use fromDict on minimized dicts.

Rectangle.fromPoints(points) ⇒ Rectangle

Build and return a rectangle from points.

Kind: static method of Rectangle
Returns: Rectangle - new rectangle from points.

Param Type Description
points Array.<Vector2> Points to build rectangle from.

Rectangle.lerp(p1, p2, a) ⇒ Rectangle

Lerp between two rectangles.

Kind: static method of Rectangle
Returns: Rectangle - result rectangle.

Param Type Description
p1 Rectangle First rectangles.
p2 Rectangle Second rectangles.
a Number Lerp factor (0.0 - 1.0).

Rectangle.fromDict(data) ⇒ Rectangle

Create rectangle from a dictionary.

Kind: static method of Rectangle
Returns: Rectangle - Newly created rectangle.

Param Type Description
data \* Dictionary with {x,y,width,height}.