Class: Rect
dg.Rect
Represents a rectangle.
Constructors
constructor
• new Rect(x
, y
, width
, height
)
Parameters
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Defined in
Properties
height
• height: number
Defined in
width
• width: number
Defined in
x
• x: number
Defined in
y
• y: number
Defined in
Accessors
bottom
• get
bottom(): number
Bottom border position of the rectangle along the y-axis.
Returns
number
Defined in
left
• get
left(): number
Left border position of the rectangle along the x-axis.
Returns
number
Defined in
maxX
• get
maxX(): number
Same as (x + width), or (right)
Returns
number
Defined in
maxY
• get
maxY(): number
Same as x + width
Returns
number
Defined in
midX
• get
midX(): number
The midpoint of the rectangle along the x-axis.
Returns
number
Defined in
midY
• get
midY(): number
The midpoint of the rectangle along the y-axis.
Returns
number
Defined in
minX
• get
minX(): number
Same as x
Returns
number
Defined in
minY
• get
minY(): number
Same as (y)
Returns
number
Defined in
right
• get
right(): number
Right border position of the rectangle along the x-axis.
Returns
number
Defined in
top
• get
top(): number
Top border position of the rectangle along the y-axis.
Returns
number
Defined in
Methods
above
▸ above(height
): Rect
New rectangle above the original with a height of height.
Parameters
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
below
▸ below(height
): Rect
New rectangle below the original with a height of height.
Parameters
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
contains
▸ contains(x
, y
): boolean
Checks if this Rect contains the point (x; y) inside
Parameters
Name | Type |
---|---|
x | number |
y | number |
Returns
boolean
Defined in
containsPoint
▸ containsPoint(p
): boolean
Checks if this Rect contains the specified point
Parameters
Name | Type |
---|---|
p | Point |
Returns
boolean
Defined in
cutBottom
▸ cutBottom(dh
): Rect
New rectangle with the same top border as the original, but with the bottom border clipped by dh.
Parameters
Name | Type | Description |
---|---|---|
dh | number | {number} delta height |
Returns
Defined in
cutLeft
▸ cutLeft(dw
): Rect
New rectangle with the same right border as the original, but with the left border clipped by dw.
Parameters
Name | Type | Description |
---|---|---|
dw | number | {number} delta width |
Returns
Defined in
cutRight
▸ cutRight(dw
): Rect
New rectangle with the same left border as the original, but with the right border clipped by dw.
Parameters
Name | Type | Description |
---|---|---|
dw | number | {number} delta width |
Returns
Defined in
cutTop
▸ cutTop(dh
): Rect
New rectangle with the same bottom border as the original, but with the top border clipped by dh.
Parameters
Name | Type | Description |
---|---|---|
dh | number | {number} delta height |
Returns
Defined in
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
Name | Type |
---|---|
width | number |
height | number |
Returns
Defined in
fitSquare
▸ fitSquare(): Rect
Square fitted (inscribed) to the original rectangle
Returns
Defined in
fromCenterSize
▸ fromCenterSize(cx
, cy
, width
, height
): Rect
Rectangle of the specified size, with the specified center
Parameters
Name | Type |
---|---|
cx | number |
cy | number |
width | number |
height | number |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
ratio | number | {number} height scale factor |
Returns
Defined in
getGridPart
▸ getGridPart(xCount
, yCount
, x
, y
): Rect
Returns (x, y) part of the original rectangle divided into parts by a grid.
Parameters
Name | 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
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Defined in
getLeftPart
▸ getLeftPart(count
, index
): Rect
Vertical part of index of the original rectangle slices on count parts.
Parameters
Name | Type | Description |
---|---|---|
count | number | {number} count of parts to divide rectangle horizontally |
index | number | {number} index of part to return |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
ratio | number | {number} width scale factor |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
ratio | number | {number} width scale factor |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Defined in
getTopPart
▸ getTopPart(count
, index
): Rect
Horizontal part of index of the original rectangle sliced on count parts.
Parameters
Name | Type | Description |
---|---|---|
count | number | {number} count of parts to divide the rectangle vertically |
index | number | {number} index of part to return |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
height | number | {number} new rectangle height |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
ratio | number | {number} height scale factor |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
dx | number | {number} vertical borders shift delta along x-axis |
dy | number | {number} horizontal borders shift delta along y-axis |
Returns
Defined in
inflateRel
▸ inflateRel(dxRatio
, dyRatio
): Rect
Inflated rectangle with new width scaled by dxRatio of the original and height scaled by dyRatio.
Parameters
Name | Type | Description |
---|---|---|
dxRatio | number | {number} width scale ratio |
dyRatio | number | {number} height scale ratio |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
dw | number | {number} delta width |
dh | number | {number} delta height |
Returns
Defined in
move
▸ move(dx
, dy
): Rect
Moves rectangle by the specified offsets.
Parameters
Name | Type |
---|---|
dx | number |
dy | number |
Returns
Defined in
toDart
▸ toDart(): any
Returns
any
Defined in
toTheBottom
▸ toTheBottom(height
): Rect
New rectangle below the original with a height of height. See below.
Parameters
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
toTheLeft
▸ toTheLeft(width
): Rect
New rectangle to the left of the original with a width of width.
Parameters
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Defined in
toTheRight
▸ toTheRight(width
): Rect
New rectangle to the right of the original with a width of width.
Parameters
Name | Type | Description |
---|---|---|
width | number | {number} new rectangle width |
Returns
Defined in
toTheTop
▸ toTheTop(height
): Rect
New rectangle above the original with a height of height. See above.
Parameters
Name | Type | Description |
---|---|---|
height | number | {number} new rectangle height |
Returns
Defined in
union
▸ union(r
): Rect
Returns a rectangle that contains both this and r.
Parameters
Name | Type |
---|---|
r | Rect |
Returns
Defined in
fromDart
▸ Static
fromDart(dart
): Rect
Parameters
Name | Type |
---|---|
dart | any |
Returns
Defined in
fromPoints
▸ Static
fromPoints(x1
, y1
, x2
, y2
): Rect
Parameters
Name | Type |
---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
Returns
Defined in
fromXYArrays
▸ Static
fromXYArrays(x
, y
): Rect
Parameters
Name | Type |
---|---|
x | number [] |
y | number [] |
Returns
Defined in
toDart
▸ Static
toDart(rect
): any
Parameters
Name | Type |
---|---|
rect | Rect |
Returns
any