mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 12:25:54 +08:00
tests from mainline
some cleaning in Medial axis.
This commit is contained in:
parent
1bf0b1c1d7
commit
36bb57c6a8
@ -112,6 +112,7 @@ MedialAxis::polyline_from_voronoi(const Lines& voronoi_edges, ThickPolylines* po
|
||||
assert(polyline.width.size() == polyline.points.size());
|
||||
|
||||
// if loop, set endpoints to false
|
||||
// prevent loop endpoints from being extended
|
||||
if (polyline.first_point().coincides_with(polyline.last_point())) {
|
||||
polyline.endpoints.first = false;
|
||||
polyline.endpoints.second = false;
|
||||
@ -511,8 +512,6 @@ MedialAxis::fusion_curve(ThickPolylines &pp)
|
||||
}
|
||||
}
|
||||
sum_dot = abs(sum_dot);
|
||||
//std::cout << " with mindot= " << min_dot << "< 0.5" << " ; with sum_dot= " << sum_dot << "< 0.2" << " ; with crosspoint.size= " << crosspoint.size() << " ; with coeff_contour_angle= " << coeff_contour_angle << " 0.2> " << (1 - (coeff_contour_angle / (PI / 2)))
|
||||
//<< " ; length= " << unscaled(polyline.length())<<" >? 1.42*width= "<< polyline.width.front()<<"->"<< polyline.width.back() << "\n";
|
||||
|
||||
//only consider very shallow angle for contour
|
||||
if (mindot > 0.15 &&
|
||||
@ -640,7 +639,7 @@ MedialAxis::fusion_corners(ThickPolylines &pp)
|
||||
|
||||
void
|
||||
MedialAxis::extends_line_both_side(ThickPolylines& pp) {
|
||||
const ExPolygons anchors = offset2_ex(diff_ex(*this->bounds, this->expolygon), double(-SCALED_RESOLUTION), double(SCALED_RESOLUTION));
|
||||
const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(*this->bounds, this->expolygon)), double(-SCALED_RESOLUTION), double(SCALED_RESOLUTION));
|
||||
for (size_t i = 0; i < pp.size(); ++i) {
|
||||
ThickPolyline& polyline = pp[i];
|
||||
this->extends_line(polyline, anchors, this->min_width);
|
||||
|
@ -227,8 +227,9 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
|
||||
|| opt_key == "extra_loading_move"
|
||||
|| opt_key == "z_offset") {
|
||||
steps.emplace_back(psWipeTower);
|
||||
} else if (
|
||||
opt_key == "first_layer_extrusion_width"
|
||||
}
|
||||
else if (
|
||||
opt_key == "first_layer_extrusion_width"
|
||||
|| opt_key == "min_layer_height"
|
||||
|| opt_key == "max_layer_height") {
|
||||
osteps.emplace_back(posPerimeters);
|
||||
@ -236,7 +237,20 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
|
||||
osteps.emplace_back(posSupportMaterial);
|
||||
steps.emplace_back(psSkirt);
|
||||
steps.emplace_back(psBrim);
|
||||
} else {
|
||||
}
|
||||
else if (opt_key == "posSlice")
|
||||
osteps.emplace_back(posSlice);
|
||||
else if (opt_key == "posPerimeters")
|
||||
osteps.emplace_back(posPerimeters);
|
||||
else if (opt_key == "posPrepareInfill")
|
||||
osteps.emplace_back(posPrepareInfill);
|
||||
else if (opt_key == "posInfill")
|
||||
osteps.emplace_back(posInfill);
|
||||
else if (opt_key == "posSupportMaterial")
|
||||
osteps.emplace_back(posSupportMaterial);
|
||||
else if (opt_key == "posCount")
|
||||
osteps.emplace_back(posCount);
|
||||
else {
|
||||
// for legacy, if we can't handle this option let's invalidate all steps
|
||||
//FIXME invalidate all steps of all objects as well?
|
||||
invalidated |= this->invalidate_all_steps();
|
||||
|
@ -374,6 +374,8 @@ public:
|
||||
// Accessed by SupportMaterial
|
||||
const PrintRegion* get_region(size_t idx) const { return m_regions[idx]; }
|
||||
|
||||
//put this in public to be accessible for tests, it was in private before.
|
||||
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
||||
protected:
|
||||
// methods for handling regions
|
||||
PrintRegion* get_region(size_t idx) { return m_regions[idx]; }
|
||||
@ -391,8 +393,6 @@ private:
|
||||
DynamicPrintConfig &placeholder_parser_overrides,
|
||||
DynamicPrintConfig &filament_overrides) const;
|
||||
|
||||
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
||||
|
||||
void _make_skirt(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out);
|
||||
ExPolygons _make_brim(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out);
|
||||
ExPolygons _make_brim_ears(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out);
|
||||
|
@ -111,3 +111,30 @@ SCENARIO("lift() is not ignored after unlift() at normal values of Z") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("set_speed emits values with fixed-point output.") {
|
||||
|
||||
GIVEN("GCodeWriter instance") {
|
||||
GCodeWriter writer;
|
||||
WHEN("set_speed is called to set speed to 1.09321e+06") {
|
||||
THEN("Output string is G1 F1093210.000") {
|
||||
REQUIRE_THAT(writer.set_speed(1.09321e+06), Catch::Equals("G1 F1093210.000\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 1") {
|
||||
THEN("Output string is G1 F1.000") {
|
||||
REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1.000\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 203.200022") {
|
||||
THEN("Output string is G1 F203.200") {
|
||||
REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.200\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 203.200522") {
|
||||
THEN("Output string is G1 F203.200") {
|
||||
REQUIRE_THAT(writer.set_speed(203.200522), Catch::Equals("G1 F203.201\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ SCENARIO("xy compensations"){
|
||||
Point{ 200, 200 },
|
||||
Point{ 100, 200 }} };
|
||||
THEN("elephant and xy can compensate each other"){
|
||||
//TODO
|
||||
}
|
||||
THEN("hole and xy can compensate each othere"){
|
||||
}
|
||||
|
@ -68,10 +68,59 @@ SCENARIO("Print: Skirt generation") {
|
||||
}
|
||||
}
|
||||
|
||||
void test_is_solid_infill(Print &p, size_t obj_id, size_t layer_id ) {
|
||||
const PrintObject& obj { *(p.objects().at(obj_id)) };
|
||||
const Layer& layer { *(obj.get_layer(layer_id)) };
|
||||
|
||||
// iterate over all of the regions in the layer
|
||||
for (const LayerRegion* reg : layer.regions()) {
|
||||
// for each region, iterate over the fill surfaces
|
||||
for (const Surface& s : reg->fill_surfaces.surfaces) {
|
||||
CHECK(s.has_fill_solid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces to become internal.") {
|
||||
GIVEN("sliced 20mm cube and config with top_solid_surfaces = 2 and bottom_solid_surfaces = 1") {
|
||||
DynamicPrintConfig *config = Slic3r::DynamicPrintConfig::new_from_defaults();
|
||||
TestMesh m { TestMesh::cube_20x20x20 };
|
||||
config->set_key_value("top_solid_layers", new ConfigOptionInt(2));
|
||||
config->set_key_value("bottom_solid_layers", new ConfigOptionInt(1));
|
||||
config->set_key_value("layer_height", new ConfigOptionFloat(0.5)); // get a known number of layers
|
||||
config->set_key_value("first_layer_height", new ConfigOptionFloat(0.5));
|
||||
Slic3r::Model model;
|
||||
auto event_counter {0U};
|
||||
std::string stage;
|
||||
Print print{};
|
||||
Slic3r::Test::init_print(print, { m }, model, config);
|
||||
print.process();
|
||||
// Precondition: Ensure that the model has 2 solid top layers (39, 38)
|
||||
// and one solid bottom layer (0).
|
||||
test_is_solid_infill(print, 0, 0); // should be solid
|
||||
test_is_solid_infill(print, 0, 39); // should be solid
|
||||
test_is_solid_infill(print, 0, 38); // should be solid
|
||||
WHEN("Model is re-sliced with top_solid_layers == 3") {
|
||||
((ConfigOptionInt&)(print.regions()[0]->config().top_solid_layers)).value = 3;
|
||||
print.invalidate_state_by_config_options(std::vector<Slic3r::t_config_option_key>{ "posPrepareInfill" });
|
||||
print.process();
|
||||
THEN("Print object does not have 0 solid bottom layers.") {
|
||||
test_is_solid_infill(print, 0, 0);
|
||||
}
|
||||
AND_THEN("Print object has 3 top solid layers") {
|
||||
test_is_solid_infill(print, 0, 39);
|
||||
test_is_solid_infill(print, 0, 38);
|
||||
test_is_solid_infill(print, 0, 37);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SCENARIO("Print: Brim generation") {
|
||||
GIVEN("20mm cube and default config, 1mm first layer width") {
|
||||
DynamicPrintConfig *config = Slic3r::DynamicPrintConfig::new_from_defaults();
|
||||
TestMesh m = TestMesh::cube_20x20x20;
|
||||
TestMesh m{ TestMesh::cube_20x20x20 };
|
||||
Slic3r::Model model{};
|
||||
config->set_key_value("first_layer_extrusion_width", new ConfigOptionFloatOrPercent(1, false));
|
||||
WHEN("Brim is set to 3mm") {
|
||||
|
@ -224,6 +224,50 @@ SCENARIO( "PrintGCode basic functionality") {
|
||||
REQUIRE(exported.find("; Layer_z 20") != std::string::npos);
|
||||
}
|
||||
}
|
||||
WHEN("current_extruder exists in start_gcode") {
|
||||
config->set("start_gcode", "; Extruder [current_extruder]");
|
||||
{
|
||||
Slic3r::Model model;
|
||||
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)};
|
||||
Slic3r::Test::gcode(gcode, print);
|
||||
auto exported {gcode.str()};
|
||||
THEN("current_extruder is processed in the start gcode and set for first extruder") {
|
||||
REQUIRE(exported.find("; Extruder 0") != std::string::npos);
|
||||
}
|
||||
}
|
||||
config->set("solid_infill_extruder", 2);
|
||||
config->set("support_material_extruder", 2);
|
||||
config->set("infill_extruder", 2);
|
||||
config->set("perimeter_extruder", 2);
|
||||
{
|
||||
Slic3r::Model model;
|
||||
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)};
|
||||
Slic3r::Test::gcode(gcode, print);
|
||||
auto exported {gcode.str()};
|
||||
THEN("current_extruder is processed in the start gcode and set for second extruder") {
|
||||
REQUIRE(exported.find("; Extruder 1") != std::string::npos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("layer_num represents the layer's index from z=0") {
|
||||
config->set("layer_gcode", ";Layer:[layer_num] ([layer_z] mm)");
|
||||
config->set("layer_height", 1.0);
|
||||
config->set("first_layer_height", 1.0);
|
||||
|
||||
Slic3r::Model model;
|
||||
auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20,TestMesh::cube_20x20x20}, model, config)};
|
||||
Slic3r::Test::gcode(gcode, print);
|
||||
|
||||
auto exported {gcode.str()};
|
||||
int count = 2;
|
||||
for(int pos = 0; pos != std::string::npos; count--)
|
||||
pos = exported.find(";Layer:38 (20 mm)", pos+1);
|
||||
|
||||
THEN("layer_num and layer_z are processed in the end gcode") {\
|
||||
REQUIRE(count == -1);
|
||||
}
|
||||
}
|
||||
|
||||
gcode.clear();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user