@searsuite/sear-foundation-rect
Immutable rectangle geometry and intersection utilities.
Rectangle values
- classPositionRect
-
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.constructor PositionRect<T>(x: number, y: number, width: number, height: number): PositionRect<T>Creates a positioned rectangle from its origin and size.
xHorizontal origin.
yVertical origin.
widthRectangle width.
heightRectangle height.
property readonly height: numberThe rectangle height measured from
y.property key: T | undefinedOptional external identifier associated with this rectangle.
property readonly width: numberThe rectangle width measured from
x.property x: numberHorizontal origin of the rectangle.
property y: numberVertical origin of the rectangle.
method getBounds(): [number, number, number, number]Returns rectangle bounds as
[left, right, top, bottom].method getPosition(): [number, number]Returns the rectangle origin as
[x, y].method getSize(): [number, number]Returns the rectangle size as
[width, height].method inRect(x: number, y: number): booleanChecks whether a point lies inside the rectangle, including its edges.
xHorizontal coordinate to test.
yVertical coordinate to test.
method toJSON(): { height: number; key: T | undefined; width: number; x: number; y: number }Serializes the rectangle and its optional key to a plain object.
method updatePosition(newX: number, newY: number): voidMoves the rectangle without changing its size.
newXNew horizontal origin.
newYNew vertical origin.
method hasDominantAxisSpan<U>(positionRect1: PositionRect<U>, positionRect2: PositionRect<U>): booleanstaticChecks 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.
positionRect1The first rectangle.
positionRect2The second rectangle.
method intersection<U>(positionRect1: PositionRect<U>, positionRect2: PositionRect<U>): booleanstaticReturns
truewhen the two rectangles overlap with a non-zero area.Edge-touching rectangles are treated as non-intersecting.
positionRect1The first rectangle.
positionRect2The second rectangle.
method merge<U>(rect1: PositionRect<U>, rect2: PositionRect<U>): PositionRect<U>staticCreates the smallest rectangle that covers both inputs.
rect1The first rectangle.
rect2The second rectangle.
- classRangeRect
-
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.constructor RangeRect<T>(rect: [number, number, number, number], value: T): RangeRect<T>Creates a range/value pair.
rectRectangle coordinates as
[startRow, endRow, startCol, endCol].valueValue associated with every cell inside the rectangle.
property rect: [number, number, number, number]Inclusive rectangle bounds encoded as
[startRow, endRow, startCol, endCol].property value: TValue returned for every cell covered by the range.
membershape shape: unknownmethod addCol(colIndex: number): thisExtends the range to the right when a column is inserted inside it.
colIndexInserted column index.
method addRow(rowIndex: number): thisExtends the range downward when a row is inserted inside the current span.
rowIndexInserted row index.
method clone(): RangeRect<T>Creates an independent copy of this value and its mutable data.
method forEach(callbackfn: (rowIndex: number, colIndex: number, value: T): void): voidIterates through every covered cell and yields the stored value.
callbackfnCalled once for each covered cell.
method getValue(rowIndex: number, colIndex: number): T | nullReturns the stored value when the requested cell lies inside the range.
rowIndexRow index to query.
colIndexColumn index to query.
method removeCol(colIndex: number): thisContracts the range when a column is removed from inside it.
colIndexRemoved column index.
method removeRow(rowIndex: number): thisContracts the range when a row is removed from inside the current span.
rowIndexRemoved row index.
method toJSON(): { rect: [number, number, number, number]; value: T }Serializes the range and its associated value.
- classRect
-
Describes 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.
constructor Rect(rect?: [Point, Point]): RectCreates a rectangle from two corner points.
rectThe rectangle bounds as
[[startRow, startCol], [endRow, endCol]].
membershape shape: unknownmemberEmptystatic Empty: unknownmethod addCol(colIndex: number): thisExpands or shifts the rectangle after a column insertion.
colIndexThe inserted column index.
method 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.
rowIndexThe inserted row index.
method clone(): RectCreates an independent copy of this value and its mutable data.
method forEach(callbackfn: (rowIndex: number, colIndex: number): void): voidIterates through every cell coordinate covered by the rectangle.
callbackfnCalled once for each
(rowIndex, colIndex)pair.
method getPoint(index: 0 | 1): PointReturns one of the stored corner points.
index0for the start point,1for the end point.
method lockMutations(): voidPrevents changes through methods or coordinates retained from a committed state.
method removeCol(colIndex: number): thisShrinks or shifts the rectangle after a column removal.
colIndexThe removed column index.
method 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.
rowIndexThe removed row index.
method toJSON(): { rect: [Point, Point] }Serializes the rectangle to a plain object.
method update(rect: [Point, Point]): RectReplaces the rectangle with a new set of bounds.
rectThe new rectangle coordinates.
method contains(rectA: Rect, rectB: Rect): booleanstaticChecks whether
rectAfully containsrectB.rectAThe outer candidate rectangle.
rectBThe inner candidate rectangle.
method findBoundingRectangle(rects: Rect[]): RectstaticComputes the smallest rectangle that encloses all provided rectangles.
rectsThe rectangles to merge into a bounding box.
- interfacePositionRectProps
-
Plain-object shape of a rectangle in pixel or layout coordinates.
- typePoint
-
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.
- variableemptyPositionRect
-
emptyPositionRect: PositionRectPropsZero-sized rectangle used as the default empty layout region.
- functioncreateEmptyRect
-
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.
- functioncreateEmptyRectShape
-
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.
Rectangle managers
- classPositionRectManager
-
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.
constructor PositionRectManager<PositionRectKeyType>(): PositionRectManager<PositionRectKeyType>memberlength length: unknownmethod addPositionRect(positionRect: PositionRect<PositionRectKeyType>): voidRegisters a rectangle with the manager.
positionRectRectangle instance to track.
method updatePosition(newX: number, newY: number): voidMoves every managed rectangle to the same new origin.
newXNew horizontal origin.
newYNew vertical origin.
- classRangeRectManager
-
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.
constructor RangeRectManager<T>(): RangeRectManager<T>memberlength length: unknownmethod addRange(range: RangeRect<T>): voidAdds a range to the manager.
rangeRange definition to register.
method 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.rowRow index to query.
colColumn index to query.
method 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.
No matching API entries.