8using SpreadKey = uint32_t;
30 explicit constexpr Cell(
const SpreadKey hash) noexcept :
data_{hash} { }
38 [[nodiscard]]
static constexpr SpreadKey
hashCell(
39 const SlopeSize
slope,
41 const FuelCodeSize& fuel
46 const auto do_hash_cell = [](
const SlopeSize s,
const AspectSize a,
const FuelCodeSize f) {
50 if (INVALID_SLOPE ==
slope || INVALID_ASPECT ==
aspect || INVALID_FUEL_CODE == fuel)
52 return do_hash_cell(INVALID_SLOPE, INVALID_ASPECT, INVALID_FUEL_CODE);
57 constexpr Cell() noexcept
59 numeric_limits<SlopeSize>::min(),
60 numeric_limits<AspectSize>::min(),
61 numeric_limits<FuelCodeSize>::min()
71 constexpr Cell(
const SlopeSize
slope,
const AspectSize
aspect,
const FuelCodeSize& fuel) noexcept
79 [[nodiscard]]
static constexpr SpreadKey
key(
const SpreadKey value)
noexcept
82 return static_cast<SpreadKey
>(value >>
FuelShift);
89 [[nodiscard]]
static constexpr AspectSize
aspect(
const SpreadKey value)
noexcept
98 [[nodiscard]]
static constexpr FuelCodeSize
fuelCode(
const SpreadKey value)
noexcept
107 [[nodiscard]]
static constexpr SlopeSize
slope(
const SpreadKey value)
noexcept
166 static constexpr uint32_t
FuelBits = std::bit_width<uint32_t>(NUMBER_OF_FUELS);
170 static constexpr SpreadKey
FuelBitMask = bit_mask<FuelBits, SpreadKey>();
184 static constexpr uint32_t
AspectBits = std::bit_width<uint32_t>(MAX_ASPECT);
188 static constexpr SpreadKey
AspectBitMask = bit_mask<AspectBits, SpreadKey>();
202 static constexpr uint32_t
SlopeBits = std::bit_width<uint32_t>(MAX_SLOPE_FOR_DISTANCE);
207 static constexpr SpreadKey
SlopeBitMask = bit_mask<SlopeBits, SpreadKey>();
215 static_cast<size_t>(std::bit_width(std::numeric_limits<SpreadKey>::max()))
A Position with a Slope, Aspect, and Fuel.
Definition Cell.h:13
static constexpr uint32_t FuelBits
Number of bits in fuel bitmask.
Definition Cell.h:166
static constexpr AspectSize aspect(const SpreadKey value) noexcept
Aspect (degrees)
Definition Cell.h:89
static constexpr SpreadKey hashCell(const SlopeSize slope, const AspectSize aspect, const FuelCodeSize &fuel) noexcept
Hash attributes into a SpreadKey value.
Definition Cell.h:38
constexpr Cell(const SlopeSize slope, const AspectSize aspect, const FuelCodeSize &fuel) noexcept
Construct based on given attributes.
Definition Cell.h:71
static constexpr SpreadKey key(const SpreadKey value) noexcept
A key defining Slope, Aspect, and Fuel, used for determining Cells that spread the same.
Definition Cell.h:79
static constexpr uint32_t SlopeShift
Shift for slope bitmask.
Definition Cell.h:198
constexpr SpreadKey key() const noexcept
A key defining Slope, Aspect, and Fuel, used for determining Cells that spread the same.
Definition Cell.h:115
static constexpr SpreadKey FuelBitMask
Bitmask for fuel information in SpreadKey before shift.
Definition Cell.h:170
static constexpr uint32_t AspectBits
Number of bits in aspect bitmask.
Definition Cell.h:184
static constexpr SpreadKey SlopeBitMask
Bitmask for slope in SpreadKey before shift.
Definition Cell.h:207
static constexpr SlopeSize slope(const SpreadKey value) noexcept
Slope (degrees)
Definition Cell.h:107
static constexpr SpreadKey AspectBitMask
Bitmask for aspect in SpreadKey before shift.
Definition Cell.h:188
constexpr Cell(const SpreadKey hash) noexcept
Construct from hash value.
Definition Cell.h:30
constexpr SlopeSize slope() const noexcept
Slope (degrees)
Definition Cell.h:130
static constexpr uint32_t SlopeBits
Number of bits in slope bitmask.
Definition Cell.h:202
static constexpr SpreadKey SlopeMask
Bitmask for slope in SpreadKey.
Definition Cell.h:213
SpreadKey data_
Stored hash that contains x and y data.
Definition Cell.h:18
static constexpr uint32_t FuelShift
Shift for fuel bitmask.
Definition Cell.h:160
static constexpr SpreadKey AspectMask
Bitmask for aspect in SpreadKey.
Definition Cell.h:194
static constexpr SpreadKey FuelMask
Bitmask for fuel information in SpreadKey.
Definition Cell.h:176
constexpr SpreadKey fullHash() const
Full stored hash that may contain data from subclasses.
Definition Cell.h:25
static constexpr FuelCodeSize fuelCode(const SpreadKey value) noexcept
Fuel.
Definition Cell.h:98
static constexpr uint32_t AspectShift
Shift for aspect bitmask.
Definition Cell.h:180
constexpr FuelCodeSize fuelCode() const noexcept
Fuel.
Definition Cell.h:125
constexpr AspectSize aspect() const noexcept
Aspect (degrees)
Definition Cell.h:120