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)
47 auto aCylinder = Surface::makeShared<CylinderSurface>(
48 std::make_shared<Transform3D>(
transform), radius, 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 Intersection::Status::onSurface);
73 BOOST_CHECK(aIntersection.alternative);
75 BOOST_CHECK(aIntersection.alternative.status ==
76 Intersection::Status::reachable);
86 BOOST_CHECK(cIntersection);
88 BOOST_CHECK(cIntersection.intersection.status ==
89 Intersection::Status::reachable);
91 BOOST_CHECK(cIntersection.alternative);
93 BOOST_CHECK(cIntersection.alternative.status ==
94 Intersection::Status::reachable);
96 BOOST_CHECK(cIntersection.alternative.pathLength *
97 cIntersection.intersection.pathLength <
105 BOOST_CHECK(oIntersection);
107 BOOST_CHECK(oIntersection.intersection.status ==
108 Intersection::Status::reachable);
110 BOOST_CHECK(oIntersection.alternative);
112 BOOST_CHECK(oIntersection.alternative.status ==
113 Intersection::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 Intersection::Status::reachable);
138 BOOST_CHECK(eIntersection.alternative);
140 BOOST_CHECK(eIntersection.alternative.status ==
141 Intersection::Status::reachable);
143 BOOST_CHECK(eIntersection.alternative.pathLength < 0.);
148 BOOST_CHECK(eIntersection.intersection.pathLength < 0.);
150 BOOST_CHECK(eIntersection.intersection.status ==
151 Intersection::Status::reachable);
153 BOOST_CHECK(!eIntersection.alternative);
155 BOOST_CHECK(eIntersection.alternative.status ==
156 Intersection::Status::missed);
158 BOOST_CHECK(eIntersection.alternative.pathLength > 0.);
162 testCylinderIntersection(Transform3D::Identity());
175 auto aCone = Surface::makeShared<ConeSurface>(
176 std::make_shared<Transform3D>(
transform), alpha,
true);
185 Vector3D perpXY = lTransform *
Vector3D(1., -1., 0.).normalized();
186 Vector3D transXY = lTransform *
Vector3D(1., 1., 0).normalized();
189 BOOST_CHECK(aCone->isOnSurface(
tgContext, onCone, transXY,
false));
190 auto aIntersection = aCone->intersect(
tgContext, onCone, transXY,
true);
193 BOOST_CHECK(aIntersection);
195 BOOST_CHECK(aIntersection.intersection.status ==
196 Intersection::Status::onSurface);
199 BOOST_CHECK(aIntersection.alternative);
201 BOOST_CHECK(aIntersection.alternative.status ==
202 Intersection::Status::reachable);
208 auto iIntersection = aCone->intersect(
tgContext, outCone, perpXY,
false);
211 BOOST_CHECK(!iIntersection);
215 testConeIntersection(Transform3D::Identity());
231 auto aPlane = Surface::makeShared<PlaneSurface>(
232 std::make_shared<Transform3D>(
transform),
233 std::make_shared<RectangleBounds>(halfX, halfY));
246 Vector3D parallel = lTransform *
Vector3D(1., 1., 0.).normalized();
249 auto fIntersection =
aPlane->intersect(
tgContext, before, direction,
true);
252 BOOST_CHECK(fIntersection);
254 BOOST_CHECK(fIntersection.intersection.status ==
255 Intersection::Status::reachable);
257 BOOST_CHECK(fIntersection.intersection.pathLength > 0.);
259 BOOST_CHECK(!fIntersection.alternative);
262 auto oIntersection =
aPlane->intersect(
tgContext, onit, direction,
true);
264 BOOST_CHECK(oIntersection);
266 BOOST_CHECK(oIntersection.intersection.status ==
267 Intersection::Status::onSurface);
269 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
272 BOOST_CHECK(!oIntersection.alternative);
275 auto bIntersection =
aPlane->intersect(
tgContext, after, direction,
true);
277 BOOST_CHECK(bIntersection);
279 BOOST_CHECK(bIntersection.intersection.status ==
280 Intersection::Status::reachable);
282 BOOST_CHECK(bIntersection.intersection.pathLength < 0.);
284 BOOST_CHECK(!bIntersection.alternative);
287 auto mIntersection =
aPlane->intersect(
tgContext, outside, direction,
true);
289 BOOST_CHECK(!mIntersection);
291 BOOST_CHECK(mIntersection.intersection.status ==
292 Intersection::Status::missed);
294 BOOST_CHECK(mIntersection.intersection.pathLength > 0.);
296 BOOST_CHECK(!mIntersection.alternative);
299 auto iIntersection =
aPlane->intersect(
tgContext, before, parallel,
true);
301 BOOST_CHECK(!iIntersection);
303 BOOST_CHECK(iIntersection.intersection.status ==
304 Intersection::Status::unreachable);
306 BOOST_CHECK(!iIntersection.alternative);
310 testPlanarIntersection(Transform3D::Identity());
326 auto aLine = Surface::makeShared<StrawSurface>(
327 std::make_shared<Transform3D>(
transform), radius, halfZ);
339 Vector3D normalP = lTransform *
Vector3D(0, 1., 0.).normalized();
340 Vector3D parallel = lTransform *
Vector3D(0, 0., 1.).normalized();
344 auto fIntersection = aLine->intersect(
tgContext, before, direction,
true);
346 BOOST_CHECK(fIntersection);
348 BOOST_CHECK(fIntersection.intersection.status ==
349 Intersection::Status::reachable);
351 BOOST_CHECK(fIntersection.intersection.pathLength > 0.);
353 BOOST_CHECK(!fIntersection.alternative);
356 auto oIntersection = aLine->intersect(
tgContext, onit1, direction,
true);
358 BOOST_CHECK(oIntersection);
360 BOOST_CHECK(oIntersection.intersection.status ==
361 Intersection::Status::onSurface);
363 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
366 BOOST_CHECK(!oIntersection.alternative);
369 oIntersection = aLine->intersect(
tgContext, onitP, normalP,
true);
371 BOOST_CHECK(oIntersection);
373 BOOST_CHECK(oIntersection.intersection.status ==
374 Intersection::Status::onSurface);
376 BOOST_CHECK(
std::abs(oIntersection.intersection.pathLength) <
379 BOOST_CHECK(!oIntersection.alternative);
382 auto bIntersection = aLine->intersect(
tgContext, after, direction,
true);
384 BOOST_CHECK(bIntersection);
386 BOOST_CHECK(bIntersection.intersection.status ==
387 Intersection::Status::reachable);
389 BOOST_CHECK(bIntersection.intersection.pathLength < 0.);
391 BOOST_CHECK(!bIntersection.alternative);
394 auto mIntersection = aLine->intersect(
tgContext, outside, direction,
true);
396 BOOST_CHECK(!mIntersection);
398 BOOST_CHECK(mIntersection.intersection.status ==
399 Intersection::Status::missed);
401 BOOST_CHECK(mIntersection.intersection.pathLength < 0.);
403 BOOST_CHECK(!mIntersection.alternative);
406 auto iIntersection = aLine->intersect(
tgContext, before, parallel,
true);
408 BOOST_CHECK(!iIntersection);
410 BOOST_CHECK(iIntersection.intersection.status ==
411 Intersection::Status::unreachable);
413 BOOST_CHECK(!iIntersection.alternative);
417 testLineAppraoch(Transform3D::Identity());
423 BOOST_AUTO_TEST_SUITE_END()