Home Reference Source
import {Rectangle} from 'shapez.io/js/core/rectangle.js'
public class | source

Rectangle

You can directly use an instance of this class. FULL_CLIP_RECT

Static Method Summary

Static Public Methods
public static

fromSquare(x: number, y: number, size: number): *

Constructs a new square rectangle

public static

fromTRBL(top: number, right: number, bottom: number, left: number): *

Creates a rectangle from top right bottom and left offsets

public static

fromTwoPoints(p1: Vector, p2: Vector): *

public static

Returns if a intersects b

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

h: *

public

w: *

public

x: *

public

y: *

Method Summary

Public Methods
public

allScaled(factor: number): *

Scales every parameter (w, h, x, y) by the given factor.

public
public

Returns the bottom left point

public

Copies this instance

public

Returns if the rectangle contains the given circle at (x, y) with the radius (radius)

public

Returns if hte rectangle contains the given point

public

Returns if the given rectangle is contained

public

Returns if this rectangle contains the other rectangle specified by the parameters

public

equalsEpsilon(other: Rectangle, epsilon: number): *

Returns if this rectangle is equal to the other while taking an epsilon into account

public

Expands the rectangle in all directions

public

Returns the center of the rect

public

Returns the shared area with another rectangle, or null if there is no intersection

public

getUnion(rect: Rectangle): *

Returns the union of this rectangle with another

public

Returns if this rectangle is empty

public
public

moveBy(x: number, y: number)

Moves the rectangle by the given parameters

public

Moves the rectangle by the given vector

public
public

setBottom(bottom: number)

Sets the bottom side of the rect without moving it

public

setLeft(left: number)

Sets the left side of the rect without scaling it

public

setRight(right: number)

Sets the right side of the rect without moving it

public

setTop(top: number)

Sets the top side of the rect without scaling it

public

Good for caching stuff

public

toString(): *

Good for printing stuff

public

Returns a new rectangle in tile space which includes all tiles which are visible in this rect

public

top(): number

public

Returns the top left point

public

trbl(): [number, number, number, number]

Returns Top, Right, Bottom, Left

Static Public Methods

public static fromSquare(x: number, y: number, size: number): * source

Constructs a new square rectangle

Params:

NameTypeAttributeDescription
x number
y number
size number

Return:

*

public static fromTRBL(top: number, right: number, bottom: number, left: number): * source

Creates a rectangle from top right bottom and left offsets

Params:

NameTypeAttributeDescription
top number
right number
bottom number
left number

Return:

*

public static fromTwoPoints(p1: Vector, p2: Vector): * source

Params:

NameTypeAttributeDescription
p1 Vector
p2 Vector

Return:

*

public static intersects(a: Rectangle, b: Rectangle): * source

Returns if a intersects b

Params:

NameTypeAttributeDescription
a Rectangle
b Rectangle

Return:

*

Public Constructors

public constructor() source

Public Members

public h: * source

public w: * source

public x: * source

public y: * source

Public Methods

public allScaled(factor: number): * source

Scales every parameter (w, h, x, y) by the given factor. Useful to transform from world to tile space and vice versa

Params:

NameTypeAttributeDescription
factor number

Return:

*

public bottom(): number source

Return:

number

public bottomRight(): Vector source

Returns the bottom left point

Return:

Vector

public clone(): Rectangle source

Copies this instance

Return:

Rectangle

public containsCircle(x: number, y: number, radius: number): boolean source

Returns if the rectangle contains the given circle at (x, y) with the radius (radius)

Params:

NameTypeAttributeDescription
x number
y number
radius number

Return:

boolean

public containsPoint(x: number, y: number): boolean source

Returns if hte rectangle contains the given point

Params:

NameTypeAttributeDescription
x number
y number

Return:

boolean

public containsRect(rect: Rectangle): boolean source

Returns if the given rectangle is contained

Params:

NameTypeAttributeDescription
rect Rectangle

Return:

boolean

public containsRect4Params(x: number, y: number, w: number, h: number): boolean source

Returns if this rectangle contains the other rectangle specified by the parameters

Params:

NameTypeAttributeDescription
x number
y number
w number
h number

Return:

boolean

public equalsEpsilon(other: Rectangle, epsilon: number): * source

Returns if this rectangle is equal to the other while taking an epsilon into account

Params:

NameTypeAttributeDescription
other Rectangle
epsilon number

Return:

*

public expandedInAllDirections(amount: number): Rectangle source

Expands the rectangle in all directions

Params:

NameTypeAttributeDescription
amount number

Return:

Rectangle

new rectangle

public getCenter(): Vector source

Returns the center of the rect

Return:

Vector

public getIntersection(rect: Rectangle): Rectangle | null source

Returns the shared area with another rectangle, or null if there is no intersection

Params:

NameTypeAttributeDescription
rect Rectangle

Return:

Rectangle | null

public getUnion(rect: Rectangle): * source

Returns the union of this rectangle with another

Params:

NameTypeAttributeDescription
rect Rectangle

Return:

*

public isEmpty(): boolean source

Returns if this rectangle is empty

Return:

boolean

public left(): number source

Return:

number

public moveBy(x: number, y: number) source

Moves the rectangle by the given parameters

Params:

NameTypeAttributeDescription
x number
y number

public moveByVector(vec: Vector) source

Moves the rectangle by the given vector

Params:

NameTypeAttributeDescription
vec Vector

public right(): number source

Return:

number

public setBottom(bottom: number) source

Sets the bottom side of the rect without moving it

Params:

NameTypeAttributeDescription
bottom number

public setLeft(left: number) source

Sets the left side of the rect without scaling it

Params:

NameTypeAttributeDescription
left number

public setRight(right: number) source

Sets the right side of the rect without moving it

Params:

NameTypeAttributeDescription
right number

public setTop(top: number) source

Sets the top side of the rect without scaling it

Params:

NameTypeAttributeDescription
top number

public toCompareableString(): * source

Good for caching stuff

Return:

*

public toString(): * source

Good for printing stuff

Return:

*

public toTileCullRectangle(): Rectangle source

Returns a new rectangle in tile space which includes all tiles which are visible in this rect

Return:

Rectangle

public top(): number source

Return:

number

public topLeft(): Vector source

Returns the top left point

Return:

Vector

public trbl(): [number, number, number, number] source

Returns Top, Right, Bottom, Left

Return:

[number, number, number, number]