85 lines
3.2 KiB
C++
85 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include <compare>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
|
|
namespace evo::world {
|
|
inline constexpr std::uint32_t coordinate_contract_version = 1;
|
|
inline constexpr std::int64_t voxel_limit = 1'048'576; // [-limit, limit), every axis
|
|
inline constexpr std::int64_t cell_pitch_mm = 1'000;
|
|
inline constexpr std::uint32_t fill_scale = 65'535;
|
|
|
|
// Values are logical addresses, never native serialization records. Each API
|
|
// validates raw input; constructing these aggregates does not validate them.
|
|
struct VoxelAddress {
|
|
std::int64_t x{}, y{}, z{};
|
|
auto operator<=>(const VoxelAddress&) const = default;
|
|
};
|
|
struct ChunkAddress {
|
|
std::int64_t x{}, y{}, z{};
|
|
auto operator<=>(const ChunkAddress&) const = default;
|
|
};
|
|
struct LocalCell {
|
|
std::uint32_t x{}, y{}, z{};
|
|
auto operator<=>(const LocalCell&) const = default;
|
|
};
|
|
struct ChunkLocation {
|
|
ChunkAddress chunk;
|
|
LocalCell local;
|
|
auto operator<=>(const ChunkLocation&) const = default;
|
|
};
|
|
struct SignedMillimetres {
|
|
std::int64_t value{};
|
|
auto operator<=>(const SignedMillimetres&) const = default;
|
|
};
|
|
struct MetricCorner {
|
|
SignedMillimetres x, y, z;
|
|
auto operator<=>(const MetricCorner&) const = default;
|
|
};
|
|
struct MaterialId {
|
|
std::uint16_t value{}; // zero is void; table membership is checked elsewhere
|
|
auto operator<=>(const MaterialId&) const = default;
|
|
};
|
|
enum class WorldError : std::uint8_t {
|
|
invalid_edge,
|
|
voxel_out_of_range,
|
|
chunk_out_of_range,
|
|
local_out_of_range,
|
|
ordinal_out_of_range,
|
|
invalid_cell
|
|
};
|
|
|
|
// Explicit edge candidate in {8,16,32,64}; no storage size has been adopted.
|
|
[[nodiscard]] std::expected<ChunkLocation, WorldError> split(VoxelAddress voxel,
|
|
std::uint32_t edge) noexcept;
|
|
[[nodiscard]] std::expected<VoxelAddress, WorldError> join(ChunkLocation location,
|
|
std::uint32_t edge) noexcept;
|
|
// Canonical logical enumeration, X fastest. Does not prescribe memory layout.
|
|
[[nodiscard]] std::expected<std::uint32_t, WorldError> ordinal(LocalCell local,
|
|
std::uint32_t edge) noexcept;
|
|
[[nodiscard]] std::expected<LocalCell, WorldError> local_from_ordinal(std::uint32_t index,
|
|
std::uint32_t edge) noexcept;
|
|
[[nodiscard]] std::expected<MetricCorner, WorldError> lower_corner_mm(VoxelAddress voxel) noexcept;
|
|
|
|
// Occupied volume fraction only; not an SDF, density or biological inventory.
|
|
// Trivial value copies/moves preserve validity. No material database dependency.
|
|
class CellSample {
|
|
public:
|
|
[[nodiscard]] static std::expected<CellSample, WorldError> create(MaterialId material,
|
|
std::uint32_t fill) noexcept;
|
|
[[nodiscard]] MaterialId material() const noexcept {
|
|
return material_;
|
|
}
|
|
[[nodiscard]] std::uint16_t fill() const noexcept {
|
|
return fill_;
|
|
}
|
|
auto operator<=>(const CellSample&) const = default;
|
|
|
|
private:
|
|
CellSample(MaterialId material, std::uint16_t fill) : material_{material}, fill_{fill} {}
|
|
MaterialId material_;
|
|
std::uint16_t fill_;
|
|
};
|
|
} // namespace evo::world
|