Fixed a bug in the hole-aware raycaster

This commit is contained in:
Lukas Matena 2020-01-17 16:01:49 +01:00
parent 49678fe418
commit d8f2c8cdab
2 changed files with 36 additions and 1 deletions

View file

@ -8,6 +8,38 @@
using namespace Slic3r;
// First do a simple test of the hole raycaster.
TEST_CASE("Raycaster - find intersections of a line and cylinder")
{
sla::DrainHole hole{Vec3f(0,0,0), Vec3f(0,0,1), 5, 10};
std::array<std::pair<float, Vec3d>, 2> out;
Vec3f s;
Vec3f dir;
// Start inside the hole and cast perpendicular to its axis.
s = {-1.f, 0, 5.f};
dir = {1.f, 0, 0};
hole.get_intersections(s, dir, out);
REQUIRE(out[0].first == Approx(-4.f));
REQUIRE(out[1].first == Approx(6.f));
// Start outside and cast parallel to axis.
s = {0, 0, -1.f};
dir = {0, 0, 1.f};
hole.get_intersections(s, dir, out);
REQUIRE(std::abs(out[0].first - 1.f) < 0.001f);
REQUIRE(std::abs(out[1].first - 11.f) < 0.001f);
// Start outside and cast so that entry is in base and exit on the cylinder
s = {0, -1.f, -1.f};
dir = {0, 1.f, 1.f};
dir.normalize();
hole.get_intersections(s, dir, out);
REQUIRE(std::abs(out[0].first - std::sqrt(2.f)) < 0.001f);
REQUIRE(std::abs(out[1].first - std::sqrt(72.f)) < 0.001f);
}
// Create a simple scene with a 20mm cube and a big hole in the front wall
// with 5mm radius. Then shoot rays from interesting positions and see where
// they land.