Skip to main content

Class: Rect

dg.Rect

Represents a rectangle.

Constructors

constructor

new Rect(x, y, width, height)

Parameters

NameType
xnumber
ynumber
widthnumber
heightnumber

Defined in

src/grid.ts:71

Properties

height

height: number

Defined in

src/grid.ts:69


width

width: number

Defined in

src/grid.ts:68


x

x: number

Defined in

src/grid.ts:66


y

y: number

Defined in

src/grid.ts:67

Accessors

bottom

get bottom(): number

Bottom border position of the rectangle along the y-axis.

Returns

number

Defined in

src/grid.ts:164


left

get left(): number

Left border position of the rectangle along the x-axis.

Returns

number

Defined in

src/grid.ts:149


maxX

get maxX(): number

Same as (x + width), or (right)

Returns

number

Defined in

src/grid.ts:140


maxY

get maxY(): number

Same as x + width

Returns

number

Defined in

src/grid.ts:146


midX

get midX(): number

The midpoint of the rectangle along the x-axis.

Returns

number

Defined in

src/grid.ts:127


midY

get midY(): number

The midpoint of the rectangle along the y-axis.

Returns

number

Defined in

src/grid.ts:132


minX

get minX(): number

Same as x

Returns

number

Defined in

src/grid.ts:137


minY

get minY(): number

Same as (y)

Returns

number

Defined in

src/grid.ts:143


get right(): number

Right border position of the rectangle along the x-axis.

Returns

number

Defined in

src/grid.ts:159


top

get top(): number

Top border position of the rectangle along the y-axis.

Returns

number

Defined in

src/grid.ts:154

Methods

above

above(height): Rect

New rectangle above the original with a height of height.

Parameters

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:303


below

below(height): Rect

New rectangle below the original with a height of height.

Parameters

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:296


contains

contains(x, y): boolean

Checks if this Rect contains the point (x; y) inside

Parameters

NameType
xnumber
ynumber

Returns

boolean

Defined in

src/grid.ts:464


containsPoint

containsPoint(p): boolean

Checks if this Rect contains the specified point

Parameters

NameType
pPoint

Returns

boolean

Defined in

src/grid.ts:469


cutBottom

cutBottom(dh): Rect

New rectangle with the same top border as the original, but with the bottom border clipped by dh.

Parameters

NameTypeDescription
dhnumber{number} delta height

Returns

Rect

Defined in

src/grid.ts:279


cutLeft

cutLeft(dw): Rect

New rectangle with the same right border as the original, but with the left border clipped by dw.

Parameters

NameTypeDescription
dwnumber{number} delta width

Returns

Rect

Defined in

src/grid.ts:263


cutRight

cutRight(dw): Rect

New rectangle with the same left border as the original, but with the right border clipped by dw.

Parameters

NameTypeDescription
dwnumber{number} delta width

Returns

Rect

Defined in

src/grid.ts:287


cutTop

cutTop(dh): Rect

New rectangle with the same bottom border as the original, but with the top border clipped by dh.

Parameters

NameTypeDescription
dhnumber{number} delta height

Returns

Rect

Defined in

src/grid.ts:271


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

NameType
widthnumber
heightnumber

Returns

Rect

Defined in

src/grid.ts:457


fitSquare

fitSquare(): Rect

Square fitted (inscribed) to the original rectangle

Returns

Rect

Defined in

src/grid.ts:449


fromCenterSize

fromCenterSize(cx, cy, width, height): Rect

Rectangle of the specified size, with the specified center

Parameters

NameType
cxnumber
cynumber
widthnumber
heightnumber

Returns

Rect

Defined in

src/grid.ts:122


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

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:191


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

NameTypeDescription
widthnumber{number} new rectangle width
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:242


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

NameTypeDescription
widthnumber{number} new rectangle width
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:253


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

NameTypeDescription
rationumber{number} height scale factor

Returns

Rect

Defined in

src/grid.ts:354


getGridPart

getGridPart(xCount, yCount, x, y): Rect

Returns (x, y) part of the original rectangle divided into parts by a grid.

Parameters

