Rect
Represents a rectangle.
Constructors
new Rect()
new Rect(
x
,y
,width
,height
):Rect
Parameters
Parameter | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns
Source
Properties
Property | Type |
---|---|
height | number |
width | number |
x | number |
y | number |
Accessors
bottom
get
bottom():number
Bottom border position of the rectangle along the y-axis.
Returns
number
Source
left
get
left():number
Left border position of the rectangle along the x-axis.
Returns
number
Source
maxX
get
maxX():number
Same as (x + width), or (right)
Returns
number
Source
maxY
get
maxY():number
Same as x + width
Returns
number
Source
midX
get
midX():number
The midpoint of the rectangle along the x-axis.
Returns
number
Source
midY
get
midY():number
The midpoint of the rectangle along the y-axis.
Returns
number
Source
minX
get
minX():number
Same as x
Returns
number
Source
minY
get
minY():number
Same as (y)
Returns
number
Source
right
get
right():number
Right border position of the rectangle along the x-axis.
Returns
number
Source
top
get
top():number
Top border position of the rectangle along the y-axis.
Returns
number
Source
Methods
above()
above(
height
):Rect
New rectangle above the original with a height of height.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
below()
below(
height
):Rect
New rectangle below the original with a height of height.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
contains()
contains(
x
,y
):boolean
Checks if this Rect contains the point (x; y) inside
Parameters
Parameter | Type |
---|---|
x | number |
y | number |
Returns
boolean
Source
containsPoint()
containsPoint(
p
):boolean
Checks if this Rect contains the specified point
Parameters
Parameter | Type |
---|---|
p | Point |
Returns
boolean
Source
cutBottom()
cutBottom(
dh
):Rect
New rectangle with the same top border as the original, but with the bottom border clipped by dh.
Parameters
Parameter | Type | Description |
---|---|---|
dh | number | {number} delta height |
Returns
Source
cutLeft()
cutLeft(
dw
):Rect
New rectangle with the same right border as the original, but with the left border clipped by dw.
Parameters
Parameter | Type | Description |
---|---|---|
dw | number | {number} delta width |
Returns
Source
cutRight()
cutRight(
dw
):Rect
New rectangle with the same left border as the original, but with the right border clipped by dw.
Parameters
Parameter | Type | Description |
---|---|---|
dw | number | {number} delta width |
Returns
Source
cutTop()
cutTop(
dh
):Rect
New rectangle with the same bottom border as the original, but with the top border clipped by dh.
Parameters
Parameter | Type | Description |
---|---|---|
dh | number | {number} delta height |
Returns
Source
fit()
fit(
width
,height
):Rect
The biggest rectangle that fits within this rect that keeps the width/height aspect ratio Positioned in the center. Useful for rendering images in cells.
Parameters
Parameter | Type |
---|---|
width | number |
height | number |
Returns
Source
fitSquare()
fitSquare():
Rect
Square fitted (inscribed) to the original rectangle
Returns
Source
fromCenterSize()
fromCenterSize(
cx
,cy
,width
,height
):Rect
Rectangle of the specified size, with the specified center
Parameters
Parameter | Type |
---|---|
cx | number |
cy | number |
width | number |
height | number |
Returns
Source
getBottom()
getBottom(
height
):Rect
Rectangle's bottom part of height height. New rectangle with the same bottom border as the original, but with a height of height. The result may be larger than the original rectangle along y-axis.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
getBottomLeft()
getBottomLeft(
width
,height
):Rect
New rectangle with the same bottom-left corner as the original, but with new width and height. The result may be larger than the original rectangle on both axes.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Source
getBottomRight()
getBottomRight(
width
,height
):Rect
New rectangle with the same bottom-right corner as the original, but with new width and height. The result may be larger than the original rectangle on both axes.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Source
getBottomScaled()
getBottomScaled(
ratio
):Rect
New rectangle with the same bottom border as the original, but with a height scaled with ratio of the original height. See also getBottom.
Parameters
Parameter | Type | Description |
---|---|---|
ratio | number | {number} height scale factor |
Returns
Source
getGridPart()
getGridPart(
xCount
,yCount
,x
,y
):Rect
Returns (x, y) part of the original rectangle divided into parts by a grid.
Parameters
Parameter | Type | Description |
---|---|---|
xCount | number | {number} dividing grid size along x-axis |
yCount | number | {number} dividing grid size along y-axis |
x | number | {number} index of part to return along x-axis |
y | number | {number} index of part to return along y-axis |
Returns
Source
getLeft()
getLeft(
width
):Rect
Rectangle's left part of width width. New rectangle with the same left border as the original, but with a width of width. The result may be larger than the original rectangle along x-axis.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Source
getLeftPart()
getLeftPart(
count
,index
):Rect
Vertical part of index of the original rectangle slices on count parts.
Parameters
Parameter | Type | Description |
---|---|---|
count | number | {number} count of parts to divide rectangle horizontally |
index | number | {number} index of part to return |
Returns
Source
getLeftScaled()
getLeftScaled(
ratio
):Rect
New rectangle with the same left border as the original, but with a width scaled with ratio of original width. See also getLeft.
Parameters
Parameter | Type | Description |
---|---|---|
ratio | number | {number} width scale factor |
Returns
Source
getRight()
getRight(
width
):Rect
Rectangle's right part of width width. New rectangle with the same right border as the original, but with a width of width. The result may be larger than the original rectangle along x-axis.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Source
getRightScaled()
getRightScaled(
ratio
):Rect
New rectangle with the same right border as the original, but with a width scaled with ratio of original width. See also getRight.
Parameters
Parameter | Type | Description |
---|---|---|
ratio | number | {number} width scale factor |
Returns
Source
getTop()
getTop(
height
):Rect
Rectangle's top part of height height. New rectangle with the same top border as the original, but with a height of height. The result may be larger than the original rectangle along y-axis.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
getTopLeft()
getTopLeft(
width
,height
):Rect
New rectangle with the same top-left corner as the original, but with new width and height. The result may be larger than the original rectangle on both axes.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Source
getTopPart()
getTopPart(
count
,index
):Rect
Horizontal part of index of the original rectangle sliced on count parts.
Parameters
Parameter | Type | Description |
---|---|---|
count | number | {number} count of parts to divide the rectangle vertically |
index | number | {number} index of part to return |
Returns
Source
getTopRight()
getTopRight(
width
,height
):Rect
New rectangle with the same top-right corner as the original, but with new width and height. The result may be larger than the original rectangle on both axes.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Source
getTopScaled()
getTopScaled(
ratio
):Rect
New rectangle with the same top border as the original, but with a height scaled with ratio of the original height. See also getTop.
Parameters
Parameter | Type | Description |
---|---|---|
ratio | number | {number} height scale factor |
Returns
Source
inflate()
inflate(
dx
,dy
):Rect
Inflated rectangle with left and right borders of the original shifted outside by dx and top and bottom borders shifted outside by dy. Overall size increased by 2dx along x-axis, and by 2dy along y-axis.
Parameters
Parameter | Type | Description |
---|---|---|
dx | number | {number} vertical borders shift delta along x-axis |
dy | number | {number} horizontal borders shift delta along y-axis |
Returns
Source
inflateRel()
inflateRel(
dxRatio
,dyRatio
):Rect
Inflated rectangle with new width scaled by dxRatio of the original and height scaled by dyRatio.
Parameters
Parameter | Type | Description |
---|---|---|
dxRatio | number | {number} width scale ratio |
dyRatio | number | {number} height scale ratio |
Returns
Source
inflateSize()
inflateSize(
dw
,dh
):Rect
Inflated rectangle with right border of the original shifted outside by dw and bottom border shifted outside by dh.
Parameters
Parameter | Type | Description |
---|---|---|
dw | number | {number} delta width |
dh | number | {number} delta height |
Returns
Source
move()
move(
dx
,dy
):Rect
Moves rectangle by the specified offsets.
Parameters
Parameter | Type |
---|---|
dx | number |
dy | number |
Returns
Source
toDart()
toDart():
any
Returns
any
Source
toTheBottom()
toTheBottom(
height
):Rect
New rectangle below the original with a height of height. See below.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
toTheLeft()
toTheLeft(
width
):Rect
New rectangle to the left of the original with a width of width.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Source
toTheRight()
toTheRight(
width
):Rect
New rectangle to the right of the original with a width of width.
Parameters
Parameter | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Source
toTheTop()
toTheTop(
height
):Rect
New rectangle above the original with a height of height. See above.
Parameters
Parameter | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Source
union()
union(
r
):Rect
Returns a rectangle that contains both this and r.
Parameters
Parameter | Type |
---|---|
r | Rect |
Returns
Source
fromDart()
static
fromDart(dart
):Rect
Parameters
Parameter | Type |
---|---|
dart | any |
Returns
Source
fromPoints()
static
fromPoints(x1
,y1
,x2
,y2
):Rect
Parameters
Parameter | Type |
---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
Returns
Source
fromXYArrays()
static
fromXYArrays(x
,y
):Rect
Parameters
Parameter | Type |
---|---|
x | number [] |
y | number [] |
Returns
Source
toDart()
static
toDart(rect
):any
Parameters
Parameter | Type |
---|---|
rect | Rect |
Returns
any