Options
All
  • Public
  • Public/Protected
  • All
Menu

Class City<L>

A mutable set of labeled "buildings" in 3D, where a building is a contiguous set of cubic cells in a 3D grid with origin at (0,0,0) and extending to (gridSize,gridSize,gridSize) (for some nonnegative integer gridSize, fixed when the set is created). Coordinates (x,y,z) are interpreted as points in 3D space in the conventional way.

Buildings must rest on the ground (the z=0 plane), and a building must be contiguous: adjacent cells share a face (not just an edge or corner), and any cell in the building must be reachable from any other cell in the building by a path passing through adjacent cells.

Buildings have floors numbered from 0 (the ground floor, resting on the ground plane) upwards to at most gridSize-1. Each individual floor of a building must be contiguous.

Each building is labeled uniquely, and buildings must be separated: no cell from one building can share a face with a cell from a different building.

Labels are of arbitrary type L and are compared for equality using ===. They may not be null or undefined.

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

  • City

Index

Constructors

Properties

Methods

Constructors

  • new City<L>(gridSize: number): City<L>
  • Create an empty city with a gridSize x gridSize x gridSize grid.

    Type parameters

    • L

    Parameters

    • gridSize: number

      dimension of city grid, must be nonnegative integer

    Returns City<L>

Properties

gridSize: number

Methods

  • bounds(label: L): undefined | { footprint: Rect; height: number }
  • Get the footprint and height of a labeled building.

    Parameters

    • label: L

      label of building

    Returns undefined | { footprint: Rect; height: number }

    building's footprint (smallest rectangle that contains the projection of the building onto the ground plane) and height (number of floors in the building), or undefined if no building with that label exists in this set.

  • expand(label: L, floor: number, rect: Rect): void
  • Add a rectangle of grid cells to a particular floor of the building labeled by the given label (creating a building or adding a floor if necessary), if the expanded building rests on the ground plane, is still contiguous, and the expansion does not conflict with other existing buildings.

    Two buildings conflict if a cubic cell of one building shares a face with a cubic cell belonging to the other building.

    throws

    Error if adding the expansion would make the building ungrounded, the building or floor discontiguous, or cause a conflict with another building.

    Parameters

    • label: L

      label of building

    • floor: number

      floor of building to expand. Must be an integer in {0...gridSize-1}.

    • rect: Rect

      rectangle to add to specified floor of the labeled building. Required to have nonzero area and integer coordinates drawn from {0...gridSize}.

    Returns void

  • owners(rect: Rect): Set<L>
  • Get the labels of buildings whose projections onto the ground plane intersect the given rectangle (where the intersection must contain 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 buildings in this set whose projections onto the ground plane intersect with rect in at least one grid cell

Generated using TypeDoc