Skip to content

Commit 67088e3

Browse files
committed
Fixed reported issue.
1 parent 99d1e9a commit 67088e3

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

interval_tree.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,22 +1242,16 @@ namespace lib_interval_tree
12421242
if (ptr->left_ && ptr->left_->max() >= ival.low())
12431243
{
12441244
// no right? can only continue left
1245-
if (!ptr->right_)
1246-
return overlap_find_all_i<Exclusive, IteratorT>(ptr->left_, ival, on_find);
1247-
1248-
// upper bounds higher than what is contained right? continue left
1249-
if (ival.high() > ptr->right_->max())
1245+
// or upper bound is lower than what is contained right? continue left
1246+
if (!ptr->right_ || ival.high() < ptr->right_->low())
12501247
return overlap_find_all_i<Exclusive, IteratorT>(ptr->left_, ival, on_find);
12511248

12521249
if (!overlap_find_all_i<Exclusive, IteratorT>(ptr->left_, ival, on_find))
12531250
return false;
12541251
}
12551252
if (ptr->right_ && ptr->right_->max() >= ival.low())
12561253
{
1257-
if (!ptr->left_)
1258-
return overlap_find_all_i<Exclusive, IteratorT>(ptr->right_, ival, on_find);
1259-
1260-
if (ival.high() > ptr->left_->max())
1254+
if (!ptr->left_ || ival.high() < ptr->left_->low())
12611255
return overlap_find_all_i<Exclusive, IteratorT>(ptr->right_, ival, on_find);
12621256

12631257
if (!overlap_find_all_i<Exclusive, IteratorT>(ptr->right_, ival, on_find))

tests/float_overlap_tests.hpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
22

33
#include "test_utility.hpp"
4-
#include "../draw.hpp"
4+
#include "../draw.hpp"
5+
6+
#include <algorithm>
57

68
class FloatOverlapFindTests
79
: public ::testing::Test
@@ -35,39 +37,31 @@ TEST_F(FloatOverlapFindTests, FloatOverlapTest)
3537
double lat0 = 1.040893537045970;
3638
double lat1 = 1.570796326794897;
3739

38-
std::vector <lib_interval_tree::interval<double>> vecOverlapsA;
40+
std::vector <std::pair<double, double>> vecOverlapsA;
3941
lib_interval_tree::interval <double> intSource({lat0, lat1});
40-
for (auto itTargetInterval : tree)
42+
for (auto const& iter : tree)
4143
{
42-
if (itTargetInterval.overlaps(intSource))
43-
{
44-
vecOverlapsA.push_back(itTargetInterval);
45-
}
44+
if (iter.overlaps(intSource))
45+
vecOverlapsA.push_back({iter.low(), iter.high()});
4646
}
4747

48-
std::vector <lib_interval_tree::interval<double>> vecOverlapsB;
48+
std::vector <std::pair<double, double>> vecOverlapsB;
4949
tree.overlap_find_all
5050
(
5151
{lat0, lat1},
52-
[&vecOverlapsB](lib_interval_tree::interval_tree_t<double>::iterator ittarget)
52+
[&vecOverlapsB](lib_interval_tree::interval_tree_t<double>::iterator iter)
5353
{
54-
vecOverlapsB.push_back(*ittarget);
54+
vecOverlapsB.push_back({iter->low(), iter->high()});
5555
return true;
5656
},
5757
false
5858
);
59-
60-
for (auto const& i : vecOverlapsA)
61-
{
62-
std::cout << i.low() << ", " << i.high() << "\n";
63-
}
64-
std::cout << "\n";
65-
for (auto const& i : vecOverlapsB)
66-
{
67-
std::cout << i.low() << ", " << i.high() << "\n";
68-
}
69-
70-
lib_interval_tree::drawTree("here.png", tree);
71-
72-
ASSERT_EQ(vecOverlapsA, vecOverlapsB);
59+
60+
lib_interval_tree::drawTree("here.png", tree);
61+
62+
std::sort(std::begin(vecOverlapsA), std::end(vecOverlapsA));
63+
std::sort(std::begin(vecOverlapsB), std::end(vecOverlapsB));
64+
65+
ASSERT_EQ(vecOverlapsA.size(), vecOverlapsB.size());
66+
EXPECT_THAT(vecOverlapsA, ::testing::ContainerEq(vecOverlapsB));
7367
}

tests/tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include "../interval_tree.hpp"
55
#include "typedefs.hpp"
6-
#include "example_drawings.hpp"
6+
//#include "example_drawings.hpp"
77

88
// following headers expect to be included after gtest headers and interval_tree
9+
/*
910
#include "interval_tests.hpp"
1011
#include "insert_tests.hpp"
1112
#include "erase_tests.hpp"
13+
*/
1214
#include "find_tests.hpp"
1315
#include "overlap_find_tests.hpp"
1416
#include "float_overlap_tests.hpp"

0 commit comments

Comments
 (0)