Skip to content

editorGlobalsRectangle2D

Class: Rectangle2D

An Axis-Aligned 2D Rectangle

Hierarchy

  • Rectangle2D

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Rectangle2D(xMin: any, xMax: any, yMin: any, yMax: any): Rectangle2D

Defined in src/util/Rectangle2D.ts:19

Parameters:

Name Type
xMin any
xMax any
yMin any
yMax any

Returns: Rectangle2D

Properties

Private xMax

xMax: any

Defined in src/util/Rectangle2D.ts:17


Private xMin

xMin: any

Defined in src/util/Rectangle2D.ts:16


Private yMax

yMax: any

Defined in src/util/Rectangle2D.ts:19


Private yMin

yMin: any

Defined in src/util/Rectangle2D.ts:18

Methods

Private _getIntersectionPointsWithXLine

_getIntersectionPointsWithXLine(y: number): IPoint2[]

Defined in src/util/Rectangle2D.ts:160

Parameters:

Name Type
y number

Returns: IPoint2[]


Private _getIntersectionPointsWithYLine

_getIntersectionPointsWithYLine(x: number): IPoint2[]

Defined in src/util/Rectangle2D.ts:164

Parameters:

Name Type
x number

Returns: IPoint2[]


add

add(other: Rectangle2D): this

Defined in src/util/Rectangle2D.ts:48

Minkowski Sum of shapes: https://en.wikipedia.org/wiki/Minkowski_addition

Parameters:

Name Type
other Rectangle2D

Returns: this


centeredAroundOrigin

centeredAroundOrigin(): Rectangle2D

Defined in src/util/Rectangle2D.ts:39

Create a new rectangle with the same dimensions as this one, but centered around the coordinate origin

Returns: Rectangle2D


contains

contains(p: IPoint2): boolean

Defined in src/util/Rectangle2D.ts:76

The border of the rectangle is not considered inside

Parameters:

Name Type
p IPoint2

Returns: boolean


equals

equals(other: Rectangle2D): boolean

Defined in src/util/Rectangle2D.ts:28

Parameters:

Name Type
other Rectangle2D

Returns: boolean


fitAtPosition

fitAtPosition(targetPosition: IPoint2, blockingRectangles: Rectangle2D[], padding: number): IPoint2

Defined in src/util/Rectangle2D.ts:115

Calculate the best position for this rectangle amongst the list of blocking ones. This position is as close as possible to "targetPosition", while still keeping at least "padding" distance to existing rects. This method will expand the given blocking rectangles and therefore modify them.

Parameters:

Name Type Default Description
targetPosition IPoint2 - where the center of this rect should ideally be positioned
blockingRectangles Rectangle2D[] - list of rects to not intersect with / keep distance
padding number 0 how much distance to keep to all existing rects.

Returns: IPoint2


getCenterPoint

getCenterPoint(): IPoint2

Defined in src/util/Rectangle2D.ts:32

Returns: IPoint2


getEdgePoints

getEdgePoints(): IPoint2[]

Defined in src/util/Rectangle2D.ts:64

Returns: IPoint2[]


getIntersectionPoints

getIntersectionPoints(other: Rectangle2D): IPoint2[]

Defined in src/util/Rectangle2D.ts:83

Compute the list of points where this rectangle intersects with the given one.

Parameters:

Name Type
other Rectangle2D

Returns: IPoint2[]


getIntersectionRect

getIntersectionRect(other: Rectangle2D): Rectangle2D | null

Defined in src/util/Rectangle2D.ts:94

If this rectangle intersects with the given one, return the intersection area as new rectangle. Otherwise, return null.

Parameters:

Name Type
other Rectangle2D

Returns: Rectangle2D | null


grow

grow(delta: number): this

Defined in src/util/Rectangle2D.ts:56

Parameters:

Name Type
delta number

Returns: this


Static fromAABB

fromAABB(aabb: AABB): Rectangle2D‹›

Defined in src/util/Rectangle2D.ts:12

Use the x and y dimensions of the given AABB as rectangle dimensions

Parameters:

Name Type
aabb AABB

Returns: Rectangle2D‹›