mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 14:20:58 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
104 lines
3.5 KiB
C++
104 lines
3.5 KiB
C++
#include <array>
|
|
#include <catch2/catch_all.hpp>
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_approx.hpp>
|
|
#include "test_utils.hpp"
|
|
|
|
#include "libslic3r/Point.hpp"
|
|
#include <cstdlib>
|
|
#include <cmath>
|
|
#include <libslic3r/SLA/IndexedMesh.hpp>
|
|
#include <libslic3r/SLA/Hollowing.hpp>
|
|
#include <utility>
|
|
|
|
#include "sla_test_utils.hpp"
|
|
|
|
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 == Catch::Approx(-4.f));
|
|
REQUIRE(out[1].first == Catch::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);
|
|
}
|
|
|
|
#ifdef SLIC3R_HOLE_RAYCASTER
|
|
// 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.
|
|
TEST_CASE("Raycaster with loaded drillholes", "[sla_raycast]")
|
|
{
|
|
// Load the cube and make it hollow.
|
|
TriangleMesh cube = load_model("20mm_cube.obj");
|
|
sla::HollowingConfig hcfg;
|
|
std::unique_ptr<TriangleMesh> cube_inside = sla::generate_interior(cube, hcfg);
|
|
REQUIRE(cube_inside);
|
|
|
|
// Helper bb
|
|
auto boxbb = cube.bounding_box();
|
|
|
|
// Create the big 10mm long drainhole in the front wall.
|
|
Vec3f center = boxbb.center().cast<float>();
|
|
Vec3f p = {center.x(), 0., center.z()};
|
|
Vec3f normal = {0.f, 1.f, 0.f};
|
|
float radius = 5.f;
|
|
float hole_length = 10.;
|
|
sla::DrainHoles holes = { sla::DrainHole{p, normal, radius, hole_length} };
|
|
|
|
cube.merge(*cube_inside);
|
|
|
|
sla::IndexedMesh emesh{cube};
|
|
emesh.load_holes(holes);
|
|
|
|
Vec3d s = center.cast<double>();
|
|
// Fire from center, should hit the interior wall
|
|
auto hit = emesh.query_ray_hit(s, {0, 1., 0.});
|
|
REQUIRE(hit.distance() == Catch::Approx(boxbb.size().x() / 2 - hcfg.min_thickness));
|
|
|
|
// Fire upward from hole center, hit distance equals the radius (hits the
|
|
// side of the hole cut.
|
|
s.y() = hcfg.min_thickness / 2;
|
|
hit = emesh.query_ray_hit(s, {0, 0., 1.});
|
|
REQUIRE(hit.distance() == Catch::Approx(radius));
|
|
|
|
// Fire from outside, hit the back side of the cube interior
|
|
s.y() = -1.;
|
|
hit = emesh.query_ray_hit(s, {0, 1., 0.});
|
|
REQUIRE(hit.distance() == Catch::Approx(boxbb.max.y() - hcfg.min_thickness - s.y()));
|
|
|
|
// Fire downwards from above the hole cylinder. Has to go through the cyl.
|
|
// as it was not there.
|
|
s = center.cast<double>();
|
|
s.z() = boxbb.max.z() - hcfg.min_thickness - 1.;
|
|
hit = emesh.query_ray_hit(s, {0, 0., -1.});
|
|
REQUIRE(hit.distance() == Catch::Approx(s.z() - boxbb.min.z() - hcfg.min_thickness));
|
|
|
|
// Check for support tree correctness
|
|
test_support_model_collision("20mm_cube.obj", {}, hcfg, holes);
|
|
}
|
|
#endif
|