annotate UnitTestsSources/ComputationalGeometryTests.cpp @ 1875:b896f20d24ca

added UnionOfRectangles algorithm
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 19:59:40 +0100
parents 08f2476e8f5e
children b1f510e601d2
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"
1875
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
28 #include "../OrthancStone/Sources/Toolbox/UnionOfRectangles.h"
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <Logging.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <OrthancException.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
36 typedef Orthanc::SingleValueObject<int> Counter;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
37
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 class CounterFactory : public OrthancStone::SegmentTree::IPayloadFactory
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
40 private:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
41 int value_;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
42
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 public:
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
44 CounterFactory(int value) :
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
45 value_(value)
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
49 virtual Orthanc::IDynamicObject* Create() ORTHANC_OVERRIDE
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
51 return new Counter(value_);
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
55 class IncrementVisitor : public OrthancStone::SegmentTree::IVisitor
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
56 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
57 private:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
58 int increment_;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
59
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
60 public:
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
61 IncrementVisitor(int increment) :
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
62 increment_(increment)
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
66 virtual void Visit(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
67 bool fullyInside) ORTHANC_OVERRIDE
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
68 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
69 if (fullyInside)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
70 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
71 Counter& payload = node.GetTypedPayload<Counter>();
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
72
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
73 if (payload.GetValue() + increment_ < 0)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
74 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
76 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
77 else
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
78 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
79 payload.SetValue(payload.GetValue() + increment_);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
80 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
81 }
1872
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
87 TEST(SegmentTree, Create)
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
89 CounterFactory factory(42);
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 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
91
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ASSERT_EQ(4u, root.GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ASSERT_EQ(15u, root.GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ASSERT_FALSE(root.IsLeaf());
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
95 ASSERT_EQ(42, root.GetTypedPayload<Counter>().GetValue());
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 ASSERT_EQ(21u, root.CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
98 const OrthancStone::SegmentTree* n = &root.GetLeftChild();
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ASSERT_EQ(9u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 n = &root.GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 n = &root.GetLeftChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_EQ(5u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ASSERT_THROW(n->GetLeftChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_THROW(n->GetRightChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 n = &root.GetLeftChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_EQ(5u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 n = &root.GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 n = &root.GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ASSERT_EQ(7u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 n = &root.GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_EQ(8u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ(8u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 n = &root.GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 ASSERT_EQ(11u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 n = &root.GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 n = &root.GetRightChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ASSERT_EQ(10u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 n = &root.GetRightChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ASSERT_EQ(11u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_EQ(11u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 n = &root.GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 n = &root.GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_EQ(13u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 n = &root.GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 n = &root.GetRightChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ASSERT_EQ(14u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 n = &root.GetRightChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ASSERT_EQ(14u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ASSERT_EQ(1u, n->CountNodes());
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
219
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
220 ASSERT_TRUE(root.FindLeaf(3) == NULL);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
221 for (size_t i = 4; i < 15; i++)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
222 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
223 n = root.FindLeaf(i);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
224 ASSERT_TRUE(n != NULL);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
225 ASSERT_TRUE(n->IsLeaf());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
226 ASSERT_EQ(i, n->GetLowBound());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
227 ASSERT_EQ(i + 1, n->GetHighBound());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
228 ASSERT_EQ(42, n->GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
229 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
230 ASSERT_TRUE(root.FindLeaf(15) == NULL);
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
1873
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
234 static bool CheckCounter(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
235 int expectedValue)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
236 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
237 if (node.GetTypedPayload<Counter>().GetValue() != expectedValue)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
238 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
239 return false;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
240 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
241 else if (node.IsLeaf())
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
242 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
243 return true;
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
244 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
245 else
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
246 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
247 return (CheckCounter(node.GetLeftChild(), expectedValue) &&
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
248 CheckCounter(node.GetRightChild(), expectedValue));
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
253 #if 0
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
254 static void Print(const OrthancStone::SegmentTree& node,
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
255 unsigned int indent)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
256 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
257 for (size_t i = 0; i < indent; i++)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
258 printf(" ");
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
259 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
260 if (!node.IsLeaf())
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
261 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
262 Print(node.GetLeftChild(), indent + 1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
263 Print(node.GetRightChild(), indent + 1);
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 }
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
266 #endif
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
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
269 TEST(SegmentTree, Visit)
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
270 {
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
271 CounterFactory factory(0);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
272 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
273
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
274 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
275
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
276 IncrementVisitor plus(1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
277 IncrementVisitor minus(-1);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
278
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
279 root.VisitSegment(0, 20, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
280 ASSERT_EQ(1, root.GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
281 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
282 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
283
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
284 root.VisitSegment(0, 20, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
285 ASSERT_EQ(2, root.GetTypedPayload<Counter>().GetValue());
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
286 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
287 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
288
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 root.VisitSegment(0, 20, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
291 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
292
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
293 root.VisitSegment(8, 11, plus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
316 root.VisitSegment(9, 11, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
328
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
329 root.VisitSegment(8, 9, minus);
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
330 ASSERT_TRUE(CheckCounter(root, 0));
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
331 }
1874
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
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
334 TEST(UnionOfRectangles, RectanglesIntegerProjection)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
335 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
336 std::list<OrthancStone::Extent2D> rectangles;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
337 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
338
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
339 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
340 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
341 ASSERT_EQ(2u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
342 ASSERT_EQ(10, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
343 ASSERT_EQ(30, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
344 ASSERT_EQ(1u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
345 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
346 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
347
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
348 ASSERT_THROW(h.GetEndpointCoordinate(2), Orthanc::OrthancException);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
349 ASSERT_THROW(h.GetProjectedRectangleLow(1), Orthanc::OrthancException);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
350 ASSERT_THROW(h.GetProjectedRectangleHigh(1), Orthanc::OrthancException);
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 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
354 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
355 ASSERT_EQ(2u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
356 ASSERT_EQ(20, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
357 ASSERT_EQ(40, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
358 ASSERT_EQ(1u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
359 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
360 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0));
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
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
363 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
364
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
365 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
366 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
367 ASSERT_EQ(4u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
368 ASSERT_EQ(10, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
369 ASSERT_EQ(20, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
370 ASSERT_EQ(30, h.GetEndpointCoordinate(2));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
371 ASSERT_EQ(40, h.GetEndpointCoordinate(3));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
372 ASSERT_EQ(2u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
373 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
374 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
375 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
376 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1));
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 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
380 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
381 ASSERT_EQ(4u, h.GetEndpointsCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
382 ASSERT_EQ(20, h.GetEndpointCoordinate(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
383 ASSERT_EQ(30, h.GetEndpointCoordinate(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
384 ASSERT_EQ(40, h.GetEndpointCoordinate(2));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
385 ASSERT_EQ(50, h.GetEndpointCoordinate(3));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
386 ASSERT_EQ(2u, h.GetProjectedRectanglesCount());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
387 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
388 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
389 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1));
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
390 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1));
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
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
395 static void Convert(std::vector<size_t>& horizontal,
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
396 std::vector<size_t>& vertical,
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
397 const OrthancStone::Internals::OrientedIntegerLine2D::Chain& chain)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
398 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
399 horizontal.clear();
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
400 vertical.clear();
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
401
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
402 for (OrthancStone::Internals::OrientedIntegerLine2D::Chain::const_iterator
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
403 it = chain.begin(); it != chain.end(); ++it)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
404 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
405 horizontal.push_back(it->first);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
406 vertical.push_back(it->second);
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
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
411 TEST(UnionOfRectangles, ExtractChains)
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
412 {
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
413 std::vector<OrthancStone::Internals::OrientedIntegerLine2D> edges;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
414 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
415 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
416 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
417
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
418 std::list<OrthancStone::Internals::OrientedIntegerLine2D::Chain> chains;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
419 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
420
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
421 std::vector<size_t> h, v;
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
422
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
423 ASSERT_EQ(1u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
424
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
425 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
426 ASSERT_EQ(4u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
427 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
428 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
429 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
430 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
431 ASSERT_EQ(4u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
432 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
433 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
434 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
435 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
436
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
437 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
438 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
439
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
440 ASSERT_EQ(2u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
441
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
442 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
443 ASSERT_EQ(4u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
444 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
445 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
446 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
447 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
448 ASSERT_EQ(4u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
449 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
450 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
451 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
452 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
453
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
454 Convert(h, v, chains.back());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
455 ASSERT_EQ(2u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
456 ASSERT_EQ(5u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
457 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
458 ASSERT_EQ(2u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
459 ASSERT_EQ(5u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
460 ASSERT_EQ(5u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
461
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
462 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
463 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
464
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
465 ASSERT_EQ(1u, chains.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
466
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
467 Convert(h, v, chains.front());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
468 ASSERT_EQ(6u, h.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
469 ASSERT_EQ(0u, h[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
470 ASSERT_EQ(10u, h[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
471 ASSERT_EQ(10u, h[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
472 ASSERT_EQ(0u, h[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
473 ASSERT_EQ(5u, h[4]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
474 ASSERT_EQ(10u, h[5]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
475 ASSERT_EQ(6u, v.size());
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
476 ASSERT_EQ(0u, v[0]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
477 ASSERT_EQ(0u, v[1]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
478 ASSERT_EQ(20u, v[2]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
479 ASSERT_EQ(20u, v[3]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
480 ASSERT_EQ(5u, v[4]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
481 ASSERT_EQ(5u, v[5]);
08f2476e8f5e added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1873
diff changeset
482 }
1875
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
483
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
484
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
485 TEST(UnionOfRectangles, Textbook)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
486 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
487 // This is Figure 8.12 from textbook
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
488
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
489 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
490 rectangles.push_back(OrthancStone::Extent2D(1, 3, 13, 5));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
491 rectangles.push_back(OrthancStone::Extent2D(3, 1, 7, 12));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
492 rectangles.push_back(OrthancStone::Extent2D(5, 7, 11, 10));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
493 rectangles.push_back(OrthancStone::Extent2D(10, 2, 14, 8));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
494 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 3)); // empty rectangle
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
495
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
496 for (unsigned int fillHole = 0; fillHole < 2; fillHole++)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
497 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
498 if (fillHole)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
499 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
500 rectangles.push_back(OrthancStone::Extent2D(6.5, 4.5, 10.5, 7.5));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
501 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
502
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
503 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
504 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
505
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
506 ASSERT_EQ(fillHole ? 1u : 2u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
507 ASSERT_EQ(17u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
508 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 12)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
509 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 12)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
510 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 10)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
511 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(11, 10)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
512 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(11, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
513 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(14, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
514 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(14, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
515 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(10, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
516 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(10, 3)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
517 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(7, 3)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
518 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(7, 1)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
519 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(3, 1)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
520 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(3, 3)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
521 ASSERT_TRUE(contours.front()[13].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
522 ASSERT_TRUE(contours.front()[14].IsEqual(OrthancStone::ScenePoint2D(1, 5)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
523 ASSERT_TRUE(contours.front()[15].IsEqual(OrthancStone::ScenePoint2D(3, 5)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
524 ASSERT_TRUE(contours.front()[16].IsEqual(OrthancStone::ScenePoint2D(3, 12)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
525
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
526 if (!fillHole)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
527 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
528 ASSERT_EQ(5u, contours.back().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
529 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(10, 7)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
530 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(7, 7)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
531 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(7, 5)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
532 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(10, 5)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
533 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(10, 7)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
534 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
535 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
536 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
537
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
538
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
539 #if 0
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
540 static void SaveSvg(const std::list< std::vector<OrthancStone::ScenePoint2D> >& contours)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
541 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
542 float ww = 15;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
543 float hh = 13;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
544
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
545 FILE* fp = fopen("test.svg", "w");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
546 fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
547 fprintf(fp, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
548 fprintf(fp, "<svg width=\"%f\" height=\"%f\" viewBox=\"0 0 %f %f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", 100.0f*ww, 100.0f*hh, ww, hh);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
549
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
550 // http://thenewcode.com/1068/Making-Arrows-in-SVG
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
551 fprintf(fp, "<defs>\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
552 fprintf(fp, "<marker id=\"arrowhead\" markerWidth=\"2\" markerHeight=\"3\" \n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
553 fprintf(fp, "refX=\"2\" refY=\"1.5\" orient=\"auto\">\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
554 fprintf(fp, "<polygon points=\"0 0, 2 1.5, 0 3\" />\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
555 fprintf(fp, "</marker>\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
556 fprintf(fp, "</defs>\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
557
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
558 fprintf(fp, "<rect fill=\"#fff\" stroke=\"#000\" x=\"0\" y=\"0\" width=\"%f\" height=\"%f\"/>\n", ww, hh);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
559
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
560 for (std::list< std::vector<OrthancStone::ScenePoint2D> >::const_iterator
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
561 it = contours.begin(); it != contours.end(); ++it)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
562 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
563 for (size_t i = 0; i + 1 < it->size(); i++)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
564 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
565 float x1 = (*it)[i].GetX();
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
566 float x2 = (*it)[i + 1].GetX();
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
567 float y1 = (*it)[i].GetY();
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
568 float y2 = (*it)[i + 1].GetY();
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
569
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
570 fprintf(fp, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" stroke=\"blue\" stroke-width=\"0.05\" marker-end=\"url(#arrowhead)\"/>\n", x1, y1, x2, y2);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
571 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
572 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
573 fprintf(fp, "</svg>\n");
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
574
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
575 fclose(fp);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
576 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
577 #endif
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
578
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
579
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
580 TEST(UnionOfRectangles, Complex)
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
581 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
582 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
583 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
584 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
585 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
586 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 4));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
587 rectangles.push_back(OrthancStone::Extent2D(7, 4, 10, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
588
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
589 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
590 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
591
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
592 ASSERT_EQ(1u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
593 ASSERT_EQ(17u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
594 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
595 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
596 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
597 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(10, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
598 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(10, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
599 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(7, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
600 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(7, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
601 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
602 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
603 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(7, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
604 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(7, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
605 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(4, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
606 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
607 ASSERT_TRUE(contours.front()[13].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
608 ASSERT_TRUE(contours.front()[14].IsEqual(OrthancStone::ScenePoint2D(1, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
609 ASSERT_TRUE(contours.front()[15].IsEqual(OrthancStone::ScenePoint2D(4, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
610 ASSERT_TRUE(contours.front()[16].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
611 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
612
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
613 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
614 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
615 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
616 rectangles.push_back(OrthancStone::Extent2D(4, 4, 7, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
617
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
618 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
619 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
620
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
621 ASSERT_EQ(1u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
622 ASSERT_EQ(5u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
623 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
624 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
625 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
626 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
627 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
628 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
629
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
630 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
631 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
632 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
633 rectangles.push_back(OrthancStone::Extent2D(1, 6, 4, 8));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
634
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
635 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
636 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
637
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
638 ASSERT_EQ(1u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
639 ASSERT_EQ(5u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
640 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
641 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
642 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
643 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
644 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
645 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
646
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
647 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
648 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
649 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
650 rectangles.push_back(OrthancStone::Extent2D(4, 4, 7, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
651 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
652
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
653 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
654 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
655
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
656 ASSERT_EQ(2u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
657
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
658 ASSERT_EQ(5u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
659 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
660 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
661 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
662 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
663 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
664
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
665 ASSERT_EQ(5u, contours.back().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
666 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
667 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
668 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
669 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
670 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
671 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
672
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
673 #if 0
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
674 {
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
675 std::list<OrthancStone::Extent2D> rectangles;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
676 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
677 rectangles.push_back(OrthancStone::Extent2D(6, 4, 9, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
678 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
679 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 6));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
680
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
681 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
682 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
683
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
684 SaveSvg(contours);
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
685
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
686 ASSERT_EQ(1u, contours.size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
687 ASSERT_EQ(13u, contours.front().size());
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
688 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
689 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
690 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
691 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(9, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
692 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(7, 6)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
693 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
694 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
695 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
696 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
697 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
698 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
699 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
700 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D()));
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
701 }
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
702 #endif
b896f20d24ca added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1874
diff changeset
703 }