From 23e7ecb812b7002d801a282522b5c127280f601f Mon Sep 17 00:00:00 2001 From: Ilusha <63184036+IlyaShurupov@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:45:24 +0300 Subject: [PATCH] Fix interval tree --- Containers/public/IntervalTree.hpp | 12 ++++++++++-- Containers/tests/IntervalTreeTests.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Containers/public/IntervalTree.hpp b/Containers/public/IntervalTree.hpp index d5e4b95..bfc55c0 100644 --- a/Containers/public/IntervalTree.hpp +++ b/Containers/public/IntervalTree.hpp @@ -14,8 +14,16 @@ namespace tp { mEnd = end; } - inline bool descentRight(const IntervalKey& in) const { return in.mStart > mStart; } - inline bool descentLeft(const IntervalKey& in) const { return in.mStart <= mStart; } + inline bool descentRight(const IntervalKey& in) const { + if (in.mStart != mStart) return in.mStart > mStart; + return in.mEnd > mEnd; + } + + inline bool descentLeft(const IntervalKey& in) const { + if (in.mStart != mStart) return in.mStart < mStart; + return in.mEnd < mEnd; + } + inline bool exactNode(const IntervalKey& in) const { return in.mStart == mStart && in.mEnd == mEnd; } inline const IntervalKey& getFindKey() const { return *this; } diff --git a/Containers/tests/IntervalTreeTests.cpp b/Containers/tests/IntervalTreeTests.cpp index 3923d7c..2dcbd69 100644 --- a/Containers/tests/IntervalTreeTests.cpp +++ b/Containers/tests/IntervalTreeTests.cpp @@ -10,7 +10,7 @@ using namespace tp; struct Interval { - [[nodiscard]] bool overlaps(const Interval& in) const { return in.start < end && in.end > start; } + [[nodiscard]] bool overlaps(const Interval& in) const { return in.start <= end && in.end >= start; } halnf start{}; halnf end{};