9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
32 using namespace UnitLiterals;
44 BOOST_AUTO_TEST_SUITE(Surfaces)
55 Surface::makeShared<CylinderSurface>(
transform, radius, halfZ);
58 auto lTransform = transform.linear();
62 Vector3 outCylinder = transform *
Vector3(-radius, 0.6 * radius, 90_cm);
63 Vector3 atCenter = transform *
Vector3(0., 0., 0.);
64 Vector3 atEdge = transform *
Vector3(0.5 * radius, 0., 0.99 * halfZ);
66 Vector3 alongX = lTransform *
Vector3(1., 0., 0.);
67 Vector3 transXY = lTransform *
Vector3(1., 1., 0).normalized();
68 Vector3 transTZ = lTransform *
Vector3(1., 0., 1.).normalized();
75 BOOST_CHECK(aIntersection[0]);
77 BOOST_CHECK(aIntersection[0].
status() == Intersection3D::Status::reachable);
81 BOOST_CHECK(aIntersection[1]);
83 BOOST_CHECK(aIntersection[1].
status() == Intersection3D::Status::onSurface);
90 BOOST_CHECK(cIntersection[0]);
92 BOOST_CHECK(cIntersection[0].
status() == Intersection3D::Status::reachable);
94 BOOST_CHECK(cIntersection[1]);
96 BOOST_CHECK(cIntersection[1].
status() == Intersection3D::Status::reachable);
106 BOOST_CHECK(oIntersection[0]);
108 BOOST_CHECK(oIntersection[0].
status() == Intersection3D::Status::reachable);
110 BOOST_CHECK(oIntersection[1]);
112 BOOST_CHECK(oIntersection[1].
status() == Intersection3D::Status::reachable);
122 BOOST_CHECK(!iIntersection[0]);
129 BOOST_CHECK(eIntersection[0]);
131 BOOST_CHECK(eIntersection[0].
pathLength() < 0.);
133 BOOST_CHECK(eIntersection[0].
status() == Intersection3D::Status::reachable);
135 BOOST_CHECK(eIntersection[1]);
137 BOOST_CHECK(eIntersection[1].
status() == Intersection3D::Status::reachable);
139 BOOST_CHECK(eIntersection[1].
pathLength() > 0.);
144 BOOST_CHECK(eIntersection[0].
pathLength() < 0.);
146 BOOST_CHECK(eIntersection[0].
status() == Intersection3D::Status::reachable);
148 BOOST_CHECK(!eIntersection[1]);
150 BOOST_CHECK(eIntersection[1].
status() == Intersection3D::Status::missed);
152 BOOST_CHECK(eIntersection[1].
pathLength() > 0.);
156 testCylinderIntersection(Transform3::Identity());
165 double alpha = 0.25 * M_PI;
169 auto aCone = Surface::makeShared<ConeSurface>(
transform,
alpha,
true);
172 auto lTransform = transform.linear();
175 Vector3 onCone = transform *
Vector3(std::sqrt(2.), std::sqrt(2.), 2.);
176 Vector3 outCone = transform *
Vector3(std::sqrt(4.), std::sqrt(4.), 2.);
178 Vector3 perpXY = lTransform *
Vector3(1., -1., 0.).normalized();
179 Vector3 transXY = lTransform *
Vector3(1., 1., 0).normalized();
182 BOOST_CHECK(aCone->isOnSurface(
tgContext, onCone, transXY,
false));
183 auto aIntersection = aCone->intersect(
tgContext, onCone, transXY,
true);
186 BOOST_CHECK(aIntersection[0]);
188 BOOST_CHECK(aIntersection[0].
status() == Intersection3D::Status::reachable);
192 BOOST_CHECK(aIntersection[1]);
194 BOOST_CHECK(aIntersection[1].
status() == Intersection3D::Status::onSurface);
197 auto iIntersection = aCone->intersect(
tgContext, outCone, perpXY,
false);
200 BOOST_CHECK(!iIntersection[0]);
204 testConeIntersection(Transform3::Identity());
220 auto aPlane = Surface::makeShared<PlaneSurface>(
225 Vector3 onit = transform *
Vector3(11_cm, -22_cm, 0_m);
226 Vector3 after = transform *
Vector3(33_cm, 12_mm, 1_m);
227 Vector3 outside = transform *
Vector3(2. * halfX, 2 * halfY, -1_mm);
230 auto lTransform = transform.linear();
233 Vector3 direction = lTransform *
Vector3(4_mm, 8_mm, 50_cm).normalized();
234 Vector3 parallel = lTransform *
Vector3(1., 1., 0.).normalized();
237 auto fIntersection =
aPlane->intersect(
tgContext, before, direction,
true);
240 BOOST_CHECK(fIntersection[0]);
242 BOOST_CHECK(fIntersection[0].
status() == Intersection3D::Status::reachable);
244 BOOST_CHECK(fIntersection[0].
pathLength() > 0.);
246 BOOST_CHECK(!fIntersection[1]);
249 auto oIntersection =
aPlane->intersect(
tgContext, onit, direction,
true);
251 BOOST_CHECK(oIntersection[0]);
253 BOOST_CHECK(oIntersection[0].
status() == Intersection3D::Status::onSurface);
257 BOOST_CHECK(!oIntersection[1]);
260 auto bIntersection =
aPlane->intersect(
tgContext, after, direction,
true);
262 BOOST_CHECK(bIntersection[0]);
264 BOOST_CHECK(bIntersection[0].
status() == Intersection3D::Status::reachable);
266 BOOST_CHECK(bIntersection[0].
pathLength() < 0.);
268 BOOST_CHECK(!bIntersection[1]);
271 auto mIntersection =
aPlane->intersect(
tgContext, outside, direction,
true);
273 BOOST_CHECK(!mIntersection[0]);
275 BOOST_CHECK(mIntersection[0].
status() == Intersection3D::Status::missed);
277 BOOST_CHECK(mIntersection[0].
pathLength() > 0.);
279 BOOST_CHECK(!mIntersection[1]);
282 auto iIntersection =
aPlane->intersect(
tgContext, before, parallel,
true);
284 BOOST_CHECK(!iIntersection[0]);
286 BOOST_CHECK(iIntersection[0].
status() ==
287 Intersection3D::Status::unreachable);
289 BOOST_CHECK(!iIntersection[1]);
293 testPlanarIntersection(Transform3::Identity());
309 auto aLine = Surface::makeShared<StrawSurface>(
transform, radius, halfZ);
313 Vector3 onit1 = transform *
Vector3(0_m, 0_m, 0_m);
314 Vector3 onitP = transform *
Vector3(1_cm, 0_m, 23_um);
315 Vector3 after = transform *
Vector3(33_cm, 12_mm, 1_m);
316 Vector3 outside = transform *
Vector3(2., 0., 100_m);
319 auto lTransform = transform.linear();
320 Vector3 direction = lTransform *
Vector3(2_cm, 3_cm, 5_cm).normalized();
321 Vector3 normalP = lTransform *
Vector3(0, 1., 0.).normalized();
322 Vector3 parallel = lTransform *
Vector3(0, 0., 1.).normalized();
326 auto fIntersection = aLine->intersect(
tgContext, before, direction,
true);
328 BOOST_CHECK(fIntersection[0]);
330 BOOST_CHECK(fIntersection[0].
status() == Intersection3D::Status::reachable);
332 BOOST_CHECK(fIntersection[0].
pathLength() > 0.);
334 BOOST_CHECK(!fIntersection[1]);
337 auto oIntersection = aLine->intersect(
tgContext, onit1, direction,
true);
339 BOOST_CHECK(oIntersection[0]);
341 BOOST_CHECK(oIntersection[0].
status() == Intersection3D::Status::onSurface);
345 BOOST_CHECK(!oIntersection[1]);
348 oIntersection = aLine->intersect(
tgContext, onitP, normalP,
true);
350 BOOST_CHECK(oIntersection[0]);
352 BOOST_CHECK(oIntersection[0].
status() == Intersection3D::Status::onSurface);
356 BOOST_CHECK(!oIntersection[1]);
359 auto bIntersection = aLine->intersect(
tgContext, after, direction,
true);
361 BOOST_CHECK(bIntersection[0]);
363 BOOST_CHECK(bIntersection[0].
status() == Intersection3D::Status::reachable);
365 BOOST_CHECK(bIntersection[0].
pathLength() < 0.);
367 BOOST_CHECK(!bIntersection[1]);
370 auto mIntersection = aLine->intersect(
tgContext, outside, direction,
true);
372 BOOST_CHECK(!mIntersection[0]);
374 BOOST_CHECK(mIntersection[0].
status() == Intersection3D::Status::missed);
376 BOOST_CHECK(mIntersection[0].
pathLength() < 0.);
378 BOOST_CHECK(!mIntersection[1]);
381 auto iIntersection = aLine->intersect(
tgContext, before, parallel,
true);
383 BOOST_CHECK(!iIntersection[0]);
385 BOOST_CHECK(iIntersection[0].
status() ==
386 Intersection3D::Status::unreachable);
388 BOOST_CHECK(!iIntersection[1]);
392 testLineAppraoch(Transform3::Identity());
398 BOOST_AUTO_TEST_SUITE_END()