Files
EVEngine/src/modules/spatial/SpatialHash3D.h
T
西风逍遥游 4377e062dd feat: zeroerr parameter validation + Doxygen API documentation
Squashed onto current main. Adds src/engine/common/Assert.h (EV_PARAM_CHECK / EV_ASSERT backed by zeroerr), an EVENGINE_ENABLE_ASSERTS option (non-Debug builds strip ZEROERR_NO_ASSERT unless enabled), parameter checks at key entry points, Doxygen comments across headers, Doxyfile + make docs / CMake docs targets, and Windows setup + code conventions in AGENTS.md.
2026-08-19 09:01:12 +08:00

54 lines
1.9 KiB
C++

#pragma once
#include "spatial/Bounds.h"
#include "spatial/QueryIds.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace eve::spatial {
/** @brief Uniform-grid spatial hash for 3D AABB / sphere queries. */
class SpatialHash3D {
public:
explicit SpatialHash3D(float cellSize = 64.f);
~SpatialHash3D() = default;
SpatialHash3D(const SpatialHash3D &) = delete;
SpatialHash3D &operator=(const SpatialHash3D &) = delete;
void clear();
void setCellSize(float cellSize);
float getCellSize() const { return cellSize_; }
bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
bool remove(int id);
bool update(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
bool contains(int id) const;
int getCount() const { return static_cast<int>(items_.size()); }
int queryPoint(float x, float y, float z);
int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
int querySphere(float cx, float cy, float cz, float radius);
int getResultCount() const { return results_.getCount(); }
int getResultId(int index) const { return results_.getId(index); }
private:
void cellRange(const AABB3 &b, int &minCX, int &minCY, int &minCZ, int &maxCX, int &maxCY,
int &maxCZ) const;
void insertCells(int id, const AABB3 &b);
void eraseCells(int id, const AABB3 &b);
void queryCells(int minCX, int minCY, int minCZ, int maxCX, int maxCY, int maxCZ,
const AABB3 *box, float cx, float cy, float cz, float radius, bool useSphere,
bool usePoint);
float cellSize_ = 64.f;
std::unordered_map<int, AABB3> items_;
std::unordered_map<uint64_t, std::vector<int>> cells_;
QueryIds results_;
};
} // namespace eve::spatial