9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
25 using namespace UnitLiterals;
37 BOOST_AUTO_TEST_SUITE(Surfaces)
51 auto lTransform = transform.linear();
55 Vector3D outCylinder = transform *
Vector3D(-radius, 0.6 * radius, 90_cm);
56 Vector3D atCenter = transform *
Vector3D(0., 0., 0.);
57 Vector3D atEdge = transform *
Vector3D(0.5 * radius, 0., 0.99 * halfZ);
59 Vector3D alongX = lTransform *
Vector3D(1., 0., 0.);
60 Vector3D transXY = lTransform *
Vector3D(1., 1., 0).normalized();
61 Vector3D transTZ = lTransform *
Vector3D(1., 0., 1.).normalized();
68 BOOST_CHECK(aIntersection);
70 BOOST_CHECK(aIntersection.intersection.status ==
71 Intersection3D::Status::onSurface);
73 BOOST_CHECK(aIntersection.alternative);
75 BOOST_CHECK(aIntersection.alternative.status ==
76 Intersection3D::Status::reachable);
86 BOOST_CHECK(cIntersection);
88 BOOST_CHECK(cIntersection.intersection.status ==
89 Intersection3D::Status::reachable);
91 BOOST_CHECK(cIntersection.alternative);
93 BOOST_CHECK(cIntersection.alternative.status ==
94 Intersection3D::Status::reachable);
96 BOOST_CHECK(cIntersection.alternative.pathLength *
97 cIntersection.intersection.pathLength <
105 BOOST_CHECK(oIntersection);
107 BOOST_CHECK(oIntersection.intersection.status ==
108 Intersection3D::Status::reachable);
110 BOOST_CHECK(oIntersection.alternative);
112 BOOST_CHECK(oIntersection.alternative.status ==
113 Intersection3D::Status::reachable);
115 BOOST_CHECK(oIntersection.alternative.pathLength *
116 oIntersection.intersection.pathLength >
124 BOOST_CHECK(!iIntersection);
131 BOOST_CHECK(eIntersection);
133 BOOST_CHECK(eIntersection.intersection.pathLength > 0.);
135 BOOST_CHECK(eIntersection.intersection.status ==
136 Intersection3D::Status::reachable);
138 BOOST_CHECK(eIntersection.alternative);
140 BOOST_CHECK(eIntersection.alternative.status ==
141 Intersection3D::Status::reachable);
143 BOOST_CHECK(eIntersection.alternative.pathLength < 0.);
148 BOOST_CHECK(eIntersection.intersection.pathLength < 0.);
150 BOOST_CHECK(eIntersection.intersection.status ==
151 Intersection3D::Status::reachable);
153 BOOST_CHECK(!eIntersection.alternative);
155 BOOST_CHECK(eIntersection.alternative.status ==
156 Intersection3D::Status::missed);
158 BOOST_CHECK(eIntersection.alternative.pathLength > 0.);
162 testCylinderIntersection(Transform3D::Identity());
175 auto aCone = Surface::makeShared<ConeSurface>(
transform,
alpha,
true);
178 auto lTransform = transform.linear();
182 Vector3D outCone = transform *
Vector3D(std::sqrt(4.), std::sqrt(4.), 2.);
184 Vector3D perpXY = lTransform *
Vector3D(1., -1., 0.).normalized();
185 Vector3D transXY = lTransform *
Vector3D(1., 1., 0).normalized();
188 BOOST_CHECK(aCone->isOnSurface(
tgContext, onCone, transXY,
false));
189 auto aIntersection = aCone->intersect(
tgContext, onCone, transXY,
true);
192 BOOST_CHECK(aIntersection);
194 BOOST_CHECK(aIntersection.intersection.status ==
195 Intersection3D::Status::onSurface);
198 BOOST_CHECK(aIntersection.alternative);
200 BOOST_CHECK(aIntersection.alternative.status ==
201 Intersection3D::Status::reachable);
207 auto iIntersection = aCone->intersect(
tgContext, outCone, perpXY,
false);
210 BOOST_CHECK(!iIntersection);
214 testConeIntersection(Transform3D::Identity());
230 auto aPlane = Surface::makeShared<PlaneSurface>(
235 Vector3D onit = transform *
Vector3D(11_cm, -22_cm, 0_m);
236 Vector3D after = transform *
Vector3D(33_cm, 12_mm, 1_m);
237 Vector3D outside = transform *
Vector3D(2. * halfX, 2 * halfY, -1_mm);
240 auto lTransform = transform.linear();
243 Vector3D direction = lTransform *
Vector3D(4_mm, 8_mm, 50_cm).normalized();
244 Vector3D parallel = lTransform *
Vector3D(1., 1., 0.).normalized();
247 auto fIntersection =
aPlane->intersect(
tgContext, before, direction,
true);
250 BOOST_CHECK(fIntersection);
252 BOOST_CHECK(fIntersection.intersection.status ==
253 Intersection3D::Status::reachable);
255 BOOST_CHECK(fIntersection.intersection.pathLength > 0.);
257 BOOST_CHECK(!fIntersection.alternative);
260 auto oIntersection =
aPlane->intersect(
tgContext, onit, direction,
true);
262 BOOST_CHECK(oIntersection);
264 BOOST_CHECK(oIntersection.intersection.status ==
265 Intersection3D::Status::onSurface);
267 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
270 BOOST_CHECK(!oIntersection.alternative);
273 auto bIntersection =
aPlane->intersect(
tgContext, after, direction,
true);
275 BOOST_CHECK(bIntersection);
277 BOOST_CHECK(bIntersection.intersection.status ==
278 Intersection3D::Status::reachable);
280 BOOST_CHECK(bIntersection.intersection.pathLength < 0.);
282 BOOST_CHECK(!bIntersection.alternative);
285 auto mIntersection =
aPlane->intersect(
tgContext, outside, direction,
true);
287 BOOST_CHECK(!mIntersection);
289 BOOST_CHECK(mIntersection.intersection.status ==
290 Intersection3D::Status::missed);
292 BOOST_CHECK(mIntersection.intersection.pathLength > 0.);
294 BOOST_CHECK(!mIntersection.alternative);
297 auto iIntersection =
aPlane->intersect(
tgContext, before, parallel,
true);
299 BOOST_CHECK(!iIntersection);
301 BOOST_CHECK(iIntersection.intersection.status ==
302 Intersection3D::Status::unreachable);
304 BOOST_CHECK(!iIntersection.alternative);
308 testPlanarIntersection(Transform3D::Identity());
324 auto aLine = Surface::makeShared<StrawSurface>(
transform,
radius, halfZ);
328 Vector3D onit1 = transform *
Vector3D(0_m, 0_m, 0_m);
329 Vector3D onitP = transform *
Vector3D(1_cm, 0_m, 23_um);
330 Vector3D after = transform *
Vector3D(33_cm, 12_mm, 1_m);
331 Vector3D outside = transform *
Vector3D(2., 0., 100_m);
334 auto lTransform = transform.linear();
335 Vector3D direction = lTransform *
Vector3D(2_cm, 3_cm, 5_cm).normalized();
336 Vector3D normalP = lTransform *
Vector3D(0, 1., 0.).normalized();
337 Vector3D parallel = lTransform *
Vector3D(0, 0., 1.).normalized();
341 auto fIntersection = aLine->intersect(
tgContext, before, direction,
true);
343 BOOST_CHECK(fIntersection);
345 BOOST_CHECK(fIntersection.intersection.status ==
346 Intersection3D::Status::reachable);
348 BOOST_CHECK(fIntersection.intersection.pathLength > 0.);
350 BOOST_CHECK(!fIntersection.alternative);
353 auto oIntersection = aLine->intersect(
tgContext, onit1, direction,
true);
355 BOOST_CHECK(oIntersection);
357 BOOST_CHECK(oIntersection.intersection.status ==
358 Intersection3D::Status::onSurface);
360 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
363 BOOST_CHECK(!oIntersection.alternative);
366 oIntersection = aLine->intersect(
tgContext, onitP, normalP,
true);
368 BOOST_CHECK(oIntersection);
370 BOOST_CHECK(oIntersection.intersection.status ==
371 Intersection3D::Status::onSurface);
373 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
376 BOOST_CHECK(!oIntersection.alternative);
379 auto bIntersection = aLine->intersect(
tgContext, after, direction,
true);
381 BOOST_CHECK(bIntersection);
383 BOOST_CHECK(bIntersection.intersection.status ==
384 Intersection3D::Status::reachable);
386 BOOST_CHECK(bIntersection.intersection.pathLength < 0.);
388 BOOST_CHECK(!bIntersection.alternative);
391 auto mIntersection = aLine->intersect(
tgContext, outside, direction,
true);
393 BOOST_CHECK(!mIntersection);
395 BOOST_CHECK(mIntersection.intersection.status ==
396 Intersection3D::Status::missed);
398 BOOST_CHECK(mIntersection.intersection.pathLength < 0.);
400 BOOST_CHECK(!mIntersection.alternative);
403 auto iIntersection = aLine->intersect(
tgContext, before, parallel,
true);
405 BOOST_CHECK(!iIntersection);
407 BOOST_CHECK(iIntersection.intersection.status ==
408 Intersection3D::Status::unreachable);
410 BOOST_CHECK(!iIntersection.alternative);
414 testLineAppraoch(Transform3D::Identity());
420 BOOST_AUTO_TEST_SUITE_END()