All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
SimpleGeo_test.cxx File Reference

Unit test for SimpleGeo library. More...

#include "larcorealg/Geometry/SimpleGeo.h"
#include <boost/test/unit_test.hpp>
#include <array>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   SimpleGeoTest
 

Functions

void Point2DTest ()
 
void Point3DTest ()
 
void AreaTest ()
 
void VolumeTest ()
 
 BOOST_AUTO_TEST_CASE (PointTestCase)
 
 BOOST_AUTO_TEST_CASE (AreaTestCase)
 

Detailed Description

Unit test for SimpleGeo library.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
November 11, 2016

Usage: just run the executable.

Definition in file SimpleGeo_test.cxx.

Macro Definition Documentation

#define BOOST_TEST_MODULE   SimpleGeoTest

Definition at line 12 of file SimpleGeo_test.cxx.

Function Documentation

void AreaTest ( )

Definition at line 124 of file SimpleGeo_test.cxx.

124  {
127 
128  //
129  // default constructor
130  //
131  Area_t A1;
132  BOOST_TEST(A1.Min() == Area_t::Point_t{});
133  BOOST_TEST(A1.Max() == Area_t::Point_t{});
134 
135  //
136  // point constructor
137  //
138  Area_t A2({ 1., 6.}, { 4., 2. });
139  BOOST_TEST(A2.Min() == Area_t::Point_t(1., 2.));
140  BOOST_TEST(A2.Max() == Area_t::Point_t(4., 6.));
141 
142  Area_t A3({ 1., 2.}, { 2., 2. });
143 
144  //
145  // queries
146  //
147  BOOST_TEST(A2.Center() == Area_t::Point_t(2.5, 4.0));
148 
149  BOOST_TEST(A1.DeltaX() == 0.0);
150  BOOST_TEST(A2.DeltaX() == 3.0);
151 
152  BOOST_TEST(!A1.isNullX());
153  BOOST_TEST(!A2.isNullX());
154  BOOST_TEST(!A3.isNullX());
155 
156  BOOST_TEST( A1.isEmptyX());
157  BOOST_TEST(!A2.isEmptyX());
158  BOOST_TEST(!A3.isEmptyX());
159 
160  BOOST_TEST(A1.nonEmptyDims() == 0U);
161  BOOST_TEST(A2.nonEmptyDims() == 2U);
162  BOOST_TEST(A3.nonEmptyDims() == 1U);
163 
164  BOOST_TEST(!A1.isNull());
165  BOOST_TEST(!A2.isNull());
166  BOOST_TEST(!A3.isNull());
167 
168  BOOST_TEST( A1.isEmpty());
169  BOOST_TEST(!A2.isEmpty());
170  BOOST_TEST(!A3.isEmpty());
171 
172  BOOST_TEST(!A1.isLine());
173  BOOST_TEST(!A2.isLine());
174  BOOST_TEST( A3.isLine());
175 
176  BOOST_TEST(A1.thinnestSize() == 0.0);
177  BOOST_TEST(A2.thinnestSize() == 3.0);
178  BOOST_TEST(A3.thinnestSize() == 0.0);
179 
180  BOOST_TEST(((A1.thinnestSide() == 0) || (A1.thinnestSide() == 1)));
181  BOOST_TEST(A2.thinnestSide() == 0U);
182  BOOST_TEST(A3.thinnestSide() == 1U);
183 
184  BOOST_TEST(A1.DeltaY() == 0.0);
185  BOOST_TEST(A2.DeltaY() == 4.0);
186  BOOST_TEST(A3.DeltaY() == 0.0);
187 
188  BOOST_TEST(!A1.isNullY());
189  BOOST_TEST(!A2.isNullY());
190  BOOST_TEST(!A3.isNullY());
191 
192  BOOST_TEST( A1.isEmptyY());
193  BOOST_TEST(!A2.isEmptyY());
194  BOOST_TEST( A3.isEmptyY());
195 
196  BOOST_TEST(!A1.isPlane());
197  BOOST_TEST( A2.isPlane());
198  BOOST_TEST(!A3.isPlane());
199 
200  //
201  // modifications
202  //
203  BOOST_TEST(A3 == Area_t({ 1.0, 2.0 }, { 2.0, 2.0 }));
204  BOOST_TEST(A3 != A2);
205  A3.Intersect(A2);
206  BOOST_TEST(A3 == Area_t({ 1.0, 2.0 }, { 2.0, 2.0 }));
207 
208  A3.IncludePoint({ 1.5, 6.0 });
209  BOOST_TEST(A3 == Area_t({ 1.0, 2.0 }, { 2.0, 6.0 }));
210  A3.IncludePoint({ 4.0, 5.0 });
211  BOOST_TEST(A3 == Area_t({ 1.0, 2.0 }, { 4.0, 6.0 }));
212  BOOST_TEST(A3 == A2);
213 
214  A3.Intersect(A2);
215  BOOST_TEST(A3 == Area_t({ 1.0, 2.0 }, { 4.0, 6.0 }));
216 
217  A3.IncludePoint({ 0.0, 4.0 });
218  BOOST_TEST(A3 == Area_t({ 0.0, 2.0 }, { 4.0, 6.0 }));
219 
220  A3.Include(Area_t({ 1.0, -1.0 }, { 2.0, 7.0 }));
221  BOOST_TEST(A3 == Area_t({ 0.0, -1.0 }, { 4.0, 7.0 }));
222 
223  A3.Include(Area_t({ -1.0, 0.0 }, { 3.0, 1.0 }));
224  BOOST_TEST(A3 == Area_t({ -1.0, -1.0 }, { 4.0, 7.0 }));
225 
226  // intersection result is empty
227  BOOST_CHECK_THROW(
228  A3.Intersect(Area_t({ 8.0, 9.0 }, { 8.0, 9.0 })),
229  Area_t::NullIntersection
230  );
231  BOOST_TEST(A3.isNull());
232 
233 } // AreaTest()
2D point (x, y) (by default, with double precision)
Definition: SimpleGeo.h:52
recob::tracking::Point_t Point_t
Area delimited by two points.
Definition: SimpleGeo.h:201
BOOST_AUTO_TEST_CASE ( PointTestCase  )

Definition at line 394 of file SimpleGeo_test.cxx.

395 {
396  Point2DTest();
397  Point3DTest();
398 }
void Point3DTest()
void Point2DTest()
BOOST_AUTO_TEST_CASE ( AreaTestCase  )

Definition at line 400 of file SimpleGeo_test.cxx.

401 {
402  AreaTest();
403  VolumeTest();
404 }
void AreaTest()
void VolumeTest()
void Point2DTest ( )

Definition at line 25 of file SimpleGeo_test.cxx.

25  {
26 
28 
29  // BUG the double brace syntax is required to work around clang bug 21629
30  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
31  std::array<Point_t::Data_t, 2U> buffer = {{ 1., 2. }};
32 
33  //
34  // default constructor
35  //
36  Point_t p1;
37  BOOST_TEST(p1.x == 0.);
38  BOOST_TEST(p1.y == 0.);
39 
40  //
41  // element constructor
42  //
43  Point_t p2(1., 2.);
44  BOOST_TEST(p2.x == 1.);
45  BOOST_TEST(p2.y == 2.);
46 
47  //
48  // data buffer constructor
49  //
50  Point_t p3(buffer.data());
51  BOOST_TEST(p3.x == 1.);
52  BOOST_TEST(p3.y == 2.);
53 
54  //
55  // implicit comparisons
56  //
57  BOOST_TEST(p2 == p3);
58  BOOST_TEST(p1 != p2);
59 
60  //
61  // arithmetic operations
62  //
63  Point_t p4 { 2., 4. };
64  BOOST_TEST(p1 + p2 == p2);
65  BOOST_TEST(p2 + p1 == p2);
66  BOOST_TEST(p1 * 2. == p1);
67  BOOST_TEST(p2 * 2.0 == p4);
68  BOOST_TEST(p2 / 0.5 == p4);
69 
70 } // Point2DTest()
2D point (x, y) (by default, with double precision)
Definition: SimpleGeo.h:52
recob::tracking::Point_t Point_t
physics associatedGroupsWithLeft p1
void Point3DTest ( )

Definition at line 73 of file SimpleGeo_test.cxx.

