FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
environment::field::aggregation::TiledGrid Class Reference

#include <TiledGrid.h>

Classes

struct  Item
 One box with its id (slot), for With(). More...
 

Public Member Functions

 TiledGrid ()=default
 An empty grid with no extent; With() must not be called on it.
 
 TiledGrid (double xMin, double xMax, double yMin, double yMax, double cellSize)
 
bool HasExtent () const
 True when the grid has an extent (was made with the extent constructor).
 
double CellSize () const
 The cell edge in use [m].
 
std::size_t CellCount () const
 The number of cells.
 
std::size_t TileCount () const
 The number of tiles (with or without entries).
 
std::size_t SharedTileCount (const TiledGrid &other) const
 Test hook: the number of tiles with entries that this grid shares (same object) with other.
 
std::size_t FilledTileCount () const
 The number of tiles with entries.
 
std::size_t OverflowCount () const
 The number of boxes in the overflow list.
 
bool Inside (const Box &box) const
 True when the box is inside the extent (so it goes into the cells, not the overflow list).
 
TiledGrid With (std::span< const Item > removed, std::span< const Item > added) const
 
TiledGrid Cleared () const
 A grid with the same geometry and no boxes.
 
template<class Visitor >
void ForEachCandidate (const Box &query, Visitor &&visit) const
 
void Candidates (const Box &query, std::vector< std::uint32_t > &out) const
 Appends the ids of the boxes that overlap the query box to out (cleared first).
 

Static Public Attributes

static constexpr int kTileSide = 8
 Cells per tile side.
 
static constexpr int kTileCells = kTileSide * kTileSide
 Cells per tile.
 

Detailed Description

Index of boxes by horizontal cell for a field that changes by keyed steps (AggregationField::ApplyChanges).

The geometry (origin, cell size, cell counts) is fixed when the grid is made. The cells are grouped in square tiles of kTileSide x kTileSide cells. A copy of the grid shares every tile; With() makes a new grid in which only the tiles that a change touches are new. A box that is not inside the extent goes to an overflow list, which every query checks.

As in HashGrid, each box is listed in every cell its horizontal extent touches, with its own bounds, and a query reports a box once. The item id is a slot of the field's flat arrays. Immutable after construction: concurrent queries are safe, and a query on a copy is not affected by With() on another copy.

Constructor & Destructor Documentation

◆ TiledGrid()

environment::field::aggregation::TiledGrid::TiledGrid ( double  xMin,
double  xMax,
double  yMin,
double  yMax,
double  cellSize 
)

An empty grid over a horizontal extent.

Parameters
[in]xMin,xMax,yMin,yMaxThe extent [m], relative to the field origin. Finite, minimum not above maximum.
[in]cellSizeCell edge [m]; positive. It is enlarged when the cell count would pass HashGrid::kMaxCells, and to at least 1e-3 of the longer side.

Member Function Documentation

◆ ForEachCandidate()

template<class Visitor >
void environment::field::aggregation::TiledGrid::ForEachCandidate ( const Box &  query,
Visitor &&  visit 
) const
inline

Calls visit(id) once for each box that overlaps the query box: the cells first, then the overflow list.

The order is fixed by the grid's content (cells row by row, ids rising within a cell), so the same change sequence gives the same order.

◆ With()

TiledGrid environment::field::aggregation::TiledGrid::With ( std::span< const Item >  removed,
std::span< const Item >  added 
) const

A new grid: this one without the removed items and with the added ones. Tiles that neither touches are shared.

Parameters
[in]removedItems to take out, with the box they were added with. An id may also be in added (an update).
[in]addedItems to put in. Each id at most once.

The documentation for this class was generated from the following file: