Skip to content

Commit 76052e0

Browse files
committed
Minor changes
1 parent f0cef9d commit 76052e0

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

octree.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ ORTHOTREE_INDEX_T__INT / ORTHOTREE_INDEX_T__SIZE_T / ORTHOTREE_INDEX_T__UINT_FAS
102102

103103
#ifndef CRASH
104104
#define CRASH_UNDEF
105-
#define CRASH() \
106-
do \
107-
{ \
108-
assert(false); \
109-
std::terminate(); \
105+
#define CRASH(errorMessage) \
106+
do \
107+
{ \
108+
assert(false && errorMessage); \
109+
std::terminate(); \
110110
} while (0)
111111
#endif // !CRASH
112112

113113
#ifndef CRASH_IF
114114
#define CRASH_IF_UNDEF
115-
#define CRASH_IF(cond) \
116-
do \
117-
{ \
118-
if (cond) \
119-
{ \
120-
CRASH(); \
121-
} \
115+
#define CRASH_IF(cond, errorMessage) \
116+
do \
117+
{ \
118+
if (cond) \
119+
{ \
120+
CRASH(errorMessage); \
121+
} \
122122
} while (0)
123123
#endif // !CRASH_IF
124124

@@ -1456,7 +1456,7 @@ namespace OrthoTree
14561456
// Indexing can be solved with integral types (above this, internal container will be changed to std::map)
14571457
static auto constexpr IS_LINEAR_TREE = IS_32BIT_LOCATION || IS_64BIT_LOCATION;
14581458

1459-
static auto constexpr MAX_NONLINEAR_DEPTH_ID = 4;
1459+
static auto constexpr MAX_NONLINEAR_DEPTH_ID = depth_t{ 4 };
14601460

14611461
using UnderlyingInt = std::conditional_t<IS_32BIT_LOCATION, uint32_t, uint64_t>;
14621462
using ChildID = UnderlyingInt;
@@ -1479,7 +1479,7 @@ namespace OrthoTree
14791479

14801480
// Type system determined maximal depth id due to the resolution.
14811481
static auto constexpr MAX_THEORETICAL_DEPTH_ID =
1482-
IS_LINEAR_TREE ? static_cast<depth_t>((CHAR_BIT * sizeof(NodeID) - 1 /*sentinal bit*/)) / DIMENSION_NO : MAX_NONLINEAR_DEPTH_ID;
1482+
IS_LINEAR_TREE ? static_cast<depth_t>((CHAR_BIT * sizeof(NodeID) - 1 /*sentinel bit*/)) / DIMENSION_NO : MAX_NONLINEAR_DEPTH_ID;
14831483

14841484
struct RangeLocationMetaData
14851485
{
@@ -1562,7 +1562,7 @@ namespace OrthoTree
15621562
if (key == 1) // If only sentinel bit remains, exit with node depth
15631563
return d;
15641564

1565-
CRASH(); // Bad key
1565+
CRASH("Bad key! Internal error!"); // Bad key
15661566
}
15671567
}
15681568

@@ -2028,6 +2028,7 @@ namespace OrthoTree
20282028
constexpr ChildBitIterator begin() const noexcept { return ChildBitIterator(m_nodeKey, m_childBits); }
20292029
constexpr ChildBitIterator end() const noexcept { return ChildBitIterator(m_nodeKey, {}); }
20302030
constexpr std::size_t size() const noexcept { return std::popcount(m_childBits); }
2031+
constexpr std::size_t empty() const noexcept { return m_childBits == 0; }
20312032

20322033
private:
20332034
MortonLocationID m_nodeKey;
@@ -2084,6 +2085,7 @@ namespace OrthoTree
20842085
constexpr ChildVectorIterator begin() const noexcept { return ChildVectorIterator(m_nodeKey, m_children.begin()); }
20852086
constexpr ChildVectorIterator end() const noexcept { return ChildVectorIterator(m_nodeKey, m_children.end()); }
20862087
constexpr std::size_t size() const noexcept { return m_children.size(); }
2088+
constexpr std::size_t empty() const noexcept { return m_children.empty(); }
20872089

20882090
private:
20892091
MortonLocationID m_nodeKey;
@@ -2734,13 +2736,12 @@ namespace OrthoTree
27342736
// Alternative creation mode (instead of Create), Init then Insert items into leafs one by one. NOT RECOMMENDED.
27352737
constexpr void InitBase(IGM::Box const& boxSpace, depth_t maxDepthID, std::size_t maxElementNo) noexcept
27362738
{
2737-
CRASH_IF(!this->m_nodes.empty()); // To build/setup/create the tree, use the Create() [recommended] or Init() function. If an already
2738-
// builded tree is wanted to be reset, use the Reset() function before init.
2739-
CRASH_IF(maxDepthID < 1);
2740-
CRASH_IF(maxDepthID > SI::MAX_THEORETICAL_DEPTH_ID);
2741-
CRASH_IF(maxDepthID >= std::numeric_limits<uint8_t>::max());
2742-
CRASH_IF(maxElementNo == 0);
2743-
CRASH_IF(CHAR_BIT * sizeof(GridID) < this->m_maxDepthID);
2739+
CRASH_IF(!this->m_nodes.empty(), "To build/setup/create the tree, use the Create() [recommended] or Init() function. If an already built tree is wanted to be reset, use the Reset() function before Init().");
2740+
CRASH_IF(maxDepthID < 1, "maxDepthID must be largar than 0!");
2741+
CRASH_IF(maxDepthID > SI::MAX_THEORETICAL_DEPTH_ID, "maxDepthID is larger than the applicable with the current DIMENSION_NO!");
2742+
CRASH_IF(maxDepthID >= std::numeric_limits<uint8_t>::max(), "maxDepthID is too large.");
2743+
CRASH_IF(maxElementNo == 0, "maxElementNo must be larger than 0. It is allowed max entity number for one node.");
2744+
CRASH_IF(CHAR_BIT * sizeof(GridID) < maxDepthID, "GridID and maxDepthID are not compatible.");
27442745

27452746
this->m_grid = detail::GridSpaceIndexing<DIMENSION_NO, TGeometry, TVector, TBox, AD>(maxDepthID, boxSpace);
27462747
this->m_maxDepthID = maxDepthID;
@@ -3797,8 +3798,8 @@ namespace OrthoTree
37973798
};
37983799

37993800

3800-
// OrthoTreeBoundingBox: Non-owning container which spatially organize bounding box ids in N dimension space into a hash-table by Morton Z order.
3801-
// DO_SPLIT_PARENT_ENTITIES: if (DO_SPLIT_PARENT_ENTITIES > 0) Those items which are not fit in the child nodes may be stored in the children/grand-children instead of the parent.
3801+
// OrthoTreeBoundingBox: Non-owning container which spatially organize axis aligned bounding box (AABB) ids in N dimension space into a hash-table by Morton Z order.
3802+
// DO_SPLIT_PARENT_ENTITIES: Those items which are not fit in the child nodes may be stored in the children/grand-children instead of the parent.
38023803
template<
38033804
dim_t DIMENSION_NO,
38043805
typename TVector_,

0 commit comments

Comments
 (0)