73  {
74 
76 
77  // BUG the double brace syntax is required to work around clang bug 21629
78  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
79  std::array<Point_t::Data_t, 3U> buffer = {{ 1., 2., 4. }};
80 
81  //
82  // default constructor
83  //
84  Point_t p1;
85  BOOST_TEST(p1.x == 0.);
86  BOOST_TEST(p1.y == 0.);
87  BOOST_TEST(p1.z == 0.);
88 
89  //
90  // element constructor
91  //
92  Point_t p2(1., 2., 4.);
93  BOOST_TEST(p2.x == 1.);
94  BOOST_TEST(p2.y == 2.);
95  BOOST_TEST(p2.z == 4.);
96 
97  //
98  // data buffer constructor
99  //
100  Point_t p3(buffer.data());
101  BOOST_TEST(p3.x == 1.);
102  BOOST_TEST(p3.y == 2.);
103  BOOST_TEST(p2.z == 4.);
104 
105  //
106  // implicit comparisons
107  //
108  BOOST_TEST(p2 == p3);
109  BOOST_TEST(p1 != p2);
110 
111  //
112  // arithmetic operations
113  //
114  Point_t p4 { 2., 4., 8. };
115  BOOST_TEST(p1 + p2 == p2);
116  BOOST_TEST(p2 + p1 == p2);
117  BOOST_TEST(p1 * 2. == p1);
118  BOOST_TEST(p2 * 2.0 == p4);
119  BOOST_TEST(p2 / 0.5 == p4);
120 
121 } // Point3DTest()
recob::tracking::Point_t Point_t
3D point (x, y, z) (by default, with double precision)
Definition: SimpleGeo.h:85
physics associatedGroupsWithLeft p1
void VolumeTest ( )

Definition at line 237 of file SimpleGeo_test.cxx.