NameTypeDescription
xCountnumber{number} dividing grid size along x-axis
yCountnumber{number} dividing grid size along y-axis
xnumber{number} index of part to return along x-axis
ynumber{number} index of part to return along y-axis

Returns

Rect

Defined in

src/grid.ts:407


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

NameTypeDescription
widthnumber{number} new rectangle width

Returns

Rect

Defined in

src/grid.ts:201


getLeftPart

getLeftPart(count, index): Rect

Vertical part of index of the original rectangle slices on count parts.

Parameters

NameTypeDescription
countnumber{number} count of parts to divide rectangle horizontally
indexnumber{number} index of part to return

Returns

Rect

Defined in

src/grid.ts:394


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

NameTypeDescription
rationumber{number} width scale factor

Returns

Rect

Defined in

src/grid.ts:363


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

NameTypeDescription
widthnumber{number} new rectangle width

Returns

Rect

Defined in

src/grid.ts:211


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

NameTypeDescription
rationumber{number} width scale factor

Returns

Rect

Defined in

src/grid.ts:372


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

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:181


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

NameTypeDescription
widthnumber{number} new rectangle width
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:221


getTopPart

getTopPart(count, index): Rect

Horizontal part of index of the original rectangle sliced on count parts.

Parameters

NameTypeDescription
countnumber{number} count of parts to divide the rectangle vertically
indexnumber{number} index of part to return

Returns

Rect

Defined in

src/grid.ts:383


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

NameTypeDescription
widthnumber{number} new rectangle width
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:231


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

NameTypeDescription
rationumber{number} height scale factor

Returns

Rect

Defined in

src/grid.ts:345


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

NameTypeDescription
dxnumber{number} vertical borders shift delta along x-axis
dynumber{number} horizontal borders shift delta along y-axis

Returns

Rect

Defined in

src/grid.ts:422


inflateRel

inflateRel(dxRatio, dyRatio): Rect

Inflated rectangle with new width scaled by dxRatio of the original and height scaled by dyRatio.

Parameters

NameTypeDescription
dxRationumber{number} width scale ratio
dyRationumber{number} height scale ratio

Returns

Rect

Defined in

src/grid.ts:444


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

NameTypeDescription
dwnumber{number} delta width
dhnumber{number} delta height

Returns

Rect

Defined in

src/grid.ts:434


move

move(dx, dy): Rect

Moves rectangle by the specified offsets.

Parameters

NameType
dxnumber
dynumber

Returns

Rect

Defined in

src/grid.ts:171


toDart

toDart(): any

Returns

any

Defined in

src/grid.ts:113


toTheBottom

toTheBottom(height): Rect

New rectangle below the original with a height of height. See below.

Parameters

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:334


toTheLeft

toTheLeft(width): Rect

New rectangle to the left of the original with a width of width.

Parameters

NameTypeDescription
widthnumber{number} new rectangle width

Returns

Rect

Defined in

src/grid.ts:310


toTheRight

toTheRight(width): Rect

New rectangle to the right of the original with a width of width.

Parameters

NameTypeDescription
widthnumber{number} new rectangle width

Returns

Rect

Defined in

src/grid.ts:318


toTheTop

toTheTop(height): Rect

New rectangle above the original with a height of height. See above.

Parameters

NameTypeDescription
heightnumber{number} new rectangle height

Returns

Rect

Defined in

src/grid.ts:326


union

union(r): Rect

Returns a rectangle that contains both this and r.

Parameters

NameType
rRect

Returns

Rect

Defined in

src/grid.ts:474


fromDart

Static fromDart(dart): Rect

Parameters

NameType
dartany

Returns

Rect

Defined in

src/grid.ts:100


fromPoints

Static fromPoints(x1, y1, x2, y2): Rect

Parameters

NameType
x1number
y1number
x2number
y2number

Returns

Rect

Defined in

src/grid.ts:78


fromXYArrays

Static fromXYArrays(x, y): Rect

Parameters

NameType
xnumber[]
ynumber[]

Returns

Rect

Defined in

src/grid.ts:84


toDart

Static toDart(rect): any

Parameters

NameType
rectRect

Returns

any

Defined in

src/grid.ts:105