annotate UnitTestsSources/ComputationalGeometryTests.cpp @ 1874:08f2476e8f5e

added classes OrientedIntegerLine2D and RectanglesIntegerProjection
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 18:58:37 +0100
parents e0966648ebd0
children b896f20d24ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include <gtest/gtest.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1874
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
25 #include "../OrthancStone/Sources/Toolbox/Internals/OrientedIntegerLine2D.h"
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
26 #include "../OrthancStone/Sources/Toolbox/Internals/RectanglesIntegerProjection.h"
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../OrthancStone/Sources/Toolbox/SegmentTree.h"
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <Logging.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <OrthancException.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
35 typedef Orthanc::SingleValueObject<int> Counter;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
36
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 class CounterFactory : public OrthancStone::SegmentTree::IPayloadFactory
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
39 private:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
40 int value_;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
41
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 public:
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
43 CounterFactory(int value) :
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
44 value_(value)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
45 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
46 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
47
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
48 virtual Orthanc::IDynamicObject* Create() ORTHANC_OVERRIDE
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
50 return new Counter(value_);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
51 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
52 };
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
53
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
54 class IncrementVisitor : public OrthancStone::SegmentTree::IVisitor
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
55 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
56 private:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
57 int increment_;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
58
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
59 public:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
60 IncrementVisitor(int increment) :
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
61 increment_(increment)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
62 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
63 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
64
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
65 virtual void Visit(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
66 bool fullyInside) ORTHANC_OVERRIDE
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
67 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
68 if (fullyInside)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
69 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
70 Counter& payload = node.GetTypedPayload<Counter>();
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
71
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
72 if (payload.GetValue() + increment_ < 0)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
73 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
75 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
76 else
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
77 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
78 payload.SetValue(payload.GetValue() + increment_);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
79 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
80 }
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 };
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
86 TEST(SegmentTree, Create)
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
88 CounterFactory factory(42);
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 OrthancStone::SegmentTree root(4u, 15u, factory); // Check out Figure 1.1 (page 14) from textbook
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ASSERT_EQ(4u, root.GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ASSERT_EQ(15u, root.GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ASSERT_FALSE(root.IsLeaf());
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
94 ASSERT_EQ(42, root.GetTypedPayload<Counter>().GetValue());
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ASSERT_EQ(21u, root.CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
97 const OrthancStone::SegmentTree* n = &root.GetLeftChild();
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_EQ(9u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 n = &root.GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 n = &root.GetLeftChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_EQ(5u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ASSERT_THROW(n->GetLeftChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ASSERT_THROW(n->GetRightChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 n = &root.GetLeftChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 ASSERT_EQ(5u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 n = &root.GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 n = &root.GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ASSERT_EQ(7u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 n = &root.GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ASSERT_EQ(8u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ASSERT_EQ(8u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 n = &root.GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ASSERT_EQ(11u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 n = &root.GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 n = &root.GetRightChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ASSERT_EQ(10u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 n = &root.GetRightChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ASSERT_EQ(11u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_EQ(11u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 n = &root.GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 n = &root.GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ASSERT_EQ(13u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 n = &root.GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 n = &root.GetRightChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ASSERT_EQ(14u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 n = &root.GetRightChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 ASSERT_EQ(14u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ASSERT_EQ(1u, n->CountNodes());
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
218
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
219 ASSERT_TRUE(root.FindLeaf(3) == NULL);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
220 for (size_t i = 4; i < 15; i++)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
221 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
222 n = root.FindLeaf(i);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
223 ASSERT_TRUE(n != NULL);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
224 ASSERT_TRUE(n->IsLeaf());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
225 ASSERT_EQ(i, n->GetLowBound());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
226 ASSERT_EQ(i + 1, n->GetHighBound());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
227 ASSERT_EQ(42, n->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
228 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
229 ASSERT_TRUE(root.FindLeaf(15) == NULL);
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
231
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
232
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
233 static bool CheckCounter(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
234 int expectedValue)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
235 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
236 if (node.GetTypedPayload<Counter>().GetValue() != expectedValue)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
237 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
238 return false;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
239 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
240 else if (node.IsLeaf())
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
241 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
242 return true;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
243 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
244 else
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
245 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
246 return (CheckCounter(node.GetLeftChild(), expectedValue) &&
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
247 CheckCounter(node.GetRightChild(), expectedValue));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
248 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
249 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
250
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
251
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
252 #if 0
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
253 static void Print(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
254 unsigned int indent)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
255 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
256 for (size_t i = 0; i < indent; i++)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
257 printf(" ");
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
258 printf("(%lu,%lu): %d\n", node.GetLowBound(), node.GetHighBound(), node.GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
259 if (!node.IsLeaf())
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
260 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
261 Print(node.GetLeftChild(), indent + 1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
262 Print(node.GetRightChild(), indent + 1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
263 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
264 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
265 #endif
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
266
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
267
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
268 TEST(SegmentTree, Visit)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
269 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
270 CounterFactory factory(0);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
271 OrthancStone::SegmentTree root(4u, 15u, factory); // Check out Figure 1.1 (page 14) from textbook
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
272
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
273 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
274
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
275 IncrementVisitor plus(1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
276 IncrementVisitor minus(-1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
277
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
278 root.VisitSegment(0, 20, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
279 ASSERT_EQ(1, root.GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
280 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
281 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
282
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
283 root.VisitSegment(0, 20, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
284 ASSERT_EQ(2, root.GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
285 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
286 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
287
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
288 root.VisitSegment(0, 20, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
289 root.VisitSegment(0, 20, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
290 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
291
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
292 root.VisitSegment(8, 11, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
293 ASSERT_EQ(0, root.FindNode(4, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
294 ASSERT_EQ(0, root.FindNode(4, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
295 ASSERT_EQ(0, root.FindNode(4, 6)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
296 ASSERT_EQ(0, root.FindNode(4, 5)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
297 ASSERT_EQ(0, root.FindNode(5, 6)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
298 ASSERT_EQ(0, root.FindNode(6, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
299 ASSERT_EQ(0, root.FindNode(6, 7)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
300 ASSERT_EQ(0, root.FindNode(7, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
301 ASSERT_EQ(0, root.FindNode(7, 8)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
302 ASSERT_EQ(1, root.FindNode(8, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
303 ASSERT_EQ(0, root.FindNode(9, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
304 ASSERT_EQ(0, root.FindNode(9, 12)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
305 ASSERT_EQ(1, root.FindNode(9, 10)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
306 ASSERT_EQ(0, root.FindNode(10, 12)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
307 ASSERT_EQ(1, root.FindNode(10, 11)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
308 ASSERT_EQ(0, root.FindNode(11, 12)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
309 ASSERT_EQ(0, root.FindNode(12, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
310 ASSERT_EQ(0, root.FindNode(12, 13)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
311 ASSERT_EQ(0, root.FindNode(13, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
312 ASSERT_EQ(0, root.FindNode(13, 14)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
313 ASSERT_EQ(0, root.FindNode(14, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
314
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
315 root.VisitSegment(9, 11, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
316 ASSERT_EQ(0, root.FindNode(4, 15)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
317 ASSERT_EQ(0, root.FindNode(4, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
318 ASSERT_EQ(0, root.FindNode(4, 6)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
319 ASSERT_EQ(0, root.FindNode(4, 5)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
320 ASSERT_EQ(0, root.FindNode(5, 6)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
321 ASSERT_EQ(0, root.FindNode(6, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
322 ASSERT_EQ(0, root.FindNode(6, 7)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
323 ASSERT_EQ(0, root.FindNode(7, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
324 ASSERT_EQ(0, root.FindNode(7, 8)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
325 ASSERT_EQ(1, root.FindNode(8, 9)->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
326 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
327
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
328 root.VisitSegment(8, 9, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
329 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
330 }
1874
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
331
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
332
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
333 TEST(UnionOfRectangles, RectanglesIntegerProjection)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
334 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
335 std::list<OrthancStone::Extent2D> rectangles;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
336 rectangles.push_back(OrthancStone::Extent2D(10, 20, 30, 40));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
337
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
338 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
339 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
340 ASSERT_EQ(2u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
341 ASSERT_EQ(10, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
342 ASSERT_EQ(30, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
343 ASSERT_EQ(1u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
344 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
345 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
346
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
347 ASSERT_THROW(h.GetEndpointCoordinate(2), Orthanc::OrthancException);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
348 ASSERT_THROW(h.GetProjectedRectangleLow(1), Orthanc::OrthancException);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
349 ASSERT_THROW(h.GetProjectedRectangleHigh(1), Orthanc::OrthancException);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
350 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
351
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
352 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
353 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
354 ASSERT_EQ(2u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
355 ASSERT_EQ(20, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
356 ASSERT_EQ(40, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
357 ASSERT_EQ(1u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
358 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
359 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
360 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
361
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
362 rectangles.push_back(OrthancStone::Extent2D(20, 30, 40, 50));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
363
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
364 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
365 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
366 ASSERT_EQ(4u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
367 ASSERT_EQ(10, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
368 ASSERT_EQ(20, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
369 ASSERT_EQ(30, h.GetEndpointCoordinate(2));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
370 ASSERT_EQ(40, h.GetEndpointCoordinate(3));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
371 ASSERT_EQ(2u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
372 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
373 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
374 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
375 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
376 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
377
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
378 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
379 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
380 ASSERT_EQ(4u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
381 ASSERT_EQ(20, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
382 ASSERT_EQ(30, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
383 ASSERT_EQ(40, h.GetEndpointCoordinate(2));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
384 ASSERT_EQ(50, h.GetEndpointCoordinate(3));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
385 ASSERT_EQ(2u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
386 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
387 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
388 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
389 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
390 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
391 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
392
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
393
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
394 static void Convert(std::vector<size_t>& horizontal,
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
395 std::vector<size_t>& vertical,
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
396 const OrthancStone::Internals::OrientedIntegerLine2D::Chain& chain)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
397 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
398 horizontal.clear();
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
399 vertical.clear();
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
400
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
401 for (OrthancStone::Internals::OrientedIntegerLine2D::Chain::const_iterator
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
402 it = chain.begin(); it != chain.end(); ++it)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
403 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
404 horizontal.push_back(it->first);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
405 vertical.push_back(it->second);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
406 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
407 }
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
408
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
409
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
410 TEST(UnionOfRectangles, ExtractChains)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
411 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
412 std::vector<OrthancStone::Internals::OrientedIntegerLine2D> edges;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
413 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(0, 0, 10, 0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
414 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(10, 0, 10, 20));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
415 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(10, 20, 0, 20));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
416
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
417 std::list<OrthancStone::Internals::OrientedIntegerLine2D::Chain> chains;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
418 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
419
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
420 std::vector<size_t> h, v;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
421
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
422 ASSERT_EQ(1u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
423
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
424 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
425 ASSERT_EQ(4u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
426 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
427 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
428 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
429 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
430 ASSERT_EQ(4u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
431 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
432 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
433 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
434 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
435
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
436 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(5, 5, 10, 5));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
437 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
438
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
439 ASSERT_EQ(2u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
440
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
441 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
442 ASSERT_EQ(4u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
443 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
444 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
445 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
446 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
447 ASSERT_EQ(4u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
448 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
449 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
450 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
451 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
452
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
453 Convert(h, v, chains.back());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
454 ASSERT_EQ(2u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
455 ASSERT_EQ(5u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
456 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
457 ASSERT_EQ(2u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
458 ASSERT_EQ(5u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
459 ASSERT_EQ(5u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
460
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
461 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(0, 20, 5, 5));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
462 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
463
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
464 ASSERT_EQ(1u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
465
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
466 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
467 ASSERT_EQ(6u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
468 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
469 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
470 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
471 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
472 ASSERT_EQ(5u, h[4]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
473 ASSERT_EQ(10u, h[5]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
474 ASSERT_EQ(6u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
475 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
476 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
477 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
478 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
479 ASSERT_EQ(5u, v[4]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
480 ASSERT_EQ(5u, v[5]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
481 }