Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RegionSet<L>

A mutable set of labeled "regions", where each region is a contiguous set of square cells in a 2D grid with origin at (0,0) and extending to (gridSize,gridSize) (for some nonnegative integer gridSize, fixed when the set is created). Coordinates (x,y) are interpreted as points in the 2D plane in the conventional way.

A region must be contiguous: adjacent cells share an edge (not just a corner), and any cell in the region must be reachable from any other cell in the region by a path passing through adjacent cells.

Each region is labeled uniquely, and regions must be separated: no cell from one region can share an edge with a cell from another region.

Labels may be of arbitrary type L and are compared for equality using ===.

PS2 instructions: this is a required ADT interface. You may not change the specifications or add new methods.

Type parameters

  • L

    type of labels in this set, compared for equality using ===.

Hierarchy

  • RegionSet

Implemented by

Index

Properties

Methods

Properties

Readonly gridSize

gridSize: number
returns

the dimension of the grid, such that this set uses a gridSize x gridSize grid. Must be nonnegative.

Methods

add

  • add(label: L, rect: Rect): void
  • Add a rectangle of grid cells to the region labeled by the given label (or create such a labeled region if it was not already present), if it does not conflict with other existing labeled regions.

    Two regions with distinct labels conflict if any of their grid cells share an edge.

    throws

    Error if adding the rectangle would make label's region discontiguous or would cause a conflict with another labeled region

    Parameters

    • label: L

      label of region

    • rect: Rect

      rectangle to add to labeled region. Required to have nonzero area and integer coordinates drawn from {0...gridSize}.

    Returns void

bounds

  • bounds(label: L): undefined | Rect
  • Get the bounding box of a labeled region.

    Parameters

    • label: L

      label of region

    Returns undefined | Rect

    the smallest rectangle that contains all the grid cells in the labeled region, or undefined if no region with that label exists.

owners

  • owners(rect: Rect): Set<L>
  • Get the labels of regions that intersect the given rectangle (where the intersection contains at least one full grid cell).

    Parameters

    • rect: Rect

      rectangle to query. Its coordinates must be integers in {0...gridSize}.

    Returns Set<L>

    the labels of regions in this set whose intersection with rect contains at least one grid cell

Generated using TypeDoc