diff --git a/extern/typed-geometry b/extern/typed-geometry index 6dd433f303977ebd6c92759041590d41288b25a1..8881f131192114d69f6239a2612accc63a70f82f 160000 --- a/extern/typed-geometry +++ b/extern/typed-geometry @@ -1 +1 @@ -Subproject commit 6dd433f303977ebd6c92759041590d41288b25a1 +Subproject commit 8881f131192114d69f6239a2612accc63a70f82f diff --git a/tests/feature/intersections/segment3-sphere-surface.cc b/tests/feature/intersections/segment3-sphere-surface.cc new file mode 100644 index 0000000000000000000000000000000000000000..ef6edddfa4ac470c738cecb86f1606491c9f394d --- /dev/null +++ b/tests/feature/intersections/segment3-sphere-surface.cc @@ -0,0 +1,49 @@ +#include <test.hh> + +#include <typed-geometry/tg.hh> + +//#include <glow-extras/viewer/canvas.hh> + +TG_FUZZ_TEST(TypedGeometry, Segment3SphereSurface) +{ + auto const radius = tg::uniform(rng, 0.01f, 10.0f); + auto const center = tg::uniform(rng, tg::aabb3(tg::pos3(-10), tg::pos3(10))); + auto const sphere = tg::sphere3(center, radius * 0.9999f); // don't sample too close to the boundary + auto const sphere_boundary = tg::sphere_boundary<3, float>(center, radius); + + auto const gen_point_inside = [&]() { return tg::uniform(rng, sphere); }; + auto const gen_point_outside = [&]() { + auto const dir = tg::uniform<tg::dir3>(rng); + auto const scaling = tg::uniform(rng, 1.0001f, 4.0f); + return center + radius * scaling * dir; + }; + + // both inside -> no intersection + for (auto i = 0; i < 1000; ++i) + { + auto const p0 = gen_point_inside(); + auto const p1 = gen_point_inside(); + auto const intersection = tg::intersection(sphere_boundary, tg::segment3(p0, p1)); + + // auto c = gv::canvas(); + // c.add_line(p0, p1); + // c.add_sphere(center, radius, tg::color3::white); + + CHECK(!intersection.any()); + } + + // one inside, one outside -> 1 intersection + for (auto i = 0; i < 1000; ++i) + { + auto const p0 = gen_point_inside(); + auto const p1 = gen_point_outside(); + auto const intersection = tg::intersection(sphere_boundary, tg::segment3(p0, p1)); + + // auto c = gv::canvas(); + // c.add_line(p0, p1); + // c.add_sphere(center, radius, tg::color3::white); + // c.add_points(intersection.first(), tg::color3::red); + + CHECK(intersection.size() == 1); + } +}