Skip to main content

Class: Rect

Defined in: packages/blockly/core/utils/rect.ts:21

Class for representing rectangular regions.

Properties index

PropertyDescription
topTop.
bottomBottom.
leftLeft.
rightRight.

Methods index

MethodDescription
fromConverts a DOM or SVG Rect to a Blockly Rect.
cloneCreates a new copy of this rectangle.
getHeightReturns the height of this rectangle.
getWidthReturns the width of this rectangle.
getOriginReturns the top left coordinate of this rectangle.
containsTests whether this rectangle contains a x/y coordinate.
intersectsTests whether this rectangle intersects the provided rectangle. Assumes that the coordinate system increases going down and left.
equalsCompares bounding rectangles for equality.
createFromPointCreates a new Rect using a position and supplied dimensions.

Constructors

Constructor

new Rect(
top,
bottom,
left,
right
): Rect;

Defined in: packages/blockly/core/utils/rect.ts:28

Parameters

ParameterTypeDescription
topnumberTop.
bottomnumberBottom.
leftnumberLeft.
rightnumberRight.

Returns

Rect

Properties

top

top: number;

Defined in: packages/blockly/core/utils/rect.ts:29

Top.


bottom

bottom: number;

Defined in: packages/blockly/core/utils/rect.ts:30

Bottom.


left

left: number;

Defined in: packages/blockly/core/utils/rect.ts:31

Left.


right: number;

Defined in: packages/blockly/core/utils/rect.ts:32

Right.

Methods

from()

static from(rect): Rect;

Defined in: packages/blockly/core/utils/rect.ts:41

Converts a DOM or SVG Rect to a Blockly Rect.

Parameters

ParameterTypeDescription
rectDOMRectThe rectangle to convert.

Returns

Rect

A representation of the same rectangle as a Blockly Rect.


clone()

clone(): Rect;

Defined in: packages/blockly/core/utils/rect.ts:50

Creates a new copy of this rectangle.

Returns

Rect

A copy of this Rect.


getHeight()

getHeight(): number;

Defined in: packages/blockly/core/utils/rect.ts:55

Returns the height of this rectangle.

Returns

number


getWidth()

getWidth(): number;

Defined in: packages/blockly/core/utils/rect.ts:60

Returns the width of this rectangle.

Returns

number


getOrigin()

getOrigin(): Coordinate;

Defined in: packages/blockly/core/utils/rect.ts:65

Returns the top left coordinate of this rectangle.

Returns

Coordinate


contains()

contains(x, y): boolean;

Defined in: packages/blockly/core/utils/rect.ts:76

Tests whether this rectangle contains a x/y coordinate.

Parameters

ParameterTypeDescription
xnumberThe x coordinate to test for containment.
ynumberThe y coordinate to test for containment.

Returns

boolean

Whether this rectangle contains given coordinate.


intersects()

intersects(other): boolean;

Defined in: packages/blockly/core/utils/rect.ts:89

Tests whether this rectangle intersects the provided rectangle. Assumes that the coordinate system increases going down and left.

Parameters

ParameterTypeDescription
otherRectThe other rectangle to check for intersection with.

Returns

boolean

Whether this rectangle intersects the provided rectangle.


equals()

static equals(a?, b?): boolean;

Defined in: packages/blockly/core/utils/rect.ts:110

Compares bounding rectangles for equality.

Parameters

ParameterTypeDescription
a?Rect | nullA Rect.
b?Rect | nullA Rect.

Returns

boolean

True iff the bounding rectangles are equal, or if both are null.


createFromPoint()

static createFromPoint(
position,
width,
height
): Rect;

Defined in: packages/blockly/core/utils/rect.ts:133

Creates a new Rect using a position and supplied dimensions.

Parameters

ParameterTypeDescription
positionCoordinateThe upper left coordinate of the new rectangle.
widthnumberThe width of the rectangle, in pixels.
heightnumberThe height of the rectangle, in pixels.

Returns

Rect

A newly created Rect using the provided Coordinate and dimensions.