From 450a816b2b91304d16195630895afcc09d260bd6 Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Tue, 8 Oct 2024 14:39:30 +0300 Subject: [PATCH] Lovelly bug in Interval Tree --- Containers/public/IntervalTree.hpp | 4 +++- Containers/tests/IntervalTreeTests.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Containers/public/IntervalTree.hpp b/Containers/public/IntervalTree.hpp index f877ed2..9419f6d 100644 --- a/Containers/public/IntervalTree.hpp +++ b/Containers/public/IntervalTree.hpp @@ -2,6 +2,8 @@ #include "Tree.hpp" +#include + namespace tp { template @@ -31,7 +33,7 @@ namespace tp { template inline void updateNodeCache(const tTreeNodeType* node) { - mMax = 0; + mMax = std::numeric_limits::min(); if (node->mRight && node->mRight->key.mMax > mMax) mMax = node->mRight->key.mMax; if (node->mLeft && node->mLeft->key.mMax > mMax) mMax = node->mLeft->key.mMax; if (mMax < mEnd) mMax = mEnd; diff --git a/Containers/tests/IntervalTreeTests.cpp b/Containers/tests/IntervalTreeTests.cpp index fdf725e..fccd4f8 100644 --- a/Containers/tests/IntervalTreeTests.cpp +++ b/Containers/tests/IntervalTreeTests.cpp @@ -16,8 +16,11 @@ struct Interval { bool ignore = false; void random(halnf span, halnf scale = 1.f) { - start = ((halnf) randomFloat()) * (span); - end = ((halnf) randomFloat()) * (span); + auto offset = 0; + + start = ((halnf) randomFloat()) * (span) - offset; + end = ((halnf) randomFloat()) * (span) - offset; + if (start > end) swap(start, end); auto len = (end - start) * scale * 0.5f;