API reference
@searsuite/sear-foundation-rect
Immutable rectangle geometry and intersection utilities.
10 exportsderived from source
- classPositionRectsource ↗
-
class PositionRect<T>Represents a rectangle in absolute position space.
Unlike
Rect, which models a grid range, this class stores an origin and a size. It is typically used for layout calculations, collision checks, and hit-testing in rendered space.constructorconstructor PositionRect<T>(x: number, y: number, width: number, height: number): PositionRect<T>Creates a positioned rectangle from its origin and size.
x: numberHorizontal origin.
y: numberVertical origin.
width: numberRectangle width.
height: numberRectangle height.
propertyheight readonly height: numberThe rectangle height measured from
y.propertykey key: T | undefinedOptional external identifier associated with this rectangle.
propertywidth readonly width: numberThe rectangle width measured from
x.propertyx x: numberHorizontal origin of the rectangle.
propertyy y: numberVertical origin of the rectangle.
methodgetBounds getBounds(): [number, number, number, number]Returns rectangle bounds as
[left, right, top, bottom].methodgetPosition getPosition(): [number, number]Returns the rectangle origin as
[x, y].methodgetSize getSize(): [number, number]Returns the rectangle size as
[width, height].methodinRect inRect(x: number, y: number): booleanChecks whether a point lies inside the rectangle, including its edges.
x: numberHorizontal coordinate to test.
y: numberVertical coordinate to test.
methodtoJSON toJSON(): { height: number; key: T | undefined; width: number; x: number; y: number }Serializes the rectangle and its optional key to a plain object.
methodupdatePosition updatePosition(newX: number, newY: number): voidMoves the rectangle without changing its size.
newX: numberNew horizontal origin.
newY: numberNew vertical origin.
methodhasDominantAxisSpanstatic hasDominantAxisSpan<U>(positionRect1: PositionRect<U>, positionRect2: PositionRect<U>): booleanChecks whether the first rectangle extends further than the second on at least one major axis.
This helper is useful when choosing a dominant rectangle during merge or overlap resolution logic.
positionRect1: PositionRect<U>The first rectangle.
positionRect2: PositionRect<U>The second rectangle.
methodintersectionstatic intersection<U>(positionRect1: PositionRect<U>, positionRect2: PositionRect<U>): booleanReturns
truewhen the two rectangles overlap with a non-zero area.Edge-touching rectangles are treated as non-intersecting.
positionRect1: PositionRect<U>The first rectangle.
positionRect2: PositionRect<U>The second rectangle.
methodmergestatic merge<U>(rect1: PositionRect<U>, rect2: PositionRect<U>): PositionRect<U>Creates the smallest rectangle that covers both inputs.
rect1: PositionRect<U>The first rectangle.
rect2: PositionRect<U>The second rectangle.
- classPositionRectManagersource ↗
-
class PositionRectManager<PositionRectKeyType>Maintains a collection of positioned rectangles that are updated together.
This manager is intentionally lightweight. It acts as a shared holder for rectangles that should move in lockstep, such as overlay fragments that track the same origin.
constructorconstructor PositionRectManager<PositionRectKeyType>(): PositionRectManager<PositionRectKeyType>Creates a PositionRectManager instance.
memberlength length: unknownmethodaddPositionRect addPositionRect(positionRect: PositionRect<PositionRectKeyType>): voidRegisters a rectangle with the manager.
positionRect: PositionRect<PositionRectKeyType>Rectangle instance to track.
methodupdatePosition updatePosition(newX: number, newY: number): voidMoves every managed rectangle to the same new origin.
newX: numberNew horizontal origin.
newY: numberNew vertical origin.
- classRangeRectsource ↗
-
class RangeRect<T>Associates a value with a rectangular range in grid coordinates.
The range is defined as
[startRow, endRow, startCol, endCol], using inclusive bounds on both axes.constructorconstructor RangeRect<T>(rect: [number, number, number, number], value: T): RangeRect<T>Creates a range/value pair.
rect: [number, number, number, number]Rectangle coordinates as
[startRow, endRow, startCol, endCol].value: TValue associated with every cell inside the rectangle.
propertyrect rect: [number, number, number, number]Inclusive rectangle bounds encoded as
[startRow, endRow, startCol, endCol].propertyvalue value: TValue returned for every cell covered by the range.
membershape shape: unknownmethodaddCol addCol(colIndex: number): thisExtends the range to the right when a column is inserted inside it.
colIndex: numberInserted column index.
methodaddRow addRow(rowIndex: number): thisExtends the range downward when a row is inserted inside the current span.
rowIndex: numberInserted row index.
methodclone clone(): RangeRect<T>Creates an independent copy of this value and its mutable data.
methodforEach forEach(callbackfn: (rowIndex: number, colIndex: number, value: T): void): voidIterates through every covered cell and yields the stored value.
callbackfn: (rowIndex: number, colIndex: number, value: T): voidCalled once for each covered cell.
methodgetValue getValue(rowIndex: number, colIndex: number): T | nullReturns the stored value when the requested cell lies inside the range.
rowIndex: numberRow index to query.
colIndex: numberColumn index to query.
methodremoveCol removeCol(colIndex: number): thisContracts the range when a column is removed from inside it.
colIndex: numberRemoved column index.
methodremoveRow removeRow(rowIndex: number): thisContracts the range when a row is removed from inside the current span.
rowIndex: numberRemoved row index.
methodtoJSON toJSON(): { rect: [number, number, number, number]; value: T }Serializes the range and its associated value.
- classRangeRectManagersource ↗
-
class RangeRectManager<T>Stores multiple
RangeRectinstances and resolves a merged value for a cell.The manager assumes each range contributes part of an object-like value. When a cell belongs to multiple ranges, the returned result is a shallow merge of all matching values in insertion order.
constructorconstructor RangeRectManager<T>(): RangeRectManager<T>memberlength length: unknownmethodaddRange addRange(range: RangeRect<T>): voidAdds a range to the manager.
range: RangeRect<T>Range definition to register.
methodgetValue getValue(row: number, col: number): T | nullResolves the value for a cell by shallow-merging all matching ranges.
When no range covers the target cell,
nullis returned.row: numberRow index to query.
col: numberColumn index to query.
methodtoJSON toJSON(): { rect: [number, number, number, number]; value: T }[]Serializes all ranges in insertion order.
A dedicated exported JSON type could be extracted later if multiple packages start depending on this exact payload shape.
- classRectsource ↗
-
class RectDescribes a rectangle in sheet coordinates.
The rectangle is stored as two corner points: the top-left point followed by the bottom-right point. The class provides helpers for iteration, structural updates after row or column mutations, and serialization.
constructorconstructor Rect(rect?: [Point, Point]): RectCreates a rectangle from two corner points.
rect: [Point, Point]The rectangle bounds as
[[startRow, startCol], [endRow, endCol]].
membershape shape: unknownmemberEmptystatic Empty: unknownmethodaddCol addCol(colIndex: number): thisExpands or shifts the rectangle after a column insertion.
colIndex: numberThe inserted column index.
methodaddRow addRow(rowIndex: number): thisExpands or shifts the rectangle after a row insertion.
If the insertion happens before the rectangle, both bounds move down. If it happens inside the rectangle, only the ending bound expands.
rowIndex: numberThe inserted row index.
methodclone clone(): RectCreates an independent copy of this value and its mutable data.
methodforEach forEach(callbackfn: (rowIndex: number, colIndex: number): void): voidIterates through every cell coordinate covered by the rectangle.
callbackfn: (rowIndex: number, colIndex: number): voidCalled once for each
(rowIndex, colIndex)pair.
methodgetPoint getPoint(index: 0 | 1): PointReturns one of the stored corner points.
index: 0 | 10for the start point,1for the end point.
methodlockMutations lockMutations(): voidPrevents changes through methods or coordinates retained from a committed state.
methodremoveCol removeCol(colIndex: number): thisShrinks or shifts the rectangle after a column removal.
colIndex: numberThe removed column index.
methodremoveRow removeRow(rowIndex: number): thisShrinks or shifts the rectangle after a row removal.
If the removed row is before the rectangle, both bounds move up. If it is inside the rectangle, only the ending bound contracts.
rowIndex: numberThe removed row index.
methodtoJSON toJSON(): { rect: [Point, Point] }Serializes the rectangle to a plain object.
methodupdate update(rect: [Point, Point]): RectReplaces the rectangle with a new set of bounds.
rect: [Point, Point]The new rectangle coordinates.
methodcontainsstatic contains(rectA: Rect, rectB: Rect): booleanChecks whether
rectAfully containsrectB.rectA: RectThe outer candidate rectangle.
rectB: RectThe inner candidate rectangle.
methodfindBoundingRectanglestatic findBoundingRectangle(rects: Rect[]): RectComputes the smallest rectangle that encloses all provided rectangles.
rects: Rect[]The rectangles to merge into a bounding box.
- interfacePositionRectPropssource ↗
-
interface PositionRectPropsPlain-object shape of a rectangle in pixel or layout coordinates.
- typePointsource ↗
-
type Point = [number, number]A tuple representing a two-dimensional point in grid coordinates.
The first item is the row index and the second item is the column index.
- variableemptyPositionRectsource ↗
-
emptyPositionRect: PositionRectPropsZero-sized rectangle used as the default empty layout region.
- functioncreateEmptyRectsource ↗
-
createEmptyRect(): RectPublic API for grid and positioned rectangle helpers.
This module re-exports the core geometry primitives used by other searTable packages to describe rectangular selections, layout bounds, and range-based value lookup.
- functioncreateEmptyRectShapesource ↗
-
createEmptyRectShape(): [Point, Point]Public API for grid and positioned rectangle helpers.
This module re-exports the core geometry primitives used by other searTable packages to describe rectangular selections, layout bounds, and range-based value lookup.
No public exports match that search.