Rect (AABB Rectangle)
Constructors
Rect
(x: number, y: number, width: number, height: number)
Creates a new instance of the rectangle with certain parameters
Rect
.zero
()
Creates a new instance of the rectangle with coordinates (0,0) and zero size
Rect
.size
(width: number, height: number)
(size: TSize)
Creates a new instance of the rectangle from a size with coordinates (0,0)
Rect
.from
(rect: TRect)
Creates a new instance of the rectangle from a rect like object
Rect
.fromTwoPoints
(p0: TPoint, p1: TPoint)
Creates a new instance from two points a top-left and a bottom-right corners
Rect
.fromCenter
(center: TPoint, width: number, height: number)
Creates a new instance of the rectangle from a center point and specified width and height
Rect
.merge
(rects: TRect[])
Gets bounded rect
Properties
x
:number
get set
Gets or sets x position of the rect
y
:number
get set
Gets or sets y position of the rect
width
:number
get set
Gets or sets width position of the rect
height
:number
get set
Gets or sets height position of the rect
absWidth
:number
get
Gets absolute width position of the rect
absHeight
:number
get
Gets absolute height position of the rect
absCenter
:TPoint
get
Gets the absolute center position of the rect
center
:Point
get set
Gets or sets the center position of the rect
(changes to the x and y properties will have no effect on the target object)
topLeft
:Point
get set
Gets or sets top-left corner of the rect
(changes to the x and y properties will have no effect on the target object)
topRight
:Point
get set
Gets or sets top-right corner of the rect
(changes to the x and y properties will have no effect on the target object)
bottomLeft
:Point
get set
Gets or sets bottom-left corner of the rect
(changes to the x and y properties will have no effect on the target object)
bottomRight
:Point
get set
Gets or sets bottom-right corner of the rect
(changes to the x and y properties will have no effect on the target object)
diagonal
:number
get
Gets a diagonal of the rect
points
:number[]
get
Gets array of points
[top-left.x, top-left.y, top-right.x, top-right.y, bottom-left.x, bottom-left.y, bottom-right.x, bottom-right.y]
Methods
move Self
(x: number, y: number, pivote?: TPivote) ⇨ Rect
(point: TPoint, pivote?: TPivote) ⇨ Rect
Sets a rect new position
shift Self
(dx: number, dy: number, pivote?: TPivote) ⇨ Rect
(dp: TPoint, pivote?: TPivote) ⇨ Rect
Shifts a rect
resize Self
(width: number, height: number) ⇨ Rect
(value: number) ⇨ Rect
(size: TSize) ⇨ Rect
Resizes a rect
scalesize Self
(dw: number, dh: number) ⇨ Rect
(value: number) ⇨ Rect
(dsize: TSize) ⇨ Rect
Scales a size of the rect
scale Self
(dx: number, dy: number) ⇨ Rect
(d: number) ⇨ Rect
Scales a rect
union Self
(rect: TRect) ⇨ Rect
Unions rectangles by min & max points
rotate
(deg: number, pivote?: TPivote) ⇨ PolyRect
(deg: number, pivote?: TPoint) ⇨ PolyRect
Returns a rotated non-AABB rectangle
overlaps
(rect: TRect) ⇨ boolean
Check overlaps
inside
(rect: TRect) ⇨ boolean
Check inside
contains
(rect: TRect) ⇨ boolean
Check contains
containsPoint
(point: TPoint) ⇨ boolean
Check a point inside the rect
equals
(rect: TRect) ⇨ boolean
Check equals
outline
(padding: number) ⇨ Rect
(top: number, left: number, bottom: number, right: number) ⇨ Rect
Create an outline
touchSide
(rect: TRect) ⇨ TSide[]
Return one or two touched sides
clone
()
Clones the current rectangle