mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-02-05 02:11:52 +03:00
update test
This commit is contained in:
@@ -26,6 +26,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_stl.cpp
|
||||
test_meshboolean.cpp
|
||||
test_marchingsquares.cpp
|
||||
test_multiple_beds.cpp
|
||||
test_region_expansion.cpp
|
||||
test_timeutils.cpp
|
||||
test_utils.cpp
|
||||
|
||||
@@ -15,7 +15,8 @@ SCENARIO("Reading 3mf file", "[3mf]") {
|
||||
std::string path = std::string(TEST_DATA_DIR) + "/test_3mf/Geräte/Büchse.3mf";
|
||||
DynamicPrintConfig config;
|
||||
ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
|
||||
bool ret = load_3mf(path.c_str(), config, ctxt, &model, false);
|
||||
boost::optional<Semver> version;
|
||||
bool ret = load_3mf(path.c_str(), config, ctxt, &model, false, version);
|
||||
THEN("load should succeed") {
|
||||
REQUIRE(ret);
|
||||
}
|
||||
@@ -59,7 +60,8 @@ SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") {
|
||||
DynamicPrintConfig dst_config;
|
||||
{
|
||||
ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
|
||||
load_3mf(test_file.c_str(), dst_config, ctxt, &dst_model, false);
|
||||
boost::optional<Semver> version;
|
||||
load_3mf(test_file.c_str(), dst_config, ctxt, &dst_model, false, version);
|
||||
}
|
||||
boost::filesystem::remove(test_file);
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <random>
|
||||
|
||||
#include <libslic3r/ExtrusionEntity.hpp>
|
||||
#include <libslic3r/GCode/ExtrusionOrder.hpp>
|
||||
#include <libslic3r/GCode/SmoothPath.hpp>
|
||||
#include <libslic3r/Geometry/ArcWelder.hpp>
|
||||
#include <libslic3r/Geometry/Circle.hpp>
|
||||
#include <libslic3r/SVG.hpp>
|
||||
@@ -398,6 +401,122 @@ TEST_CASE("arc wedge test", "[ArcWelder]") {
|
||||
}
|
||||
}
|
||||
|
||||
// Distilled a test case for failing assert(p != prev) inside GCodeGenerator::_extrude() that is caused
|
||||
// by performing simplification of each ExtrusionPath in ExtrusionMultiPath one by one and not
|
||||
// simplifying ExtrusionMultiPath as a whole.
|
||||
TEST_CASE("ExtrusionMultiPath simplification", "[ArcWelderMultiPathSimplify][!mayfail]")
|
||||
{
|
||||
using namespace Slic3r::Geometry;
|
||||
using namespace Slic3r::GCode;
|
||||
|
||||
ExtrusionMultiPath multi_path;
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(3615254, 8843476), Point(5301926, 8703627), Point(5503271, 8717959),
|
||||
Point(5787717, 8834837), Point(7465587, 10084995), Point(7565376, 10117372)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0626713, 0.449999f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(7565376, 10117372), Point(7751661, 10097239)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0604367, 0.435101f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(7751661, 10097239), Point(11289346, 8638614), Point(11412324, 8600432)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0547566, 0.397234f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(11412324, 8600432), Point(11727623, 8578798)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.059829, 0.43105f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(11727623, 8578798), Point(12042923, 8557165)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0654324, 0.468406f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(12042923, 8557165), Point(12358223, 8535532), Point(12339460, 8545477)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0710358, 0.505762f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(12339460, 8545477), Point(12035789, 8689023)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0701369, 0.499769f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(12035789, 8689023), Point(11732119, 8832569)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0650101, 0.465591f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(11732119, 8832569), Point(11428449, 8976115)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0598834, 0.431413f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(11428449, 8976115), Point(7890375, 10433797)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0547566, 0.397234f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(7890375, 10433797), Point(7890196, 10433871)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0546036, 0.396214f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(7890196, 10433871), Point(7645162, 10520244)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0586375, 0.423107f, 0.15f), false));
|
||||
|
||||
multi_path.paths.emplace_back(Polyline({Point(7645162, 10520244), Point(7400129, 10606618), Point(6491466, 10980845),
|
||||
Point(3782930, 8968079)}),
|
||||
ExtrusionAttributes(ExtrusionRole::SolidInfill, ExtrusionFlow(0.0626713, 0.449999f, 0.15f), false));
|
||||
|
||||
const double resolution = 8000.;
|
||||
SmoothPathCache smooth_path_cache;
|
||||
SmoothPath smooth_path = smooth_path_cache.resolve_or_fit(multi_path, false, resolution);
|
||||
|
||||
double min_segment_length = std::numeric_limits<double>::max();
|
||||
for (const SmoothPathElement &el : smooth_path) {
|
||||
assert(el.path.size() > 1);
|
||||
Point prev_pt = el.path.front().point;
|
||||
|
||||
for (auto segment_it = std::next(el.path.begin()); segment_it != el.path.end(); ++segment_it) {
|
||||
if (const double length = (segment_it->point - prev_pt).cast<double>().norm(); length < min_segment_length) {
|
||||
min_segment_length = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(min_segment_length >= resolution);
|
||||
}
|
||||
|
||||
TEST_CASE("SmoothPath clipping test", "[ArcWelder]") {
|
||||
using namespace Slic3r::Geometry;
|
||||
|
||||
const Polyline polyline = {
|
||||
Point(9237362, -279099), Point(9239309, -204770), Point(9232158, 477899), Point(9153712, 1292530),
|
||||
Point(9014384, 2036579), Point(8842322, 2697128), Point(8569131, 3468590), Point(8287136, 4090253),
|
||||
Point(8050736, 4537759), Point(7786167, 4978071), Point(7502123, 5396751), Point(7085512, 5937730),
|
||||
Point(6536631, 6536722), Point(5937701, 7085536), Point(5336389, 7545178), Point(4766354, 7921046),
|
||||
Point(4287299, 8181151), Point(3798566, 8424823), Point(3161891, 8687141), Point(2477384, 8903260),
|
||||
Point(1985727, 9025657), Point(1488659, 9120891), Point(811611, 9208824), Point(229795, 9234222),
|
||||
Point(-477899, 9232158), Point(-1292541, 9153710), Point(-1963942, 9030487), Point(-2483966, 8901437),
|
||||
Point(-2967612, 8752145), Point(-3606656, 8511944), Point(-4098726, 8277235), Point(-4583048, 8025111),
|
||||
Point(-5164553, 7667365), Point(-5602853, 7343037), Point(-6030084, 7003203), Point(-6532687, 6541035),
|
||||
Point(-7085558, 5937673), Point(-7502041, 5396860), Point(-7802209, 4952884), Point(-8061668, 4518435),
|
||||
Point(-8375899, 3912214), Point(-8689042, 3156205), Point(-8915304, 2433948), Point(-9073554, 1769674),
|
||||
Point(-9194504, 960323), Point(-9238723, 227049), Point(-9237360, -279112), Point(-9194498, -960380),
|
||||
Point(-9073524, -1769810), Point(-8895452, -2505523), Point(-8689032, -3156238), Point(-8375859, -3912298),
|
||||
Point(-8025112, -4583044), Point(-7667378, -5164532), Point(-7180536, -5822455), Point(-6729193, -6334406),
|
||||
Point(-6350620, -6713810), Point(-5973693, -7051366), Point(-5438560, -7475505), Point(-4756170, -7927163),
|
||||
Point(-4110103, -8277232), Point(-3651006, -8489813), Point(-3015355, -8738921), Point(-2492584, -8893770),
|
||||
Point(-1963947, -9030483), Point(-1286636, -9154696), Point(-590411, -9222659), Point(14602, -9244383),
|
||||
Point(974789, -9192915), Point(1634833, -9095889), Point(2193590, -8977466), Point(2851102, -8793883),
|
||||
Point(3612042, -8509372), Point(4098709, -8277242), Point(4583076, -8025095), Point(5164577, -7667349),
|
||||
Point(5822437, -7180551), Point(6388368, -6677987), Point(6866030, -6190211), Point(7236430, -5740880),
|
||||
Point(7660739, -5174380), Point(8088357, -4476558), Point(8394013, -3866175), Point(8593000, -3400880),
|
||||
Point(8768650, -2918284), Point(8915319, -2433894), Point(9073549, -1769711), Point(9194508, -960282),
|
||||
Point(9237362, -279099)
|
||||
};
|
||||
|
||||
const ExtrusionAttributes extrusion_attributes(ExtrusionRole::Perimeter, ExtrusionFlow{1.0, 1.0, 1.0});
|
||||
const GCode::SmoothPath smooth_path = {GCode::SmoothPathElement{extrusion_attributes, ArcWelder::fit_path(polyline.points, 32000., 0.05)}};
|
||||
const double smooth_path_length = GCode::length(smooth_path);
|
||||
|
||||
const size_t clip_segment_cnt = 20;
|
||||
for (size_t segment_idx = 1; segment_idx <= clip_segment_cnt; ++segment_idx) {
|
||||
const double clip_length = static_cast<double>(segment_idx) * (smooth_path_length / (clip_segment_cnt + 1));
|
||||
GCode::SmoothPath smooth_path_clipped = smooth_path;
|
||||
|
||||
clip_end(smooth_path_clipped, smooth_path_length - clip_length, scaled<double>(GCode::ExtrusionOrder::min_gcode_segment_length));
|
||||
|
||||
const double smooth_path_clipped_length = GCode::length(smooth_path_clipped);
|
||||
const double relative_diff = std::abs(1. - (clip_length / smooth_path_clipped_length));
|
||||
REQUIRE(relative_diff <= 0.000001);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// For quantization
|
||||
//#include <libslic3r/GCode/GCodeWriter.hpp>
|
||||
|
||||
@@ -103,12 +103,13 @@ std::string get_font_filepath() {
|
||||
|
||||
// Explicit horror include (used to be implicit) - libslic3r "officialy" does not depend on imgui.
|
||||
#include "../../bundled_deps/imgui/imgui/imstb_truetype.h" // stbtt_fontinfo
|
||||
#include "boost/nowide/cstdio.hpp"
|
||||
TEST_CASE("Read glyph C shape from font, stb library calls ONLY", "[Emboss]") {
|
||||
std::string font_path = get_font_filepath();
|
||||
char letter = 'C';
|
||||
|
||||
// Read font file
|
||||
FILE *file = fopen(font_path.c_str(), "rb");
|
||||
FILE *file = boost::nowide::fopen(font_path.c_str(), "rb");
|
||||
REQUIRE(file != nullptr);
|
||||
// find size of file
|
||||
REQUIRE(fseek(file, 0L, SEEK_END) == 0);
|
||||
|
||||
35
tests/libslic3r/test_multiple_beds.cpp
Normal file
35
tests/libslic3r/test_multiple_beds.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <libslic3r/MultipleBeds.hpp>
|
||||
#include <numeric>
|
||||
|
||||
using namespace Slic3r;
|
||||
TEST_CASE("Conversion between grid coords and index", "[MultipleBeds]")
|
||||
{
|
||||
std::vector<BedsGrid::Index> original_indices(10);
|
||||
std::iota(original_indices.begin(), original_indices.end(), 0);
|
||||
|
||||
// Add indexes covering the whole int positive range.
|
||||
const int n{100};
|
||||
std::generate_n(std::back_inserter(original_indices), n, [i = 1]() mutable {
|
||||
return std::numeric_limits<int>::max() / n * i++;
|
||||
});
|
||||
|
||||
std::vector<BedsGrid::GridCoords> coords;
|
||||
std::transform(
|
||||
original_indices.begin(),
|
||||
original_indices.end(),
|
||||
std::back_inserter(coords),
|
||||
BedsGrid::index2grid_coords
|
||||
);
|
||||
|
||||
std::vector<BedsGrid::Index> indices;
|
||||
std::transform(
|
||||
coords.begin(),
|
||||
coords.end(),
|
||||
std::back_inserter(indices),
|
||||
BedsGrid::grid_coords2index
|
||||
);
|
||||
|
||||
CHECK(original_indices == indices);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ TEST_CASE("Distance to line", "[Point]") {
|
||||
|
||||
TEST_CASE("Distance to diagonal line", "[Point]") {
|
||||
const Line line{{50, 50}, {125, -25}};
|
||||
CHECK(std::abs(line.distance_to(Point{100, 0})) == Approx(0));
|
||||
CHECK_THAT(std::abs(line.distance_to(Point{100, 0})), Catch::Matchers::WithinAbs(0, 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("Perp distance to line does not overflow", "[Point]") {
|
||||
|
||||
@@ -78,14 +78,14 @@ SCENARIO("Simplify polyne, template", "[Polyline]")
|
||||
Points polyline{ {0,0}, {1000,0}, {2000,0}, {2000,1000}, {2000,2000}, {1000,2000}, {0,2000}, {0,1000}, {0,0} };
|
||||
WHEN("simplified with Douglas-Peucker with back inserter") {
|
||||
Points out;
|
||||
douglas_peucker<int64_t>(polyline.begin(), polyline.end(), std::back_inserter(out), 10, [](const Point &p) { return p; });
|
||||
douglas_peucker<int64_t>(polyline.begin(), polyline.end(), std::back_inserter(out), 10., [](const Point &p) { return p; });
|
||||
THEN("simplified correctly") {
|
||||
REQUIRE(out == Points{ {0,0}, {2000,0}, {2000,2000}, {0,2000}, {0,0} });
|
||||
}
|
||||
}
|
||||
WHEN("simplified with Douglas-Peucker in place") {
|
||||
Points out{ polyline };
|
||||
out.erase(douglas_peucker<int64_t>(out.begin(), out.end(), out.begin(), 10, [](const Point &p) { return p; }), out.end());
|
||||
out.erase(douglas_peucker<int64_t>(out.begin(), out.end(), out.begin(), 10., [](const Point &p) { return p; }), out.end());
|
||||
THEN("simplified correctly") {
|
||||
REQUIRE(out == Points{ {0,0}, {2000,0}, {2000,2000}, {0,2000}, {0,0} });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user