载入中...
搜索中...
未找到
HexSphereTopology.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
7#include "common/Result.h"
8#include "hexmap/HexMetrics.h"
9
10#include <cstdint>
11#include <vector>
12
13namespace eve::hexmap {
14
16using HexSphereCell = std::int32_t;
17
19inline constexpr HexSphereCell kNoHexSphereCell = -1;
20
22inline constexpr std::int32_t kMaxHexSphereSubdivision = 7;
23
55public:
57 HexSphereTopology() = default;
58
71 [[nodiscard]] static Result<HexSphereTopology> build(std::int32_t subdivision);
72
74 [[nodiscard]] bool empty() const noexcept { return directions_.empty(); }
76 [[nodiscard]] std::int32_t subdivision() const noexcept { return subdivision_; }
78 [[nodiscard]] std::int32_t frequency() const noexcept { return frequency_; }
80 [[nodiscard]] std::int32_t cellCount() const noexcept { return static_cast<std::int32_t>(directions_.size()); }
82 [[nodiscard]] std::int32_t pentagonCount() const noexcept { return empty() ? 0 : 12; }
84 [[nodiscard]] std::int32_t edgeCount() const noexcept { return static_cast<std::int32_t>(neighbors_.size() / 2u); }
86 [[nodiscard]] std::int32_t cornerCount() const noexcept {
87 return static_cast<std::int32_t>(cornerDirections_.size());
88 }
89
91 [[nodiscard]] bool contains(HexSphereCell cell) const noexcept { return cell >= 0 && cell < cellCount(); }
93 [[nodiscard]] bool isPentagon(HexSphereCell cell) const noexcept {
94 return contains(cell) && neighborCount(cell) == 5;
95 }
97 [[nodiscard]] std::int32_t neighborCount(HexSphereCell cell) const noexcept;
106 [[nodiscard]] HexSphereCell neighbor(HexSphereCell cell, std::int32_t direction) const noexcept;
117 [[nodiscard]] std::int32_t directionOf(HexSphereCell cell, HexSphereCell other) const noexcept;
119 [[nodiscard]] std::int32_t oppositeDirection(HexSphereCell cell, std::int32_t direction) const noexcept;
120
122 [[nodiscard]] HexVec3 direction(HexSphereCell cell) const noexcept;
124 [[nodiscard]] std::int32_t cornerCountOf(HexSphereCell cell) const noexcept;
135 [[nodiscard]] HexVec3 corner(HexSphereCell cell, std::int32_t corner) const noexcept;
136
147 [[nodiscard]] HexSphereCell cellAt(HexVec3 unitDirection) const noexcept;
149 [[nodiscard]] static float angularDistance(HexVec3 a, HexVec3 b) noexcept;
150
151private:
152 std::vector<HexVec3> directions_;
153 std::vector<std::int32_t> cellOffsets_;
154 std::vector<HexSphereCell> neighbors_;
155 std::vector<std::int32_t> corners_;
156 std::vector<HexVec3> cornerDirections_;
157 std::int32_t subdivision_ = 0;
158 std::int32_t frequency_ = 1;
159};
160
161} // namespace eve::hexmap
#define EVENGINE_API_WORLD
Definition Export.h:109
Pointy-top hex metrics, directions and vertex helpers.
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
Move-only, checked operation results for the common layer.
RoadLaneDirection direction
Cell cell
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Icosahedral (Goldberg) hex topology for a spherical hex map.
std::int32_t subdivision() const noexcept
The subdivision level this topology was built at.
bool contains(HexSphereCell cell) const noexcept
Whether cell is a valid id of this topology.
HexSphereTopology()=default
Hex sphere topology.
std::int32_t cornerCount() const noexcept
Number of distinct corners (20 * f^2), each shared by three cells.
std::int32_t cellCount() const noexcept
Number of cells (10 * f^2 + 2).
std::int32_t pentagonCount() const noexcept
Number of pentagonal cells (12 for every non-empty topology).
std::int32_t frequency() const noexcept
Subdivision frequency f = 2^subdivision.
bool isPentagon(HexSphereCell cell) const noexcept
Whether cell has five edges instead of six; false when out of range.
bool empty() const noexcept
Whether the topology holds no cell.
std::int32_t edgeCount() const noexcept
Number of cell-to-cell edges (30 * f^2).
constexpr std::int32_t kMaxHexSphereSubdivision
Largest supported subdivision level; 10 * 4^7 + 2 = 163842 cells.
constexpr HexSphereCell kNoHexSphereCell
Returned by a spherical cell query that has no answer.
std::int32_t HexSphereCell
Dense identifier of one cell of a spherical hex topology.
Minimal 3-component float vector used by the hex mesh builders.
Definition HexMetrics.h:18