9constexpr auto CELL_CENTER =
static_cast<InnerSize
>(0.5);
11static constexpr HashSize XYBits = std::bit_width<HashSize>(MAX_HEIGHT - 1);
12static_assert(pow_int<XYBits, size_t>(2) == MAX_HEIGHT);
13static_assert(pow_int<XYBits, size_t>(2) == MAX_WIDTH);
14static constexpr HashSize ColumnMask = bit_mask<XYBits, HashSize>();
23struct XPos :
public StrictType<XPos, units::Unitless, XYSize, std::numeric_limits<Idx>::max()>
25 using StrictType::StrictType;
26 auto operator<=>(
const XPos& rhs)
const =
default;
29struct YPos :
public StrictType<YPos, units::Unitless, XYSize, std::numeric_limits<Idx>::max()>
31 using StrictType::StrictType;
32 auto operator<=>(
const YPos& rhs)
const =
default;
34struct XIdx :
public StrictType<XIdx, units::Unitless, Idx, std::numeric_limits<Idx>::max()>
36 using StrictType::StrictType;
37 explicit constexpr XIdx(
const XPos& x) :
XIdx(
static_cast<Idx
>(x.value)) { }
38 auto operator<=>(
const XIdx& rhs)
const =
default;
40struct YIdx :
public StrictType<YIdx, units::Unitless, Idx, std::numeric_limits<Idx>::max()>
42 using StrictType::StrictType;
43 explicit constexpr YIdx(
const YPos& y) :
YIdx(
static_cast<Idx
>(y.value)) { }
44 auto operator<=>(
const YIdx& rhs)
const =
default;
52 static constexpr XYPos Invalid()
noexcept {
return XYPos{XPos::Invalid(), YPos::Invalid()}; }
53 auto operator<=>(
const XYPos& rhs)
const =
default;
56template <
class S,
int XMin,
int XMax,
int YMin,
int YMax>
62template <
class S,
int XMin,
int XMax,
int YMin,
int YMax>
67 auto operator==(
const BoundedPoint& rhs)
const noexcept {
return x == rhs.x && y == rhs.y; }
70 if (
auto cmp = x <=> rhs.x; 0 != cmp)
77 static constexpr auto INVALID_X = XMin - 1;
78 static constexpr auto INVALID_Y = YMin - 1;
84 constexpr inline Idx x_value()
const noexcept {
return x.value; }
85 constexpr inline Idx y_value()
const noexcept {
return y.value; }
86 constexpr XYIdx() =
default;
87 explicit constexpr XYIdx(
const XIdx& x0,
const YIdx& y0) : x{x0}, y{y0}
91 if (-1 >= x.value || MAX_WIDTH <= x.value || -1 >= y.value || MAX_HEIGHT <= y.value)
93 cout << std::format(
"xy out of bounds: ({}, {})", x.value, y.value);
99 explicit constexpr XYIdx(
const T& x0,
const T& y0)
100 :
XYIdx(
XIdx{
static_cast<Idx
>(x0)},
YIdx{
static_cast<Idx
>(y0)})
102 template <
class S,
int XMin,
int XMax,
int YMin,
int YMax>
107 constexpr auto operator==(
const XYIdx& rhs)
const noexcept {
return x == rhs.x && y == rhs.y; }
108 constexpr auto operator<=>(
const XYIdx& rhs)
const noexcept
111 if (
const auto cmp = y <=> rhs.y; 0 != cmp)
117 XYPos operator+(
const XYPos& rhs)
const noexcept
119 return XYPos{
XPos{rhs.x.value + x.value},
YPos{rhs.y.value + y.value}};
121 XYPos center()
const noexcept {
return *
this +
XYPos{
XPos{CELL_CENTER},
YPos{CELL_CENTER}}; }
122 XYIdx operator+(
const XYIdx& rhs)
const noexcept {
return XYIdx{x + rhs.x, y + rhs.y}; }
123 XYIdx operator+(
const XIdx& rhs)
const noexcept {
return XYIdx{x + rhs, y}; }
124 XYIdx operator+(
const YIdx& rhs)
const noexcept {
return XYIdx{x, y + rhs}; }
135 constexpr CellIndex DIRECTIONS[9] = {
146 return DIRECTIONS[((x - rhs.x).value + 1) + 3 * ((y - rhs.y).value + 1)];
151inline XYPos operator+(
const XYPos& lhs,
const XYIdx& rhs)
noexcept {
return rhs + lhs; }
152static inline constexpr std::pair<XIdx, YIdx> hash_to_xy(
const XYIdx& xy)
noexcept
156static inline constexpr std::pair<Idx, Idx> hash_to_xy_value(
const XYIdx& xy)
noexcept
158 return {xy.x_value(), xy.y_value()};
160static inline constexpr size_t to_index(
const XYIdx& xy)
noexcept
163 return (
static_cast<HashSize
>(xy.y_value()) << XYBits) +
static_cast<HashSize
>(xy.x_value());
173inline constexpr CellIndex relativeIndex(
const XYIdx& src,
const XYIdx& dst)
noexcept
175 return src.relativeIndex(dst);
A wrapper around a ValueType to ensure correct types are used.
Definition StrictType.h:34
constexpr CellIndex relativeIndex(const XYIdx &rhs) const noexcept
Definition Location.h:133