Shifted Cartesian Layout

Header: fiction/layouts/shifted_cartesian_layout.hpp

Coordinate system that represents a shifted Cartesian grid of compile-time coordinate types. In contrast to Cartesian layouts, the faces of shifted Cartesian layouts can be arranged in different ways. The most obvious are the distinction between the orientation of the shift that can be horizontal and vertical.

struct horizontal_shift_cartesian
+-------+
|       |
|       |
|       |
+---+---+---+
    |       |
    |       |
    |       |
    +-------+

Subclassed by fiction::even_row_cartesian, fiction::odd_row_cartesian

struct vertical_shift_cartesian
+-------+
|       |
|       +-------+
|       |       |
+-------+       |
        |       |
        +-------+

Subclassed by fiction::even_column_cartesian, fiction::odd_column_cartesian

Furthermore, when assuming rectangular-ish layouts, either odd or even rows or columns can be shifted inwards, yielding a total of four different orientations.

struct odd_row_cartesian : public fiction::horizontal_shift_cartesian
+-------+-------+-------+
|       |       |       |
| (0,0) | (1,0) | (2,0) |
|       |       |       |
+---+---+---+---+---+---+---+
    |       |       |       |
    | (0,1) | (1,1) | (2,1) |
    |       |       |       |
+---+---+---+---+---+---+---+
|       |       |       |
| (0,2) | (1,2) | (2,2) |
|       |       |       |
+-------+-------+-------+
struct even_row_cartesian : public fiction::horizontal_shift_cartesian
     +-------+-------+-------+
     |       |       |       |
     | (0,0) | (1,0) | (2,0) |
     |       |       |       |
 +---+---+---+---+---+---+---+
 |       |       |       |
 | (0,1) | (1,1) | (2,1) |
 |       |       |       |
 +---+---+---+---+---+---+---+
     |       |       |       |
     | (0,2) | (1,2) | (2,2) |
     |       |       |       |
     +-------+-------+-------+
struct odd_column_cartesian : public fiction::vertical_shift_cartesian
  +-------+       +-------+
  |       |       |       |
  | (0,0) +-------+ (2,0) +-------+
  |       |       |       |       |
  +-------+ (1,0) +-------+ (3,0) |
  |       |       |       |       |
  | (0,1) +-------+ (2,1) +-------+
  |       |       |       |       |
  +-------+ (1,1) +-------+ (3,1) |
  |       |       |       |       |
  | (0,2) +-------+ (2,2) +-------+
  |       |       |       |
  +-------+       +-------+
struct even_column_cartesian : public fiction::vertical_shift_cartesian
          +-------+       +-------+
          |       |       |       |
  +-------+ (1,0) +-------+ (3,0) |
  |       |       |       |       |
  | (0,0) +-------+ (2,0) +-------+
  |       |       |       |       |
  +-------+ (1,1) +-------+ (3,1) |
  |       |       |       |       |
  | (0,1) +-------+ (2,1) +-------+
  |       |       |       |       |
  +-------+ (1,2) +-------+ (3,2) |
          |       |       |       |
          +-------+       +-------+

The shifted Cartesian layout supports all of them via template parameters. It shares its members with hexagonal_layout.

template<typename OffsetCoordinateType = offset::ucoord_t, typename ShiftedCartesianCoordinateSystem = even_row_cartesian>
class shifted_cartesian_layout : public fiction::hexagonal_layout<offset::ucoord_t, std::conditional_t<std::is_same_v<even_row_cartesian, odd_row_cartesian>, odd_row_hex, std::conditional_t<std::is_same_v<even_row_cartesian, even_row_cartesian>, even_row_hex, std::conditional_t<std::is_same_v<even_row_cartesian, odd_column_cartesian>, odd_column_hex, std::conditional_t<std::is_same_v<even_row_cartesian, even_column_cartesian>, even_column_hex, void>>>>, cube::coord_t>

A layout type that utilizes offset coordinates to represent a cartesian layout with shifted coordinates. Its faces are organizes in an offset coordinate system as provided. These can either be the horizontal_shift_cartesian or vertical_shift_cartesian orientation. Based on that, two respectively possible coordinate systems emerge accordingly: odd_row_cartesian and even_row_cartesian for horizontal shifts and odd_column_cartesian and even_column_cartesian for vertical shifts. All are sketched in ASCII above.

Template Parameters:

Public Functions

inline explicit shifted_cartesian_layout(const typename HexagonalLayout::aspect_ratio &ar = {})

Standard constructor. The given aspect ratio points to the highest possible coordinate in the layout. That means in the even_column_cartesian ASCII layout representation above ar = (3,2). Consequently, with ar = (0,0), the layout has exactly one coordinate.

Parameters:

ar – Highest possible position in the layout.