cubexx::direction_t

struct cubexx::direction_t

Represents a direction of a cube.

There are 6 directions in a cube. A direction_t is 1:1 equivalent to a face_t; they can be converted from one to the other via direction_t::face() and face_t::direction().

See
face_t

Public Functions

direction_t()

Default constructs a “null” direction_t.

const face_t &face() const

Returns the equivalent face.

const direction_t &opposite() const

Returns the opposite direction.

const std::array<direction_t, 4> &adjacents() const

Returns the four adjacent directions.

const direction_set_t &adjacent_set() const

Return a direction_set_t containing the 4 adjacent directions.

std::int_fast8_t x() const

Return the x component of the direction vector.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See
get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t), xyz()

std::int_fast8_t y() const

Return the y component of the direction vector.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See
get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t), xyz()

std::int_fast8_t z() const

Return the z component of the direction vector.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See
get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t), xyz()

bool positive() const

Returns true if the direction vector is positive; false if it is negative.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See

get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t), xyz()

axis(), x(), y(), z(), xyz()

uint_fast8_t axis() const

Returns a number \(\in \left\{0,1,2\right\}\) representing the axis of the direction.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See

get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t)

positive(), x(), y(), z(), xyz()

const std::array<std::int_fast8_t, 3> &xyz() const

Return all three components of the direction vector.

See get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t) for more information.

See
get(std::int_fast8_t,std::int_fast8_t,std::int_fast8_t), x(), y(), z()

std::uint_fast8_t index() const

Retrieve a numeric 0-based index for the direction, for use in indexing when storing in an array, or for comparison when storing in a container requiring comparison.

The index will be less than SIZE(). The “null” direction has no index, and it is illegal to call index() on it.

See
get(std::uint_fast8_t idx)

bool operator<(const direction_t &other) const

Comparison.

bool operator==(const direction_t &other) const

Comparison.

bool operator!=(const direction_t &other) const

Comparison.

bool is_null() const

Returns true if this direction is a null direction_t.

Public Static Functions

static const direction_t &get(std::int_fast8_t x, std::int_fast8_t y, std::int_fast8_t z)

Returns a direction from a vector of 3 integer components; two of them must be 0, the third must be positive or negative in the dimension of the direction.

For example, (0,0,+1) means a direction on the z-axis pointing along the positive length of the axis. While (-1,0,0) means a direction on the (negative) x-axis pointing toward the negative asymptote of the x-axis.

See
x(), y(), z(), axis(), positive()

static const direction_t &get(const direction_t &direction)

Returns a direction given a direction.

static const direction_t &get(std::uint_fast8_t idx)

Return the direction represented by an index.

See
index()

static const std::array<direction_t, 6> &all()

Return a list of all the directions on the cube.

static const direction_t &null_direction()

Returns a null direction.

static std::size_t SIZE()

Number of directions.