mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-01 21:21:10 -06:00
New functions for variable offsets of polygons / expolygons.
Test cases for the above. Improvements of older test cases.
This commit is contained in:
parent
18bbefcd61
commit
5e8572a196
8 changed files with 565 additions and 27 deletions
|
|
@ -95,7 +95,6 @@ SCENARIO(" Bridge flow specifics.", "[Flow]") {
|
|||
SCENARIO("Flow: Flow math for non-bridges", "[Flow]") {
|
||||
GIVEN("Nozzle Diameter of 0.4, a desired width of 1mm and layer height of 0.5") {
|
||||
ConfigOptionFloatOrPercent width(1.0, false);
|
||||
float spacing = 0.4f;
|
||||
float nozzle_diameter = 0.4f;
|
||||
float bridge_flow = 0.f;
|
||||
float layer_height = 0.5f;
|
||||
|
|
@ -119,7 +118,6 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") {
|
|||
}
|
||||
/// Check the min/max
|
||||
GIVEN("Nozzle Diameter of 0.25") {
|
||||
float spacing = 0.4f;
|
||||
float nozzle_diameter = 0.25f;
|
||||
float bridge_flow = 0.f;
|
||||
float layer_height = 0.5f;
|
||||
|
|
@ -161,7 +159,6 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") {
|
|||
SCENARIO("Flow: Flow math for bridges", "[Flow]") {
|
||||
GIVEN("Nozzle Diameter of 0.4, a desired width of 1mm and layer height of 0.5") {
|
||||
auto width = ConfigOptionFloatOrPercent(1.0, false);
|
||||
float spacing = 0.4f;
|
||||
float nozzle_diameter = 0.4f;
|
||||
float bridge_flow = 1.0f;
|
||||
float layer_height = 0.5f;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ using namespace Slic3r;
|
|||
/// Helper method to find the tool used for the brim (always the first extrusion)
|
||||
static int get_brim_tool(const std::string &gcode)
|
||||
{
|
||||
int brim_tool = -1;
|
||||
int tool = -1;
|
||||
int brim_tool = -1;
|
||||
int tool = -1;
|
||||
GCodeReader parser;
|
||||
parser.parse_buffer(gcode, [&tool, &brim_tool] (Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line)
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ static int get_brim_tool(const std::string &gcode)
|
|||
return brim_tool;
|
||||
}
|
||||
|
||||
TEST_CASE("Skirt height is honored") {
|
||||
TEST_CASE("Skirt height is honored", "[Skirt]") {
|
||||
DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize({
|
||||
{ "skirts", 1 },
|
||||
|
|
@ -60,7 +60,7 @@ TEST_CASE("Skirt height is honored") {
|
|||
REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
|
||||
}
|
||||
|
||||
SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
|
||||
SCENARIO("Original Slic3r Skirt/Brim tests", "[SkirtBrim]") {
|
||||
GIVEN("A default configuration") {
|
||||
DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
|
||||
config.set_num_extruders(4);
|
||||
|
|
@ -73,7 +73,8 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
|
|||
{ "first_layer_speed", "100%" },
|
||||
// remove noise from top/solid layers
|
||||
{ "top_solid_layers", 0 },
|
||||
{ "bottom_solid_layers", 1 }
|
||||
{ "bottom_solid_layers", 1 },
|
||||
{ "start_gcode", "T[initial_tool]\n" }
|
||||
});
|
||||
|
||||
WHEN("Brim width is set to 5") {
|
||||
|
|
@ -120,25 +121,29 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
|
|||
|
||||
WHEN("Perimeter extruder = 2 and support extruders = 3") {
|
||||
THEN("Brim is printed with the extruder used for the perimeters of first object") {
|
||||
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, {
|
||||
config.set_deserialize({
|
||||
{ "skirts", 0 },
|
||||
{ "brim_width", 5 },
|
||||
{ "perimeter_extruder", 2 },
|
||||
{ "support_material_extruder", 3 }
|
||||
});
|
||||
{ "support_material_extruder", 3 },
|
||||
{ "infill_extruder", 4 }
|
||||
});
|
||||
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
|
||||
int tool = get_brim_tool(gcode);
|
||||
REQUIRE(tool == config.opt_int("perimeter_extruder") - 1);
|
||||
}
|
||||
}
|
||||
WHEN("Perimeter extruder = 2, support extruders = 3, raft is enabled") {
|
||||
THEN("brim is printed with same extruder as skirt") {
|
||||
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, {
|
||||
{ "skirts", 0 },
|
||||
{ "brim_width", 5 },
|
||||
{ "perimeter_extruder", 2 },
|
||||
{ "support_material_extruder", 3 },
|
||||
{ "raft_layers", 1 }
|
||||
});
|
||||
config.set_deserialize({
|
||||
{ "skirts", 0 },
|
||||
{ "brim_width", 5 },
|
||||
{ "perimeter_extruder", 2 },
|
||||
{ "support_material_extruder", 3 },
|
||||
{ "infill_extruder", 4 },
|
||||
{ "raft_layers", 1 }
|
||||
});
|
||||
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
|
||||
int tool = get_brim_tool(gcode);
|
||||
REQUIRE(tool == config.opt_int("support_material_extruder") - 1);
|
||||
}
|
||||
|
|
@ -200,6 +205,7 @@ SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
|
|||
{ "infill_extruder", 3 }, // ensure that a tool command gets emitted.
|
||||
{ "cooling", false }, // to prevent speeds to be altered
|
||||
{ "first_layer_speed", "100%" }, // to prevent speeds to be altered
|
||||
{ "start_gcode", "T[initial_tool]\n" }
|
||||
});
|
||||
|
||||
THEN("overhang generates?") {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
|
|||
add_executable(${_TEST_NAME}_tests
|
||||
${_TEST_NAME}_tests.cpp
|
||||
test_3mf.cpp
|
||||
test_clipper_offset.cpp
|
||||
test_config.cpp
|
||||
# test_elephant_foot_compensation.cpp
|
||||
test_geometry.cpp
|
||||
test_polygon.cpp
|
||||
test_stl.cpp
|
||||
|
|
|
|||
214
tests/libslic3r/test_clipper_offset.cpp
Normal file
214
tests/libslic3r/test_clipper_offset.cpp
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/SVG.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
#define TESTS_EXPORT_SVGS
|
||||
|
||||
SCENARIO("Constant offset", "[ClipperUtils]") {
|
||||
coord_t s = 1000000;
|
||||
GIVEN("20mm box") {
|
||||
ExPolygon box20mm;
|
||||
box20mm.contour.points = { { 0, 0 }, { 20 * s, 0 }, { 20 * s, 20 * s}, { 0, 20 * s} };
|
||||
std::vector<float> deltas_plus(box20mm.contour.points.size(), 1. * s);
|
||||
std::vector<float> deltas_minus(box20mm.contour.points.size(), - 1. * s);
|
||||
Polygons output;
|
||||
WHEN("Slic3r::offset()") {
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("plus 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::offset(box20mm, 1. * s, ClipperLib::jtMiter, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("constant_offset_box20mm_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 22^2mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(22. * 22. * s * s));
|
||||
}
|
||||
}
|
||||
DYNAMIC_SECTION("minus 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::offset(box20mm, - 1. * s, ClipperLib::jtMiter, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("constant_offset_box20mm_minus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 18^2mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(18. * 18. * s * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WHEN("Slic3r::variable_offset_outer/inner") {
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("plus 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::variable_offset_outer(box20mm, { deltas_plus }, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("variable_offset_box20mm_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 22^2mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(22. * 22. * s * s));
|
||||
}
|
||||
}
|
||||
DYNAMIC_SECTION("minus 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::variable_offset_inner(box20mm, { deltas_minus }, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("variable_offset_box20mm_minus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 18^2mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(18. * 18. * s * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("20mm box with 10mm hole") {
|
||||
ExPolygon box20mm;
|
||||
box20mm.contour.points = { { 0, 0 }, { 20 * s, 0 }, { 20 * s, 20 * s}, { 0, 20 * s} };
|
||||
box20mm.holes.emplace_back(Slic3r::Polygon({ { 5 * s, 5 * s }, { 5 * s, 15 * s}, { 15 * s, 15 * s}, { 15 * s, 5 * s } }));
|
||||
std::vector<float> deltas_plus(box20mm.contour.points.size(), 1. * s);
|
||||
std::vector<float> deltas_minus(box20mm.contour.points.size(), -1. * s);
|
||||
ExPolygons output;
|
||||
SECTION("Slic3r::offset()") {
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("miter " << miter << "x") {
|
||||
WHEN("plus 1mm") {
|
||||
output = Slic3r::offset_ex(box20mm, 1. * s, ClipperLib::jtMiter, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("constant_offset_box20mm_10mm_hole_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(to_polygons(output), "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 22^2-8^2 mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx((22. * 22. - 8. * 8.) * s * s));
|
||||
}
|
||||
}
|
||||
WHEN("minus 1mm") {
|
||||
output = Slic3r::offset_ex(box20mm, - 1. * s, ClipperLib::jtMiter, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("constant_offset_box20mm_10mm_hole_minus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(to_polygons(output), "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 18^2-12^2 mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx((18. * 18. - 12. * 12.) * s * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SECTION("Slic3r::variable_offset_outer()") {
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("miter " << miter << "x") {
|
||||
WHEN("plus 1mm") {
|
||||
output = Slic3r::variable_offset_outer_ex(box20mm, { deltas_plus, deltas_plus }, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("variable_offset_box20mm_10mm_hole_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(to_polygons(output), "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 22^2-8^2 mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx((22. * 22. - 8. * 8.) * s * s));
|
||||
}
|
||||
}
|
||||
WHEN("minus 1mm") {
|
||||
output = Slic3r::variable_offset_inner_ex(box20mm, { deltas_minus, deltas_minus }, miter);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("variable_offset_box20mm_10mm_hole_minus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(box20mm, "blue");
|
||||
svg.draw_outline(to_polygons(output), "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area is 18^2-12^2 mm2") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx((18. * 18. - 12. * 12.) * s * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("20mm right angle triangle") {
|
||||
ExPolygon triangle20mm;
|
||||
triangle20mm.contour.points = { { 0, 0 }, { 20 * s, 0 }, { 0, 20 * s} };
|
||||
Polygons output;
|
||||
double offset = 1.;
|
||||
// Angle of the sharp corner bisector.
|
||||
double angle_bisector = M_PI / 8.;
|
||||
// Area tapered by mitering one sharp corner.
|
||||
double area_tapered = pow(offset * (1. / sin(angle_bisector) - 1.), 2.) * tan(angle_bisector);
|
||||
double l_triangle_side_offsetted = 20. + offset * (1. + 1. / tan(angle_bisector));
|
||||
double area_offsetted = (0.5 * l_triangle_side_offsetted * l_triangle_side_offsetted - 2. * area_tapered) * s * s;
|
||||
SECTION("Slic3r::offset()") {
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("Outer offset 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::offset(triangle20mm, offset * s, ClipperLib::jtMiter, 2.0);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("constant_offset_triangle20mm_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(triangle20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area matches") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(area_offsetted));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SECTION("Slic3r::variable_offset_outer()") {
|
||||
std::vector<float> deltas(triangle20mm.contour.points.size(), 1. * s);
|
||||
for (double miter : { 2.0, 1.5, 1.2 }) {
|
||||
DYNAMIC_SECTION("Outer offset 1mm, miter " << miter << "x") {
|
||||
output = Slic3r::variable_offset_outer(triangle20mm, { deltas }, 2.0);
|
||||
#ifdef TESTS_EXPORT_SVGS
|
||||
{
|
||||
SVG svg(debug_out_path("variable_offset_triangle20mm_plus1mm_miter%lf.svg", miter).c_str(), get_extents(output));
|
||||
svg.draw(triangle20mm, "blue");
|
||||
svg.draw_outline(output, "black", coord_t(scale_(0.01)));
|
||||
}
|
||||
#endif
|
||||
THEN("Area matches") {
|
||||
REQUIRE(output.size() == 1);
|
||||
REQUIRE(output.front().area() == Approx(area_offsetted));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue