Files
OrcaSlicer/tests/slic3rutils/test_sequential_clearance.cpp
Kris Austin 9921437c27 Fail tests whose sections assert nothing (#17420)
tests/CATCH2.md says to run the suites with `--order rand --warn
NoAssertions`. On main that fails in fff_print (8 test cases), libslic3r
(15), sla_print (1) and slic3rutils (4), even when each case runs alone.
ctest never passed the flag, so nothing stopped new ones. Most of these
tests have SECTIONs that only set up state, with the assertions after
them, or generated cases that return early for combinations that don't
apply. Catch2 counts assertions per section, so each of those reads as
an empty test.

Where only a value or a short setup changes, use GENERATE or a table and
generate only the combinations that apply. Elsewhere, end each section
with a call to a local check. ctest now passes `--warn NoAssertions`, so
CI fails a case or section that asserts nothing, and tests/AGENTS.md
says so. ctest also passes the CATCH_EXTRA_ARGS cache variable, which
nothing read before, split like a command line, so setting it now takes
effect.

Three tests only wrote a debug mesh or diagram and asserted nothing.
They now check that the Voronoi diagram of the six points is complete,
that hollowing with hfRemoveInsideTriangles removes at least half of the
roughly 400 mm² of the two spheres that lies deeper than the wall, and
that the half cone is closed. The legacy 3MF scenario checked for a
volume map on every plate of a file that has none, so it now also saves
and loads a project with a plate, and its name says so.
2026-11-14 10:47:42 -06:00

166 lines
7.8 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "catch2/matchers/catch_matchers.hpp"
#include "fff_print/test_helpers.hpp"
#include "slic3r/GUI/SequentialPrintClearance.hpp"
#include <libslic3r/libslic3r.h>
#include <libslic3r/Model.hpp>
#include <libslic3r/TriangleMesh.hpp>
#include <libslic3r/PrintConfig.hpp>
#include <libslic3r/Print.hpp>
#include <libslic3r/Polygon.hpp>
#include <libslic3r/ObjectID.hpp>
#include <cstddef>
#include <map>
#include <vector>
#include <utility>
using namespace Slic3r;
using namespace Slic3r::GUI;
using Catch::Matchers::WithinAbs;
namespace {
SequentialClearanceInstance instance(coord_t x, coord_t y, double height)
{
return {height, BoundingBox(Point(x, y), Point(x + 5, y + 10)),
Slic3r::Polygon{Point(x, y), Point(x + 5, y), Point(x + 5, y + 10), Point(x, y + 10)}};
}
} // namespace
TEST_CASE("Sequential clearance preserves model print order when objects move", "[SequentialClearance][Regression]")
{
const coord_t last_y = GENERATE(-20, 20);
std::vector<SequentialClearanceInstance> instances{instance(20, 0, 50.), instance(0, last_y, 50.)};
const auto warnings = sequential_clearance_height_polygons(instances, 200., 30., 10.);
REQUIRE(warnings.size() == 1);
CHECK(warnings.front().first == instance(20, 0, 50.).hull_polygon);
CHECK_THAT(warnings.front().second, WithinAbs(30., 1e-6));
}
TEST_CASE("Sequential clearance handles chains of overlapping Y ranges", "[SequentialClearance][Regression]")
{
// A overlaps B, B overlaps C, but A does not overlap C. Combining X order
// for overlaps with Y order otherwise formed the cycle B < A < C < B.
std::vector<SequentialClearanceInstance> instances{
instance(20, 0, 50.), instance(10, 8, 50.), instance(0, 16, 50.)};
const auto warnings = sequential_clearance_height_polygons(instances, 200., 30., 10.);
REQUIRE(warnings.size() == 2);
CHECK(warnings[0].first == instance(20, 0, 50.).hull_polygon);
CHECK(warnings[1].first == instance(10, 8, 50.).hull_polygon);
CHECK_THAT(warnings[0].second, WithinAbs(10., 1e-6));
CHECK_THAT(warnings[1].second, WithinAbs(10., 1e-6));
}
TEST_CASE("Sequential clearance applies rod height only to positive Y overlap", "[SequentialClearance]")
{
const coord_t next_y = GENERATE(9, 10, 11);
std::vector<SequentialClearanceInstance> instances{instance(0, 0, 50.), instance(20, next_y, 50.)};
const auto warnings = sequential_clearance_height_polygons(instances, 200., 30., 10.);
REQUIRE(warnings.size() == 1);
CHECK(warnings.front().first == instances.front().hull_polygon);
CHECK_THAT(warnings.front().second, WithinAbs(next_y < 10 ? 10. : 30., 1e-6));
}
TEST_CASE("Sequential clearance allows the last object up to printable height", "[SequentialClearance]")
{
std::vector<SequentialClearanceInstance> instances;
CHECK(sequential_clearance_height_polygons(instances, 200., 30., 10.).empty());
instances.push_back(instance(0, 0, 200.));
CHECK(sequential_clearance_height_polygons(instances, 200., 30., 10.).empty());
instances.front().instance_height = 201.;
const auto warnings = sequential_clearance_height_polygons(instances, 200., 30., 10.);
REQUIRE(warnings.size() == 1);
CHECK_THAT(warnings.front().second, WithinAbs(200., 1e-6));
}
TEST_CASE("Sequential clearance warns the same copy as print validation", "[SequentialClearance][Regression]")
{
constexpr double rod_height = 10.;
constexpr double lid_height = 30.;
constexpr double printable_height = 200.;
Model model = Test::model("rotated copies", make_cube(10., 10., 50.));
ModelObject* object = model.objects.front();
object->instances.front()->set_offset(Vec3d(150., 80., 0.));
ModelInstance* rotated = object->add_instance();
rotated->set_offset(Vec3d(50., 80., 0.));
rotated->set_rotation(Z, PI / 2.);
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"print_sequence", "by object"}, {"extruder_clearance_radius", 20.},
{"extruder_clearance_height_to_lid", lid_height}, {"extruder_clearance_height_to_rod", rod_height},
{"printable_height", printable_height}});
Print print;
print.auto_assign_extruders(object);
print.apply(model, config);
Polygons polygons;
std::vector<std::pair<Slic3r::Polygon, float>> validation_warnings;
Print::sequential_print_clearance_valid(print, &polygons, &validation_warnings);
std::map<ObjectID, int> print_order;
for (const PrintObject* print_object : print.objects())
for (const PrintInstance& print_instance : print_object->instances())
print_order.emplace(print_instance.model_instance->id(), print_instance.model_instance->arrange_order);
std::vector<SequentialClearanceInstance> instances;
for (size_t i = 0; i < object->instances.size(); ++i) {
Slic3r::Polygon hull = object->convex_hull_2d(object->instances[i]->get_matrix());
instances.push_back({object->get_instance_max_z(i), hull.bounding_box(), hull, object->instances[i]->id()});
}
// Copies print in object-list order, so the first copy is the one held to the rod height: the later
// copy shares its Y band. Print validation warns about that copy, and the clearance preview must
// warn about the same one.
REQUIRE(validation_warnings.size() == 1);
CHECK(validation_warnings.front().first.bounding_box().contains(instances[0].bounding_box.center()));
CHECK_FALSE(validation_warnings.front().first.bounding_box().contains(instances[1].bounding_box.center()));
sort_sequential_clearance_instances(instances.begin(), instances.end(), print_order);
const auto warnings = sequential_clearance_height_polygons(instances, printable_height, lid_height, rod_height);
REQUIRE(warnings.size() == 1);
CHECK(warnings.front().first == instances[0].hull_polygon);
CHECK_THAT(warnings.front().second, WithinAbs(rod_height, 1e-6));
}
TEST_CASE("Sequential clearance keeps copy order when print order is unavailable", "[SequentialClearance]")
{
std::vector<SequentialClearanceInstance> instances{instance(20, 0, 50.), instance(0, 0, 50.)};
instances[0].instance_id = ObjectID(1);
instances[1].instance_id = ObjectID(2);
std::map<ObjectID, int> print_order{{ObjectID(1), 2}, {ObjectID(2), 1}};
const auto check_copy_order = [&]() {
sort_sequential_clearance_instances(instances.begin(), instances.end(), print_order);
CHECK(instances[0].instance_id == ObjectID(1));
CHECK(instances[1].instance_id == ObjectID(2));
};
SECTION("No validation order") { print_order.clear(); check_copy_order(); }
SECTION("New copy missing from print") { print_order.erase(ObjectID(2)); check_copy_order(); }
SECTION("Copy has not been ordered") { print_order[ObjectID(2)] = 0; check_copy_order(); }
SECTION("Copy has an invalid order") { print_order[ObjectID(2)] = -1; check_copy_order(); }
}
TEST_CASE("Sequential clearance keeps object order when sorting copies", "[SequentialClearance]")
{
std::vector<SequentialClearanceInstance> instances(4, instance(0, 0, 50.));
for (size_t i = 0; i < instances.size(); ++i)
instances[i].instance_id = ObjectID(instances.size() - i);
const std::map<ObjectID, int> print_order{{ObjectID(1), 1}, {ObjectID(2), 2}, {ObjectID(3), 3}, {ObjectID(4), 4}};
// The two objects were reordered in the model since the last validation.
sort_sequential_clearance_instances(instances.begin(), instances.begin() + 2, print_order);
sort_sequential_clearance_instances(instances.begin() + 2, instances.end(), print_order);
CHECK(instances[0].instance_id == ObjectID(3));
CHECK(instances[1].instance_id == ObjectID(4));
CHECK(instances[2].instance_id == ObjectID(1));
CHECK(instances[3].instance_id == ObjectID(2));
}