Struct NeighbourId#

Struct Documentation#

struct NeighbourId#

A type identifying a neighboring direction

A neighbor is identified by using a Position value at each dimension, where the Position can be FRONT, MID or BACK

  • FRONT: the neighbor is in the front in this dimension

  • MID: the neighbor is at the same pos in this dimension

  • BACK: the neighbor is at the back in this dimension

To retrieve the Position value at each dimension, use the subscript operator.

To iterate through all the neighbor dimension, use the firstId static method to get the initial neighbor and then get subsequence ones using the ++ operator. To check whether the next neighbor exist, use the hasNextNeighbour method.

for (auto neighborId = NeighbourId::firstId(3); neighborId.hasNextNeighbour(); neighborId++) {
    // do something ...
}

Note

This is a very lightweight type, so copying it is very efficient.

Public Types

enum class Position : uint#

Values:

enumerator FRONT#
enumerator MID#
enumerator BACK#

Public Functions

inline NeighbourId(const Dimension dimensions, const Index flattenId)#

Initialize a NeighbourId using the flattened id

The flattened id is a single integer calculated by treating the Position values at each dimension as a base-3 encoding and convert to base-10 representation.

inline NeighbourId(const std::initializer_list<Position> &list)#

Initialize a NeighbourId by directly providing the Position value at each dimension

Parameters:

list – A brace init list specifying the Position value at each dimension

inline Dimension dimensions() const noexcept#
inline Index flattenId() const noexcept#
inline Position operator[](const Index dimIndex) const noexcept#

Get the Position value at a certain dimension

inline void setPosAtDim(const Index dimIndex, const Position pos) noexcept#

Update the Position value at a certain dimension

inline NeighbourId oppositeNeighbourId() const noexcept#

Get the identity of the neighbor at the opposite direction

inline bool operator==(const NeighbourId &other) const noexcept#
NeighbourId operator++()#
inline bool hasNextNeighbour() const noexcept#

Check whether there is a subsequence neighbor after the current one

Public Static Functions

static inline NeighbourId firstId(const Dimension dimensions)#

Construct the first neighbor id with the smallest flattened id

static inline NeighbourId lastId(const Dimension dimensions)#

Construct the last neighbor id with the largest flattened id

Note that the NeighbourId returned by this function is still a valid one

Friends

friend std::ostream &operator<<(std::ostream &os, const NeighbourId &neighbourId)#