Skip to main content
Axis-aligned rectangle. right and bottom are exclusive (Playwright / DOM convention), so the box covers [left, right) × [top, bottom). Spatial predicates (isBelow, overlapsX, …) match the Rust methods and are what you compose in searchRelative.

Constructor

Construct a box from exclusive-edge coordinates. Throws if the box is degenerate (right <= left or bottom <= top).

Parameters

number
required
number
required
number
required

Returns

BoundingBox

Properties

number
required
number
required
Height (bottom - top). Always positive by construction.
number
required
number
required
number
required
Width (right - left). Always positive by construction.

Methods

area()

Area in pixels.

Returns

number

center()

Geometric center as [x, y] (integer-truncated, the pixel midpoint).

Returns

[number, number]

containsBox()

true if this box fully encloses other (equal boxes count).

Parameters

BoundingBox
required

Returns

boolean

containsPoint()

true if the point (x, y) lies inside this box. Exclusive right / bottom edges are outside.

Parameters

number
required
number
required

Returns

boolean

equals()

true if both boxes have the same exclusive-edge corners. === is still object identity — two separately constructed boxes with the same corners need this method.

Parameters

BoundingBox
required

Returns

boolean

fromXywh()

Construct from origin + size. Throws if width / height are not positive or if x + width / y + height overflow i32.

Parameters

number
required
number
required
number
required
number
required

Returns

BoundingBox

intersects()

true if the boxes’ interiors overlap. Exclusive edges that merely touch do not count.

Parameters

BoundingBox
required

Returns

boolean

isAbove()

true if this box sits entirely above other (no vertical overlap; exclusive edges that touch still count).

Parameters

BoundingBox
required

Returns

boolean

isBelow()

true if this box sits entirely below other. See [isAbove].

Parameters

BoundingBox
required

Returns

boolean

isContainedIn()

true if other fully encloses this box. Inverse of [containsBox].

Parameters

BoundingBox
required

Returns

boolean

isLeftOf()

true if this box sits entirely to the left of other. See [isAbove].

Parameters

BoundingBox
required

Returns

boolean

isRightOf()

true if this box sits entirely to the right of other. See [isAbove].

Parameters

BoundingBox
required

Returns

boolean

overlapArea()

Overlap area with other in pixels, 0 when the boxes do not intersect.

Parameters

BoundingBox
required

Returns

number

overlapsX()

true if the x-projections overlap (exclusive edges that touch do not). A narrow button over a wide field typically matches even when centers do not — compose with [isAbove] for “above in this column”.

Parameters

BoundingBox
required

Returns

boolean

overlapsY()

true if the y-projections overlap. See [overlapsX].

Parameters

BoundingBox
required

Returns

boolean

sameColumn()

true if the boxes share a column: centers within tolerance on x.

Parameters

BoundingBox
required
number
required

Returns

boolean

sameRow()

true if the boxes share a row: centers within tolerance on y. tolerance is in OS-native units (physical pixels on Windows/Linux, logical points on macOS).

Parameters

BoundingBox
required
number
required

Returns

boolean

shortestDistanceTo()

Shortest edge-to-edge distance to other, 0 when they touch or overlap. Rank matches with Math.min / Math.max on this value.

Parameters

BoundingBox
required

Returns

number

toString()

Playwright / DOM shape: {x: …, y: …, width: …, height: …}.

Returns

string