237  {
240 
241  //
242  // default constructor
243  //
244  Volume_t A1;
245  BOOST_TEST(A1.Min() == Volume_t::Point_t{});
246  BOOST_TEST(A1.Max() == Volume_t::Point_t{});
247 
248  //
249  // point constructor
250  //
251  Volume_t A2({ 1., 6., 4.}, { 4., 2., 8. });
252  BOOST_TEST(A2.Min() == Volume_t::Point_t(1., 2., 4.));
253  BOOST_TEST(A2.Max() == Volume_t::Point_t(4., 6., 8.));
254 
255  Volume_t A3({ 1., 2., 3.}, { 2., 2., 6. });
256  Volume_t A4({ 2., 3., 3.}, { 2., 2., 3. });
257 
258 
259  //
260  // queries
261  //
262  BOOST_TEST(A2.Center() == Volume_t::Point_t(2.5, 4.0, 6.0));
263 
264  BOOST_TEST(A1.DeltaX() == 0.0);
265  BOOST_TEST(A2.DeltaX() == 3.0);
266  BOOST_TEST(A3.DeltaX() == 1.0);
267  BOOST_TEST(A4.DeltaX() == 0.0);
268 
269  BOOST_TEST(!A1.isNullX());
270  BOOST_TEST(!A2.isNullX());
271  BOOST_TEST(!A3.isNullX());
272  BOOST_TEST(!A4.isNullX());
273 
274  BOOST_TEST( A1.isEmptyX());
275  BOOST_TEST(!A2.isEmptyX());
276  BOOST_TEST(!A3.isEmptyX());
277  BOOST_TEST( A4.isEmptyX());
278 
279  BOOST_TEST(A1.nonEmptyDims() == 0U);
280  BOOST_TEST(A2.nonEmptyDims() == 3U);
281  BOOST_TEST(A3.nonEmptyDims() == 2U);
282  BOOST_TEST(A4.nonEmptyDims() == 1U);
283 
284  BOOST_TEST(!A1.isNull());
285  BOOST_TEST(!A2.isNull());
286  BOOST_TEST(!A3.isNull());
287  BOOST_TEST(!A4.isNull());
288 
289  BOOST_TEST( A1.isEmpty());
290  BOOST_TEST(!A2.isEmpty());
291  BOOST_TEST(!A3.isEmpty());
292  BOOST_TEST(!A4.isEmpty());
293 
294  BOOST_TEST(!A1.isLine());
295  BOOST_TEST(!A2.isLine());
296  BOOST_TEST(!A3.isLine());
297  BOOST_TEST( A4.isLine());
298 
299  BOOST_TEST(A1.thinnestSize() == 0.0);
300  BOOST_TEST(A2.thinnestSize() == 3.0);
301  BOOST_TEST(A3.thinnestSize() == 0.0);
302  BOOST_TEST(A4.thinnestSize() == 0.0);
303 
304  BOOST_TEST((
305  (A1.thinnestSide() == 0)
306  || (A1.thinnestSide() == 1)
307  || (A1.thinnestSide() == 2)
308  ));
309  BOOST_TEST(A2.thinnestSide() == 0U);
310  BOOST_TEST(A3.thinnestSide() == 1U);
311  BOOST_TEST(((A4.thinnestSide() == 0) || (A4.thinnestSide() == 2)));
312 
313  BOOST_TEST(A1.DeltaY() == 0.0);
314  BOOST_TEST(A2.DeltaY() == 4.0);
315  BOOST_TEST(A3.DeltaY() == 0.0);
316  BOOST_TEST(A4.DeltaY() == 1.0);
317 
318  BOOST_TEST(!A1.isNullY());
319  BOOST_TEST(!A2.isNullY());
320  BOOST_TEST(!A3.isNullY());
321  BOOST_TEST(!A4.isNullY());
322 
323  BOOST_TEST( A1.isEmptyY());
324  BOOST_TEST(!A2.isEmptyY());
325  BOOST_TEST( A3.isEmptyY());
326  BOOST_TEST(!A4.isEmptyY());
327 
328  BOOST_TEST(!A1.isPlane());
329  BOOST_TEST(!A2.isPlane());
330  BOOST_TEST( A3.isPlane());
331  BOOST_TEST(!A4.isPlane());
332 
333  BOOST_TEST(A1.DeltaZ() == 0.0);
334  BOOST_TEST(A2.DeltaZ() == 4.0);
335  BOOST_TEST(A3.DeltaZ() == 3.0);
336  BOOST_TEST(A4.DeltaZ() == 0.0);
337 
338  BOOST_TEST(!A1.isNullZ());
339  BOOST_TEST(!A2.isNullZ());
340  BOOST_TEST(!A3.isNullZ());
341  BOOST_TEST(!A4.isNullZ());
342 
343  BOOST_TEST( A1.isEmptyZ());
344  BOOST_TEST(!A2.isEmptyZ());
345  BOOST_TEST(!A3.isEmptyZ());
346  BOOST_TEST( A4.isEmptyZ());
347 
348  BOOST_TEST(!A1.isVolume());
349  BOOST_TEST( A2.isVolume());
350  BOOST_TEST(!A3.isVolume());
351  BOOST_TEST(!A4.isVolume());
352 
353  //
354  // modifications
355  //
356  BOOST_TEST(A3 == Volume_t({ 1.0, 2.0, 3.0 }, { 2.0, 2.0, 6.0 }));
357  BOOST_TEST(A2 == Volume_t({ 1.0, 2.0, 4.0 }, { 4.0, 6.0, 8.0 }));
358  BOOST_TEST(A3 != A2);
359  A3.Intersect(A2);
360  BOOST_TEST(A3 == Volume_t({ 1.0, 2.0, 4.0 }, { 2.0, 2.0, 6.0 }));
361 
362  A3.IncludePoint({ 1.5, 6.0, 4.0 });
363  BOOST_TEST(A3 == Volume_t({ 1.0, 2.0, 4.0 }, { 2.0, 6.0, 6.0 }));
364  A3.IncludePoint({ 4.0, 5.0, 8.0 });
365  BOOST_TEST(A3 == Volume_t({ 1.0, 2.0, 4.0 }, { 4.0, 6.0, 8.0 }));
366  BOOST_TEST(A3 == A2);
367 
368  A3.Intersect(A2);
369  BOOST_TEST(A3 == Volume_t({ 1.0, 2.0, 4.0 }, { 4.0, 6.0, 8.0 }));
370 
371  A3.IncludePoint({ 0.0, 4.0, 4.0 });
372  BOOST_TEST(A3 == Volume_t({ 0.0, 2.0, 4.0 }, { 4.0, 6.0, 8.0 }));
373 
374  A3.Include(Volume_t({ 1.0, -1.0, 3.0 }, { 2.0, 7.0, 7.0 }));
375  BOOST_TEST(A3 == Volume_t({ 0.0, -1.0, 3.0 }, { 4.0, 7.0, 8.0 }));
376 
377  A3.Include(Volume_t({ -1.0, 0.0, 2.0 }, { 3.0, 1.0, 6.0 }));
378  BOOST_TEST(A3 == Volume_t({ -1.0, -1.0, 2.0 }, { 4.0, 7.0, 8.0 }));
379 
380  // intersection result is empty
381  BOOST_CHECK_THROW(
382  A3.Intersect(Volume_t({ 8.0, 9.0, 2.0 }, { 8.0, 9.0, 3.0 })),
383  Volume_t::NullIntersection
384  );
385  BOOST_TEST(A3.isNull());
386 
387 
388 } // VolumeTest()
Volume delimited by two points.
Definition: SimpleGeo.h:261
recob::tracking::Point_t Point_t
3D point (x, y, z) (by default, with double precision)
Definition: SimpleGeo.h:85