diff --git a/benchmark/infill_benchmark.h b/benchmark/infill_benchmark.h index a6a52b817a..4799e5f5cb 100644 --- a/benchmark/infill_benchmark.h +++ b/benchmark/infill_benchmark.h @@ -6,6 +6,7 @@ #include +#include "geometry/open_lines_set.h" #include "infill.h" namespace cura @@ -58,8 +59,8 @@ class InfillTest : public benchmark::Fixture ff_holes.back().emplace_back(MM2INT(60), MM2INT(40)); ff_holes.back().emplace_back(MM2INT(90), MM2INT(25)); - outline_polygons.add(square_shape); - outline_polygons.add(ff_holes); + outline_polygons.push_back(square_shape); + outline_polygons.push_back(ff_holes); settings.add("fill_outline_gaps", "false"); settings.add("meshfix_maximum_deviation", "0.1"); @@ -93,29 +94,30 @@ class InfillTest : public benchmark::Fixture BENCHMARK_DEFINE_F(InfillTest, Infill_generate_connect)(benchmark::State& st) { - Infill infill(pattern, - zig_zagify, - connect_polygons, - outline_polygons, - INFILL_LINE_WIDTH, - line_distance, - INFILL_OVERLAP, - INFILL_MULTIPLIER, - FILL_ANGLE, - Z, - SHIFT, - MAX_RESOLUTION, - MAX_DEVIATION); // There are some optional parameters, but these will do for now (future improvement?). + Infill infill( + pattern, + zig_zagify, + connect_polygons, + outline_polygons, + INFILL_LINE_WIDTH, + line_distance, + INFILL_OVERLAP, + INFILL_MULTIPLIER, + FILL_ANGLE, + Z, + SHIFT, + MAX_RESOLUTION, + MAX_DEVIATION); // There are some optional parameters, but these will do for now (future improvement?). for (auto _ : st) { std::vector result_paths; Shape result_polygons; - Shape result_lines; + OpenLinesSet result_lines; infill.generate(result_paths, result_polygons, result_lines, settings, 0, SectionType::INFILL, nullptr, nullptr); } } -BENCHMARK_REGISTER_F(InfillTest, Infill_generate_connect)->ArgsProduct({{true, false}, {400, 800, 1200}})->Unit(benchmark::kMillisecond); +BENCHMARK_REGISTER_F(InfillTest, Infill_generate_connect)->ArgsProduct({ { true, false }, { 400, 800, 1200 } })->Unit(benchmark::kMillisecond); } // namespace cura #endif // CURAENGINE_INFILL_BENCHMARK_H diff --git a/benchmark/wall_benchmark.h b/benchmark/wall_benchmark.h index 6b43a4255e..95d99d6a90 100644 --- a/benchmark/wall_benchmark.h +++ b/benchmark/wall_benchmark.h @@ -4,21 +4,20 @@ #ifndef CURAENGINE_WALL_BENCHMARK_H #define CURAENGINE_WALL_BENCHMARK_H +#include +#include +#include +#include #include -#include #include +#include #include "InsetOrderOptimizer.h" #include "WallsComputation.h" +#include "geometry/polygon.h" #include "settings/Settings.h" #include "sliceDataStorage.h" -#include "geometry/polygon.h" - -#include -#include -#include -#include namespace cura { @@ -85,7 +84,7 @@ class WallTestFixture : public benchmark::Fixture layer.parts.emplace_back(); SliceLayerPart& part = layer.parts.back(); - part.outline.add(ff_holes); + part.outline.push_back(ff_holes); } void TearDown(const ::benchmark::State& state) @@ -145,7 +144,7 @@ class HolesWallTestFixture : public benchmark::Fixture layer.parts.emplace_back(); SliceLayerPart& part = layer.parts.back(); - part.outline.add(shape.paths.front()); + part.outline.push_back(shape.front()); part.print_outline = shape; } @@ -168,7 +167,7 @@ BENCHMARK_DEFINE_F(WallTestFixture, InsetOrderOptimizer_getRegionOrder)(benchmar { walls_computation.generateWalls(&layer, SectionType::WALL); std::vector all_paths; - for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join ) + for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join) { all_paths.emplace_back(line); } @@ -184,7 +183,7 @@ BENCHMARK_DEFINE_F(WallTestFixture, InsetOrderOptimizer_getInsetOrder)(benchmark { walls_computation.generateWalls(&layer, SectionType::WALL); std::vector all_paths; - for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join ) + for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join) { all_paths.emplace_back(line); } @@ -210,7 +209,7 @@ BENCHMARK_DEFINE_F(HolesWallTestFixture, InsetOrderOptimizer_getRegionOrder)(ben { walls_computation.generateWalls(&layer, SectionType::WALL); std::vector all_paths; - for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join ) + for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join) { all_paths.emplace_back(line); } @@ -226,7 +225,7 @@ BENCHMARK_DEFINE_F(HolesWallTestFixture, InsetOrderOptimizer_getInsetOrder)(benc { walls_computation.generateWalls(&layer, SectionType::WALL); std::vector all_paths; - for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join ) + for (auto& line : layer.parts.back().wall_toolpaths | ranges::views::join) { all_paths.emplace_back(line); } diff --git a/include/geometry/lines_set.h b/include/geometry/lines_set.h index 6562112ddd..f012eaccf7 100644 --- a/include/geometry/lines_set.h +++ b/include/geometry/lines_set.h @@ -6,6 +6,8 @@ #include +#include + #include "geometry/point2ll.h" namespace cura @@ -25,6 +27,10 @@ class LinesSet private: std::vector lines_; +public: + // Requires for some std calls as a container + typedef LineType value_type; + public: LinesSet() = default; @@ -226,6 +232,29 @@ class LinesSet void addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType PolyTyp) const; void addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType jointType, ClipperLib::EndType endType) const; + + /*! + * \brief Display operator, useful for debugging/testing + */ + template + friend std::basic_ostream& operator<<(std::basic_ostream& os, const LinesSet& lines) + { + os << "LinesSet["; + + for (const LineType& line : lines | ranges::views::drop(1)) + { + os << line; + os << ", "; + } + + if (lines.size() > 1) + { + os << lines.back(); + } + + os << "]"; + return os; + } }; } // namespace cura diff --git a/include/geometry/points_set.h b/include/geometry/points_set.h index 3eb151fd59..73d4673c73 100644 --- a/include/geometry/points_set.h +++ b/include/geometry/points_set.h @@ -24,6 +24,10 @@ class PointsSet private: ClipperLib::Path points_; +public: + // Requires for some std calls as a container + typedef Point2LL value_type; + public: PointsSet() = default; @@ -195,6 +199,15 @@ class PointsSet */ void applyMatrix(const PointMatrix& matrix); void applyMatrix(const Point3Matrix& matrix); + + /*! + * \brief Display operator, useful for debugging/testing + */ + template + friend std::basic_ostream& operator<<(std::basic_ostream& os, const PointsSet& polygon) + { + return os << "PointsSet(" << polygon.getPoints() << ")"; + } }; } // namespace cura diff --git a/include/geometry/shape.h b/include/geometry/shape.h index 16bfb8d59b..6cce47e5e6 100644 --- a/include/geometry/shape.h +++ b/include/geometry/shape.h @@ -286,6 +286,21 @@ class Shape : public LinesSet */ void simplify(ClipperLib::PolyFillType fill_type = ClipperLib::pftEvenOdd); +#ifdef BUILD_TESTS + /*! + * @brief Import the polygon from a WKT string + * @param wkt The WKT string to read from + * @return Polygons The polygons read from the stream + */ + [[maybe_unused]] static Shape fromWkt(const std::string& wkt); + + /*! + * @brief Export the polygon to a WKT string + * @param stream The stream to write to + */ + [[maybe_unused]] void writeWkt(std::ostream& stream) const; +#endif + private: /*! * recursive part of \ref Polygons::removeEmptyHoles and \ref Polygons::getEmptyHoles diff --git a/include/utils/polygonUtils.h b/include/utils/polygonUtils.h index 159d27d7b6..6ece6b6561 100644 --- a/include/utils/polygonUtils.h +++ b/include/utils/polygonUtils.h @@ -228,7 +228,7 @@ class PolygonUtils * the polygon. * \return Always returns 0. */ - static unsigned int moveInside(const Polygon& polygon, Point2LL& from, int distance = 0, int64_t max_dist2 = std::numeric_limits::max()); + static unsigned int moveInside(const ClosedPolyline& polygon, Point2LL& from, int distance = 0, int64_t max_dist2 = std::numeric_limits::max()); /*! * Moves the point \p from onto the nearest polygon or leaves the point as-is, when the comb boundary is not within the root of \p max_dist2 distance. diff --git a/src/geometry/shape.cpp b/src/geometry/shape.cpp index e0d893eef6..0051cc26f9 100644 --- a/src/geometry/shape.cpp +++ b/src/geometry/shape.cpp @@ -7,6 +7,19 @@ #include #include +#ifdef BUILD_TESTS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include #include @@ -916,6 +929,59 @@ void Shape::applyMatrix(const Point3Matrix& matrix) } } +#ifdef BUILD_TESTS +[[maybe_unused]] Shape Shape::fromWkt(const std::string& wkt) +{ + typedef boost::geometry::model::d2::point_xy point_type; + typedef boost::geometry::model::polygon polygon_type; + + polygon_type poly; + boost::geometry::read_wkt(wkt, poly); + + Shape ret; + + Polygon outer; + for (const auto& point : poly.outer()) + { + outer.emplace_back(point.x(), point.y()); + } + ret.push_back(outer); + + for (const auto& hole : poly.inners()) + { + Polygon inner; + for (const auto& point : hole) + { + inner.emplace_back(point.x(), point.y()); + } + ret.push_back(inner); + } + + return ret; +} + +[[maybe_unused]] void Shape::writeWkt(std::ostream& stream) const +{ + stream << "POLYGON ("; + const auto paths_str = getLines() + | ranges::views::transform( + [](const Polygon& path) + { + const auto line_string = ranges::views::concat(path, path | ranges::views::take(1)) + | ranges::views::transform( + [](const Point2LL& point) + { + return fmt::format("{} {}", point.X, point.Y); + }) + | ranges::views::join(ranges::views::c_str(", ")) | ranges::to(); + return "(" + line_string + ")"; + }) + | ranges::views::join(ranges::views::c_str(", ")) | ranges::to(); + stream << paths_str; + stream << ")"; +} +#endif + template LinesSet Shape::intersection(const LinesSet& polylines, bool restitch, const coord_t max_stitch_distance) const; template LinesSet Shape::intersection(const LinesSet& polylines, bool restitch, const coord_t max_stitch_distance) const; template LinesSet Shape::intersection(const LinesSet& polylines, bool restitch, const coord_t max_stitch_distance) const; diff --git a/src/utils/polygonUtils.cpp b/src/utils/polygonUtils.cpp index e4371f5d6d..b6edcae9e2 100644 --- a/src/utils/polygonUtils.cpp +++ b/src/utils/polygonUtils.cpp @@ -451,7 +451,7 @@ size_t PolygonUtils::moveInside(const Shape& polygons, Point2LL& from, int dista } // Version that works on single PolygonRef. -unsigned int PolygonUtils::moveInside(const Polygon& polygon, Point2LL& from, int distance, int64_t maxDist2) +unsigned int PolygonUtils::moveInside(const ClosedPolyline &polygon, Point2LL& from, int distance, int64_t maxDist2) { // TODO: This is copied from the moveInside of Polygons. /* diff --git a/stress_benchmark/stress_benchmark.cpp b/stress_benchmark/stress_benchmark.cpp index a55ee0a6f2..3562e20ae0 100644 --- a/stress_benchmark/stress_benchmark.cpp +++ b/stress_benchmark/stress_benchmark.cpp @@ -20,12 +20,12 @@ #include #include "WallsComputation.h" +#include "geometry/polygon.h" #include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" #include "settings/Settings.h" #include "sliceDataStorage.h" -#include "geometry/polygon.h" constexpr std::string_view USAGE = R"(Stress Benchmark. @@ -80,18 +80,18 @@ struct Resource cura::Polygon outer; for (const auto& point : boost_polygon.outer()) { - outer.add(cura::Point2LL(point.x(), point.y())); + outer.push_back(cura::Point2LL(point.x(), point.y())); } - polygon.add(outer); + polygon.push_back(outer); for (const auto& hole : boost_polygon.inners()) { cura::Polygon inner; for (const auto& point : hole) { - inner.add(cura::Point2LL(point.x(), point.y())); + inner.push_back(cura::Point2LL(point.x(), point.y())); } - polygon.add(inner); + polygon.push_back(inner); } polygons.push_back(polygon); @@ -149,7 +149,7 @@ void handleChildProcess(const auto& shapes, const auto& settings) { layer.parts.emplace_back(); cura::SliceLayerPart& part = layer.parts.back(); - part.outline.add(shape); + part.outline.push_back(shape); } cura::LayerIndex layer_idx(100); cura::WallsComputation walls_computation(settings, layer_idx); diff --git a/tests/InfillTest.cpp b/tests/InfillTest.cpp index 8f9866e9ee..dc2f20e2dd 100644 --- a/tests/InfillTest.cpp +++ b/tests/InfillTest.cpp @@ -76,7 +76,7 @@ class InfillTestParameters Shape outline_polygons; // Resulting infill: - Shape result_lines; + OpenLinesSet result_lines; Shape result_polygons; std::string name; @@ -89,7 +89,7 @@ class InfillTestParameters { } - InfillTestParameters(const InfillParameters& params, const size_t& test_polygon_id, Shape outline_polygons, Shape result_lines, Shape result_polygons) + InfillTestParameters(const InfillParameters& params, const size_t& test_polygon_id, Shape outline_polygons, OpenLinesSet result_lines, Shape result_polygons) : valid(true) , fail_reason("__") , params(params) @@ -177,7 +177,7 @@ InfillTestParameters generateInfillToTest(const InfillParameters& params, const Settings infill_settings; std::vector result_paths; Shape result_polygons; - Shape result_lines; + OpenLinesSet result_lines; infill.generate(result_paths, result_polygons, result_lines, infill_settings, 1, SectionType::INFILL, nullptr, nullptr); InfillTestParameters result = InfillTestParameters(params, test_polygon_id, outline_polygons, result_lines, result_polygons); @@ -267,7 +267,7 @@ TEST_P(InfillTest, TestInfillSanity) long double worst_case_zig_zag_added_area = 0; if (params.params.zig_zagify || params.params.pattern == EFillMethod::ZIG_ZAG) { - worst_case_zig_zag_added_area = params.outline_polygons.polygonLength() * INFILL_LINE_WIDTH; + worst_case_zig_zag_added_area = params.outline_polygons.length() * INFILL_LINE_WIDTH; } const double min_available_area = std::abs(params.outline_polygons.offset(static_cast(-params.params.line_distance) / 2).area()); @@ -275,8 +275,8 @@ TEST_P(InfillTest, TestInfillSanity) const long double min_expected_infill_area = (min_available_area * static_cast(INFILL_LINE_WIDTH)) / params.params.line_distance; const long double max_expected_infill_area = (max_available_area * INFILL_LINE_WIDTH) / params.params.line_distance + worst_case_zig_zag_added_area; - const long double out_infill_area = ((params.result_polygons.polygonLength() + params.result_lines.polyLineLength()) * static_cast(INFILL_LINE_WIDTH)) - / getPatternMultiplier(params.params.pattern); + const long double out_infill_area + = ((params.result_polygons.length() + params.result_lines.length()) * static_cast(INFILL_LINE_WIDTH)) / getPatternMultiplier(params.params.pattern); ASSERT_GT((coord_t)max_available_area, (coord_t)out_infill_area) << "Infill area should allways be less than the total area available."; ASSERT_GT((coord_t)out_infill_area, (coord_t)min_expected_infill_area) << "Infill area should be greater than the minimum area expected to be covered."; @@ -285,14 +285,14 @@ TEST_P(InfillTest, TestInfillSanity) const coord_t maximum_error = 10_mu; // potential rounding error const Shape padded_shape_outline = params.outline_polygons.offset(INFILL_LINE_WIDTH / 2); constexpr bool restitch = false; // No need to restitch polylines - that would introduce stitching errors. - ASSERT_LE(std::abs(padded_shape_outline.intersectionPolyLines(params.result_lines, restitch).polyLineLength() - params.result_lines.polyLineLength()), maximum_error) + ASSERT_LE(std::abs(padded_shape_outline.intersection(params.result_lines, restitch).length() - params.result_lines.length()), maximum_error) << "Infill (lines) should not be outside target polygon."; Shape result_polygon_lines = params.result_polygons; for (Polygon& poly : result_polygon_lines) { poly.push_back(poly.front()); } - ASSERT_LE(std::abs(padded_shape_outline.intersectionPolyLines(result_polygon_lines, restitch).polyLineLength() - result_polygon_lines.polyLineLength()), maximum_error) + ASSERT_LE(std::abs(padded_shape_outline.intersection(result_polygon_lines, restitch).length() - result_polygon_lines.length()), maximum_error) << "Infill (lines) should not be outside target polygon."; } diff --git a/tests/PathOrderMonotonicTest.cpp b/tests/PathOrderMonotonicTest.cpp index 108d1178ed..c6932c214b 100644 --- a/tests/PathOrderMonotonicTest.cpp +++ b/tests/PathOrderMonotonicTest.cpp @@ -2,24 +2,28 @@ // CuraEngine is released under the terms of the AGPLv3 or higher #include "PathOrderMonotonic.h" -#include "ReadTestPolygons.h" -#include "infill.h" -#include "slicer.h" -#include "utils/Coord_t.h" -#include "utils/math.h" -#include "geometry/polygon.h" -#include + #include #include #include #include +#include + +#include "ReadTestPolygons.h" +#include "geometry/polygon.h" +#include "infill.h" +#include "slicer.h" +#include "utils/Coord_t.h" +#include "utils/math.h" + // To diagnose failing tests with visual images, uncomment the following line: // #define TEST_PATHS_SVG_OUTPUT #ifdef TEST_PATHS_SVG_OUTPUT -#include "utils/SVG.h" #include + +#include "utils/SVG.h" #endif // TEST_PATHS_SVG_OUTPUT namespace cura @@ -30,22 +34,22 @@ class PathOrderMonotonicTest : public testing::TestWithParam& path) +inline Point2LL startVertex(const PathOrdering& path) { return (*path.vertices_)[path.start_vertex_]; } -inline Point2LL endVertex(const PathOrdering& path) +inline Point2LL endVertex(const PathOrdering& path) { return (*path.vertices_)[path.vertices_->size() - (1 + path.start_vertex_)]; } -coord_t projectPathAlongAxis(const PathOrdering& path, const Point2LL& vector) +coord_t projectPathAlongAxis(const PathOrdering& path, const Point2LL& vector) { return dot(startVertex(path), vector); } -coord_t projectEndAlongAxis(const PathOrdering& path, const Point2LL& vector) +coord_t projectEndAlongAxis(const PathOrdering& path, const Point2LL& vector) { return dot(endVertex(path), vector); } @@ -54,7 +58,8 @@ bool rangeOverlaps(const std::pair& range_b, const std::pair shapes; if (! readTestPolygons(filename, shapes)) @@ -81,7 +86,20 @@ bool getInfillLines(const std::string& filename, const AngleRadians& angle, Shap for (const auto& shape : shapes) { - Infill infill_comp(pattern, zig_zagify, connect_polygons, shape, infill_line_width, line_distance, infill_overlap, infill_multiplier, AngleDegrees(angle), z, shift, max_resolution, max_deviation); + Infill infill_comp( + pattern, + zig_zagify, + connect_polygons, + shape, + infill_line_width, + line_distance, + infill_overlap, + infill_multiplier, + AngleDegrees(angle), + z, + shift, + max_resolution, + max_deviation); Settings infill_settings; std::vector result_paths; Shape dummy_polys; @@ -91,7 +109,11 @@ bool getInfillLines(const std::string& filename, const AngleRadians& angle, Shap } #ifdef TEST_PATHS_SVG_OUTPUT -void writeDebugSVG(const std::string& original_filename, const AngleRadians& angle, const Point& monotonic_vec, const std::vector>>& sections) +void writeDebugSVG( + const std::string& original_filename, + const AngleRadians& angle, + const Point& monotonic_vec, + const std::vector>>& sections) { constexpr int buff_size = 1024; char buff[buff_size]; @@ -136,7 +158,7 @@ TEST_P(PathOrderMonotonicTest, SectionsTest) const auto params = GetParam(); const double angle_radians{ std::get<1>(params) }; const auto& filename = std::get<0>(params); - Shape polylines; + OpenLinesSet polylines; ASSERT_TRUE(getInfillLines(filename, angle_radians, polylines)) << "Input test-file could not be read, check setup."; const Point2LL& pt_r = polylines.begin()->at(0); @@ -146,15 +168,15 @@ TEST_P(PathOrderMonotonicTest, SectionsTest) const Point2LL perpendicular_axis{ turn90CCW(monotonic_axis) }; constexpr coord_t max_adjacent_distance = line_distance + 1; - PathOrderMonotonic object_under_test(angle_from_first_line, max_adjacent_distance, monotonic_axis * -1000); + PathOrderMonotonic object_under_test(angle_from_first_line, max_adjacent_distance, monotonic_axis * -1000); for (const auto& polyline : polylines) { - object_under_test.addPolyline(ConstPolygonPointer(polyline)); + object_under_test.addPolyline(&polyline); } object_under_test.optimize(); // Collect sections: - std::vector>> sections; + std::vector>> sections; sections.emplace_back(); coord_t last_path_mono_projection = projectPathAlongAxis(object_under_test.paths_.front(), monotonic_axis); for (const auto& path : object_under_test.paths_) @@ -202,7 +224,8 @@ TEST_P(PathOrderMonotonicTest, SectionsTest) const coord_t mono_b = projectPathAlongAxis(*it_b, monotonic_axis); if (mono_a < mono_b) { - EXPECT_FALSE(rangeOverlaps(perp_b_range, perp_a_range)) << "Perpendicular range overlaps for neighboring lines in different sections (next line of A / line in B)."; + EXPECT_FALSE(rangeOverlaps(perp_b_range, perp_a_range)) + << "Perpendicular range overlaps for neighboring lines in different sections (next line of A / line in B)."; } } } @@ -210,14 +233,28 @@ TEST_P(PathOrderMonotonicTest, SectionsTest) } } -const std::vector polygon_filenames = { - std::filesystem::path(__FILE__).parent_path().append("resources/polygon_concave.txt").string(), std::filesystem::path(__FILE__).parent_path().append("resources/polygon_concave_hole.txt").string(), - std::filesystem::path(__FILE__).parent_path().append("resources/polygon_square.txt").string(), std::filesystem::path(__FILE__).parent_path().append("resources/polygon_square_hole.txt").string(), - std::filesystem::path(__FILE__).parent_path().append("resources/polygon_triangle.txt").string(), std::filesystem::path(__FILE__).parent_path().append("resources/polygon_two_squares.txt").string(), - std::filesystem::path(__FILE__).parent_path().append("resources/polygon_slant_gap.txt").string(), std::filesystem::path(__FILE__).parent_path().append("resources/polygon_sawtooth.txt").string(), - std::filesystem::path(__FILE__).parent_path().append("resources/polygon_letter_y.txt").string() -}; -const std::vector angle_radians = { 0, 0.1, 0.25 * std::numbers::pi, 1.0, 0.5 * std::numbers::pi, 0.75 * std::numbers::pi, std::numbers::pi, 1.25 * std::numbers::pi, 4.0, 1.5 * std::numbers::pi, 1.75 * std::numbers::pi, 5.0, (2.0 * std::numbers::pi) - 0.1 }; +const std::vector polygon_filenames = { std::filesystem::path(__FILE__).parent_path().append("resources/polygon_concave.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_concave_hole.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_square.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_square_hole.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_triangle.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_two_squares.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_slant_gap.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_sawtooth.txt").string(), + std::filesystem::path(__FILE__).parent_path().append("resources/polygon_letter_y.txt").string() }; +const std::vector angle_radians = { 0, + 0.1, + 0.25 * std::numbers::pi, + 1.0, + 0.5 * std::numbers::pi, + 0.75 * std::numbers::pi, + std::numbers::pi, + 1.25 * std::numbers::pi, + 4.0, + 1.5 * std::numbers::pi, + 1.75 * std::numbers::pi, + 5.0, + (2.0 * std::numbers::pi) - 0.1 }; INSTANTIATE_TEST_SUITE_P(PathOrderMonotonicTestInstantiation, PathOrderMonotonicTest, testing::Combine(testing::ValuesIn(polygon_filenames), testing::ValuesIn(angle_radians))); // NOLINTEND(*-magic-numbers) diff --git a/tests/PathOrderOptimizerTest.cpp b/tests/PathOrderOptimizerTest.cpp index b4d4a32ee1..c8621ba3d8 100644 --- a/tests/PathOrderOptimizerTest.cpp +++ b/tests/PathOrderOptimizerTest.cpp @@ -15,7 +15,7 @@ class PathOrderOptimizerTest : public testing::Test /*! * A blank optimizer with no polygons added yet. Fresh and virgin. */ - PathOrderOptimizer optimizer; + PathOrderOptimizer optimizer; /*! * A simple isosceles triangle. Base length and height 50. @@ -29,12 +29,12 @@ class PathOrderOptimizerTest : public testing::Test void SetUp() override { - optimizer = PathOrderOptimizer(Point2LL(0, 0)); + optimizer = PathOrderOptimizer(Point2LL(0, 0)); triangle.clear(); - triangle.add(Point2LL(0, 0)); - triangle.add(Point2LL(50, 0)); - triangle.add(Point2LL(25, 50)); + triangle.push_back(Point2LL(0, 0)); + triangle.push_back(Point2LL(50, 0)); + triangle.push_back(Point2LL(25, 50)); } }; // NOLINTEND(misc-non-private-member-variables-in-classes) @@ -62,9 +62,9 @@ TEST_F(PathOrderOptimizerTest, ThreeTrianglesShortestOrder) far.translate(Point2LL(1000, 1000)); // Add them out of order so that it's clear that the optimization changes the order. - optimizer.addPolygon(middle); - optimizer.addPolygon(far); - optimizer.addPolygon(near); + optimizer.addPolygon(&middle); + optimizer.addPolygon(&far); + optimizer.addPolygon(&near); optimizer.optimize(); diff --git a/tests/WallsComputationTest.cpp b/tests/WallsComputationTest.cpp index 424a3c9b66..fc6d60a365 100644 --- a/tests/WallsComputationTest.cpp +++ b/tests/WallsComputationTest.cpp @@ -2,21 +2,25 @@ // CuraEngine is released under the terms of the AGPLv3 or higher #include "WallsComputation.h" //Unit under test. + +#include + +#include +#include + +#include + #include "InsetOrderOptimizer.h" //Unit also under test. +#include "geometry/polygon.h" //To create example polygons. #include "settings/Settings.h" //Settings to generate walls with. #include "sliceDataStorage.h" //Sl #include "slicer.h" -#include "geometry/polygon.h" //To create example polygons. -#include -#include -#include - -#include #ifdef WALLS_COMPUTATION_TEST_SVG_OUTPUT -#include "utils/SVG.h" -#include "geometry/polygon.h" #include + +#include "geometry/polygon.h" +#include "utils/SVG.h" #endif // WALLS_COMPUTATION_TEST_SVG_OUTPUT // NOLINTBEGIN(*-magic-numbers) @@ -48,7 +52,8 @@ class WallsComputationTest : public testing::Test */ Shape ff_holes; - WallsComputationTest() : walls_computation(settings, LayerIndex(100)) + WallsComputationTest() + : walls_computation(settings, LayerIndex(100)) { square_shape.emplace_back(); square_shape.back().emplace_back(0, 0); @@ -104,7 +109,7 @@ TEST_F(WallsComputationTest, GenerateWallsForLayerSinglePart) SliceLayer layer; layer.parts.emplace_back(); SliceLayerPart& part = layer.parts.back(); - part.outline.add(square_shape); + part.outline.push_back(square_shape); // Run the test. walls_computation.generateWalls(&layer, SectionType::WALL); @@ -113,7 +118,8 @@ TEST_F(WallsComputationTest, GenerateWallsForLayerSinglePart) EXPECT_FALSE(part.wall_toolpaths.empty()) << "There must be some walls."; EXPECT_GT(part.print_outline.area(), 0) << "The print outline must encompass the outer wall, so it must be more than 0."; EXPECT_LE(part.print_outline.area(), square_shape.area()) << "The print outline must stay within the bounds of the original part."; - EXPECT_GT(part.inner_area.area(), 0) << "The inner area must be within the innermost wall. There are not enough walls to fill the entire part, so there is a positive inner area."; + EXPECT_GT(part.inner_area.area(), 0) + << "The inner area must be within the innermost wall. There are not enough walls to fill the entire part, so there is a positive inner area."; EXPECT_EQ(layer.parts.size(), 1) << "There is still just 1 part."; } @@ -126,7 +132,7 @@ TEST_F(WallsComputationTest, GenerateWallsZeroWalls) SliceLayer layer; layer.parts.emplace_back(); SliceLayerPart& part = layer.parts.back(); - part.outline.add(square_shape); + part.outline.push_back(square_shape); // Run the test. walls_computation.generateWalls(&layer, SectionType::WALL); @@ -147,7 +153,7 @@ TEST_F(WallsComputationTest, WallToolPathsGetWeakOrder) SliceLayer layer; layer.parts.emplace_back(); SliceLayerPart& part = layer.parts.back(); - part.outline.add(ff_holes); + part.outline.push_back(ff_holes); // Run the test. walls_computation.generateWalls(&layer, SectionType::WALL); diff --git a/tests/arcus/ArcusCommunicationTest.cpp b/tests/arcus/ArcusCommunicationTest.cpp index cf66883c36..3c56047815 100644 --- a/tests/arcus/ArcusCommunicationTest.cpp +++ b/tests/arcus/ArcusCommunicationTest.cpp @@ -1,15 +1,17 @@ // Copyright (c) 2022 Ultimaker B.V. // CuraEngine is released under the terms of the AGPLv3 or higher. +#include +#include + +#include + #include "FffProcessor.h" #include "MockSocket.h" //To mock out the communication with the front-end. #include "communication/ArcusCommunicationPrivate.h" //To access the private fields of this communication class. +#include "geometry/polygon.h" //Create test shapes to send over the socket. #include "settings/types/LayerIndex.h" #include "utils/Coord_t.h" -#include "geometry/polygon.h" //Create test shapes to send over the socket. -#include -#include -#include // NOLINTBEGIN(*-magic-numbers) namespace cura @@ -47,24 +49,24 @@ class ArcusCommunicationTest : public testing::Test test_square.emplace_back(1000, 0); test_square.emplace_back(1000, 1000); test_square.emplace_back(0, 1000); - test_shapes.add(test_square); + test_shapes.push_back(test_square); test_square2.emplace_back(1100, 1500); test_square2.emplace_back(2000, 1500); test_square2.emplace_back(2000, -500); test_square2.emplace_back(1100, -500); - test_shapes.add(test_square2); + test_shapes.push_back(test_square2); test_triangle.emplace_back(0, 2100); test_triangle.emplace_back(500, 1100); test_triangle.emplace_back(1500, 2100); - test_shapes.add(test_triangle); + test_shapes.push_back(test_triangle); for (double a = 0; a < 1.0; a += .05) { - test_circle.add(Point2LL(2050, 2050) + Point2LL(std::cos(a * 2 * std::numbers::pi) * 500, std::sin(a * 2 * std::numbers::pi) * 500)); + test_circle.push_back(Point2LL(2050, 2050) + Point2LL(std::cos(a * 2 * std::numbers::pi) * 500, std::sin(a * 2 * std::numbers::pi) * 500)); } - test_shapes.add(test_circle); + test_shapes.push_back(test_circle); test_convex_shape.emplace_back(-300, 0); test_convex_shape.emplace_back(-100, 500); @@ -75,7 +77,7 @@ class ArcusCommunicationTest : public testing::Test test_convex_shape.emplace_back(-1500, 1500); test_convex_shape.emplace_back(-1600, 1100); test_convex_shape.emplace_back(-700, 200); - test_shapes.add(test_convex_shape); + test_shapes.push_back(test_convex_shape); } void TearDown() override @@ -170,4 +172,4 @@ TEST_F(ArcusCommunicationTest, SendProgress) } } // namespace cura -// NOLINTEND(*-magic-numbers) \ No newline at end of file +// NOLINTEND(*-magic-numbers) diff --git a/tests/arcus/MockCommunication.h b/tests/arcus/MockCommunication.h index 405ebc2878..fb1151c4e0 100644 --- a/tests/arcus/MockCommunication.h +++ b/tests/arcus/MockCommunication.h @@ -7,9 +7,10 @@ #include #include "communication/Communication.h" //The interface we're implementing. +#include "geometry/polygon.h" //In the signature of Communication. +#include "geometry/shape.h" #include "settings/types/LayerIndex.h" #include "utils/Coord_t.h" -#include "geometry/polygon.h" //In the signature of Communication. namespace cura { @@ -24,7 +25,7 @@ class MockCommunication : public Communication MOCK_CONST_METHOD0(isSequential, bool()); MOCK_CONST_METHOD1(sendProgress, void(double progress)); MOCK_METHOD3(sendLayerComplete, void(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness)); - MOCK_METHOD5(sendPolygons, void(const PrintFeatureType& type, const Polygons& polygons, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity)); + MOCK_METHOD5(sendPolygons, void(const PrintFeatureType& type, const Shape& polygons, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity)); MOCK_METHOD5(sendPolygon, void(const PrintFeatureType& type, const Polygon& polygon, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity)); MOCK_METHOD5(sendLineTo, void(const PrintFeatureType& type, const Point2LL& to, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity)); MOCK_METHOD1(sendCurrentPosition, void(const Point2LL& position)); diff --git a/tests/integration/SlicePhaseTest.cpp b/tests/integration/SlicePhaseTest.cpp index 9c6a0f641b..1a4fc1579e 100644 --- a/tests/integration/SlicePhaseTest.cpp +++ b/tests/integration/SlicePhaseTest.cpp @@ -7,10 +7,10 @@ #include "Application.h" // To set up a slice with settings. #include "Slice.h" // To set up a scene to slice. +#include "geometry/polygon.h" // Creating polygons to compare to sliced layers. #include "slicer.h" // Starts the slicing phase that we want to test. #include "utils/Coord_t.h" #include "utils/Matrix4x3D.h" // To load STL files. -#include "geometry/polygon.h" // Creating polygons to compare to sliced layers. #include "utils/polygonUtils.h" // Comparing similarity of polygons. namespace cura @@ -158,7 +158,7 @@ TEST_F(SlicePhaseTest, Cylinder1000) circle.emplace_back(x, y); } Shape circles; - circles.add(circle); + circles.push_back(circle); for (size_t layer_nr = 0; layer_nr < num_layers; layer_nr++) { diff --git a/tests/utils/AABBTest.cpp b/tests/utils/AABBTest.cpp index 8305798621..e3ad71f54c 100644 --- a/tests/utils/AABBTest.cpp +++ b/tests/utils/AABBTest.cpp @@ -7,6 +7,7 @@ #include +#include "geometry/polygon.h" #include "geometry/shape.h" namespace cura @@ -43,9 +44,12 @@ TEST(AABBTest, TestConstructPolygons) EXPECT_FALSE(polygons_box_a.contains(Point2LL(0, 0))) << "Box constructed from empty polygon shouldn't contain anything."; Shape polygons; - polygons.add(Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ -10, -10 }, ClipperLib::IntPoint{ 10, -10 }, ClipperLib::IntPoint{ -5, -5 }, ClipperLib::IntPoint{ -10, 10 } }))); - polygons.add(Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ 11, 11 }, ClipperLib::IntPoint{ -11, 11 }, ClipperLib::IntPoint{ 4, 4 }, ClipperLib::IntPoint{ 11, -11 } }))); - polygons.add(Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ 2, 2 }, ClipperLib::IntPoint{ 2, 3 }, ClipperLib::IntPoint{ 3, 3 }, ClipperLib::IntPoint{ 3, 2 } }))); + polygons.push_back( + Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ -10, -10 }, ClipperLib::IntPoint{ 10, -10 }, ClipperLib::IntPoint{ -5, -5 }, ClipperLib::IntPoint{ -10, 10 } }), false)); + polygons.push_back( + Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ 11, 11 }, ClipperLib::IntPoint{ -11, 11 }, ClipperLib::IntPoint{ 4, 4 }, ClipperLib::IntPoint{ 11, -11 } }), false)); + polygons.push_back( + Polygon(ClipperLib::Path({ ClipperLib::IntPoint{ 2, 2 }, ClipperLib::IntPoint{ 2, 3 }, ClipperLib::IntPoint{ 3, 3 }, ClipperLib::IntPoint{ 3, 2 } }), false)); AABB polygons_box_b(polygons); diff --git a/tests/utils/IntPointTest.cpp b/tests/utils/IntPointTest.cpp index cd6d2f2a73..0dfe1e36b4 100644 --- a/tests/utils/IntPointTest.cpp +++ b/tests/utils/IntPointTest.cpp @@ -1,9 +1,12 @@ // Copyright (c) 2022 Ultimaker B.V. // CuraEngine is released under the terms of the AGPLv3 or higher. -#include "geometry/point2ll.h" #include +#include "geometry/point2ll.h" +#include "geometry/point3_matrix.h" +#include "geometry/point_matrix.h" + // NOLINTBEGIN(*-magic-numbers) namespace cura { diff --git a/tests/utils/LinearAlg2DTest.cpp b/tests/utils/LinearAlg2DTest.cpp index b9e4f41bb0..fd0c3cde9b 100644 --- a/tests/utils/LinearAlg2DTest.cpp +++ b/tests/utils/LinearAlg2DTest.cpp @@ -7,6 +7,8 @@ #include +#include "geometry/point3_matrix.h" + // NOLINTBEGIN(*-magic-numbers) namespace cura { diff --git a/tests/utils/PolygonConnectorTest.cpp b/tests/utils/PolygonConnectorTest.cpp index c30fde412e..bc7ae275f6 100644 --- a/tests/utils/PolygonConnectorTest.cpp +++ b/tests/utils/PolygonConnectorTest.cpp @@ -2,11 +2,14 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "utils/PolygonConnector.h" // The class under test. -#include "utils/Coord_t.h" -#include "geometry/polygon.h" // To create polygons to test with. -#include + #include +#include + +#include "geometry/polygon.h" // To create polygons to test with. +#include "utils/Coord_t.h" + // NOLINTBEGIN(*-magic-numbers) namespace cura { @@ -70,7 +73,8 @@ TEST_F(PolygonConnectorTest, getBridgeNestedSquares) EXPECT_EQ(vSize(bridge->a_.from_point_ - bridge->a_.to_point_), 100) << "The polygons are 100 units spaced out concentrically, so this is the shortest possible bridge."; EXPECT_EQ(vSize(bridge->b_.from_point_ - bridge->b_.to_point_), 100) << "The second bridge should also be equally short in this case."; - EXPECT_EQ(LinearAlg2D::getDist2BetweenLineSegments(bridge->a_.from_point_, bridge->a_.to_point_, bridge->b_.from_point_, bridge->b_.to_point_), 100 * 100) << "The bridges should be spaced 1 line width (100 units) apart."; + EXPECT_EQ(LinearAlg2D::getDist2BetweenLineSegments(bridge->a_.from_point_, bridge->a_.to_point_, bridge->b_.from_point_, bridge->b_.to_point_), 100 * 100) + << "The bridges should be spaced 1 line width (100 units) apart."; EXPECT_LT(LinearAlg2D::pointIsLeftOfLine(bridge->b_.from_point_, bridge->a_.from_point_, bridge->a_.to_point_), 0) << "Connection B should be to the right of connection A."; EXPECT_LT(LinearAlg2D::pointIsLeftOfLine(bridge->b_.to_point_, bridge->a_.from_point_, bridge->a_.to_point_), 0) << "Connection B should be to the right of connection A."; } @@ -90,7 +94,8 @@ TEST_F(PolygonConnectorTest, getBridgeAdjacentSquares) EXPECT_EQ(vSize(bridge->a_.from_point_ - bridge->a_.to_point_), 100) << "The polygons are 100 units spaced apart, so this is the shortest possible bridge."; EXPECT_EQ(vSize(bridge->b_.from_point_ - bridge->b_.to_point_), 100) << "The second bridge should also be equally short in this case."; - EXPECT_EQ(LinearAlg2D::getDist2BetweenLineSegments(bridge->a_.from_point_, bridge->a_.to_point_, bridge->b_.from_point_, bridge->b_.to_point_), 100 * 100) << "The bridges should be spaced 1 line width (100 units) apart."; + EXPECT_EQ(LinearAlg2D::getDist2BetweenLineSegments(bridge->a_.from_point_, bridge->a_.to_point_, bridge->b_.from_point_, bridge->b_.to_point_), 100 * 100) + << "The bridges should be spaced 1 line width (100 units) apart."; EXPECT_LT(LinearAlg2D::pointIsLeftOfLine(bridge->b_.from_point_, bridge->a_.from_point_, bridge->a_.to_point_), 0) << "Connection B should be to the right of connection A."; EXPECT_LT(LinearAlg2D::pointIsLeftOfLine(bridge->b_.to_point_, bridge->a_.from_point_, bridge->a_.to_point_), 0) << "Connection B should be to the right of connection A."; } @@ -113,8 +118,10 @@ TEST_F(PolygonConnectorTest, getBridgeClosest) ASSERT_NE(bridge, std::nullopt) << "The two polygons are adjacent and spaced closely enough to bridge along their entire side, even with the slant."; - EXPECT_EQ(bridge->b_.from_point_, Point2LL(1000, 200)) << "The closest connection is [1000,200] -> [1100,200]. There is no space to the right of that, so bridge B should be there."; - EXPECT_EQ(bridge->b_.to_point_, Point2LL(1100, 200)) << "The closest connection is [1000,200] -> [1100,200]. There is no space to the right of that, so bridge B should be there."; + EXPECT_EQ(bridge->b_.from_point_, Point2LL(1000, 200)) + << "The closest connection is [1000,200] -> [1100,200]. There is no space to the right of that, so bridge B should be there."; + EXPECT_EQ(bridge->b_.to_point_, Point2LL(1100, 200)) + << "The closest connection is [1000,200] -> [1100,200]. There is no space to the right of that, so bridge B should be there."; EXPECT_GT(LinearAlg2D::pointIsLeftOfLine(bridge->a_.from_point_, bridge->b_.from_point_, bridge->b_.to_point_), 0) << "Connection A should be to the left of connection B."; EXPECT_GT(LinearAlg2D::pointIsLeftOfLine(bridge->a_.to_point_, bridge->b_.from_point_, bridge->b_.to_point_), 0) << "Connection A should be to the left of connection B."; } @@ -133,7 +140,8 @@ TEST_F(PolygonConnectorTest, getBridgeTooFar) std::optional> bridge = pc->getBridge(test_square, to_connect); - EXPECT_EQ(bridge, std::nullopt) << "The two polygons are 200 units apart where they are closest, which is more than 1.5 times the line width (100), so they can't be connected."; + EXPECT_EQ(bridge, std::nullopt) + << "The two polygons are 200 units apart where they are closest, which is more than 1.5 times the line width (100), so they can't be connected."; } /*! @@ -154,7 +162,8 @@ TEST_F(PolygonConnectorTest, getBridgeTooNarrow) std::optional> bridge = pc->getBridge(test_square, to_connect); - EXPECT_EQ(bridge, std::nullopt) << "Where the two polygons are adjacent is only 80 units wide. This is not enough to create a bridge with the connecting lines spaced 1 line width (100 units) apart."; + EXPECT_EQ(bridge, std::nullopt) + << "Where the two polygons are adjacent is only 80 units wide. This is not enough to create a bridge with the connecting lines spaced 1 line width (100 units) apart."; } /*! @@ -165,10 +174,10 @@ TEST_F(PolygonConnectorTest, getBridgeTooNarrow) TEST_F(PolygonConnectorTest, connectFourNested) { Shape connecting; - connecting.add(test_square_around); // 1200-wide square. - connecting.add(test_square); // 1000-wide square. - connecting.add(test_square.offset(-100)); // 800-wide square. - connecting.add(test_square.offset(-200)); // 600-wide square. + connecting.push_back(test_square_around); // 1200-wide square. + connecting.push_back(test_square); // 1000-wide square. + connecting.push_back(test_square.offset(-100)); // 800-wide square. + connecting.push_back(test_square.offset(-200)); // 600-wide square. pc->add(connecting); Shape output_polygons; diff --git a/tests/utils/PolygonTest.cpp b/tests/utils/PolygonTest.cpp index e2d7ec6839..13b218e484 100644 --- a/tests/utils/PolygonTest.cpp +++ b/tests/utils/PolygonTest.cpp @@ -5,7 +5,6 @@ #include -#include "geometry/closed_polyline.h" #include "geometry/open_polyline.h" #include "geometry/single_shape.h" #include "utils/Coord_t.h" @@ -82,9 +81,9 @@ class PolygonTest : public testing::Test small_area.emplace_back(10, 10); small_area.emplace_back(0, 10); } - void twoPolygonsAreEqual(Shape& polygon1, Shape& polygon2) const + void twoPolygonsAreEqual(Shape& shape1, Shape& shape2) const { - auto poly_cmp = [](const ClipperLib::Path& a, const ClipperLib::Path& b) + auto poly_cmp = [](const Polygon& a, const Polygon& b) { return std::lexicographical_compare( a.begin(), @@ -96,15 +95,15 @@ class PolygonTest : public testing::Test return p1 < p2; }); }; - std::sort(polygon1.begin(), polygon1.end(), poly_cmp); - std::sort(polygon2.begin(), polygon2.end(), poly_cmp); + std::sort(shape1.begin(), shape1.end(), poly_cmp); + std::sort(shape2.begin(), shape2.end(), poly_cmp); - std::vector difference; - std::set_difference(polygon1.begin(), polygon1.end(), polygon2.begin(), polygon2.end(), std::back_inserter(difference), poly_cmp); + LinesSet difference; + std::set_difference(shape1.begin(), shape1.end(), shape2.begin(), shape2.end(), std::back_inserter(difference), poly_cmp); ASSERT_TRUE(difference.empty()) << "Paths in polygon1 not found in polygon2:" << difference; difference.clear(); - std::set_difference(polygon2.begin(), polygon2.end(), polygon1.begin(), polygon1.end(), std::back_inserter(difference), poly_cmp); + std::set_difference(shape2.begin(), shape2.end(), shape1.begin(), shape1.end(), std::back_inserter(difference), poly_cmp); ASSERT_TRUE(difference.empty()) << "Paths in polygon2 not found in polygon1:" << difference; } }; @@ -567,24 +566,24 @@ TEST_F(PolygonTest, removeSmallAreas_complex) TEST_F(PolygonTest, openCloseLines) { // make some line - OpenPolyline openPolyline; - openPolyline.emplace_back(0, 0); - openPolyline.emplace_back(1000, 0); - openPolyline.emplace_back(1000, 1000); - openPolyline.emplace_back(0, 1000); + OpenPolyline open_polyline; + open_polyline.emplace_back(0, 0); + open_polyline.emplace_back(1000, 0); + open_polyline.emplace_back(1000, 1000); + open_polyline.emplace_back(0, 1000); // Make some casts and check that the results are consistent - EXPECT_EQ(openPolyline.length(), 3000); + EXPECT_EQ(open_polyline.length(), 3000); - ClosedPolyline& closedPolyline = openPolyline.toType(); - EXPECT_EQ(closedPolyline.length(), 4000); + ClosedPolyline closed_polyline(open_polyline.getPoints(), false); + EXPECT_EQ(closed_polyline.length(), 4000); - Polygon& polygon = openPolyline.toType(); + Polygon polygon(closed_polyline.getPoints(), false); EXPECT_EQ(polygon.area(), 1000000); // Check advanced calculations on segment length - EXPECT_TRUE(openPolyline.shorterThan(3500)); - EXPECT_FALSE(closedPolyline.shorterThan(3500)); + EXPECT_TRUE(open_polyline.shorterThan(3500)); + EXPECT_FALSE(closed_polyline.shorterThan(3500)); } } // namespace cura diff --git a/tests/utils/PolygonUtilsTest.cpp b/tests/utils/PolygonUtilsTest.cpp index 1b1cf91f83..ffa8b21612 100644 --- a/tests/utils/PolygonUtilsTest.cpp +++ b/tests/utils/PolygonUtilsTest.cpp @@ -5,9 +5,9 @@ #include -#include "utils/Coord_t.h" #include "geometry/point2ll.h" // Creating and testing with points. #include "geometry/polygon.h" // Creating polygons to test with. +#include "utils/Coord_t.h" // NOLINTBEGIN(*-magic-numbers) namespace cura @@ -71,7 +71,7 @@ TEST_P(MoveInsideTest, MoveInside2) { const MoveInsideParameters parameters = GetParam(); Shape polys; - polys.add(test_square); + polys.push_back(test_square); Point2LL result = parameters.close_to; PolygonUtils::moveInside2(polys, result, parameters.distance); ASSERT_LE(vSize(result - parameters.supposed), 10) << parameters.close_to << " moved with " << parameters.distance << " micron inside to " << result << "rather than " @@ -165,7 +165,7 @@ TEST_F(MoveInsideTest, cornerEdgeTest2) const Point2LL supposed2(72, 100); constexpr coord_t distance = 28; Shape polys; - polys.add(test_square); + polys.push_back(test_square); Point2LL result = close_to; PolygonUtils::moveInside2(polys, result, distance); @@ -179,7 +179,7 @@ TEST_F(MoveInsideTest, pointyCorner) const Point2LL from(55, 100); // Above pointy bit. Point2LL result(from); Shape inside; - inside.add(pointy_square); + inside.push_back(pointy_square); ClosestPointPolygon cpp = PolygonUtils::ensureInsideOrOutside(inside, result, 10); ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; @@ -193,7 +193,7 @@ TEST_F(MoveInsideTest, pointyCornerFail) const Point2LL from(55, 170); // Above pointy bit. Point2LL result(from); Shape inside; - inside.add(pointy_square); + inside.push_back(pointy_square); ClosestPointPolygon cpp = PolygonUtils::moveInside2(inside, result, 10); ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; @@ -207,7 +207,7 @@ TEST_F(MoveInsideTest, outsidePointyCorner) Point2LL result(from); const Point2LL supposed(50, 70); // 10 below pointy bit. Shape inside; - inside.add(pointy_square); + inside.push_back(pointy_square); const ClosestPointPolygon cpp = PolygonUtils::ensureInsideOrOutside(inside, result, -10); ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; @@ -222,7 +222,7 @@ TEST_F(MoveInsideTest, outsidePointyCornerFail) Point2LL result(from); const Point2LL supposed(50, 70); // 10 below pointy bit. Shape inside; - inside.add(pointy_square); + inside.push_back(pointy_square); const ClosestPointPolygon cpp = PolygonUtils::moveInside2(inside, result, -10); ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; @@ -266,7 +266,7 @@ TEST_P(FindCloseTest, FindClose) { const FindCloseParameters parameters = GetParam(); Shape polygons; - polygons.add(test_square); + polygons.push_back(test_square); auto loc_to_line = PolygonUtils::createLocToLineGrid(polygons, parameters.cell_size); std::optional cpp; @@ -323,28 +323,28 @@ class PolygonUtilsTest : public testing::Test test_square.emplace_back(100, 0); test_square.emplace_back(100, 100); test_square.emplace_back(0, 100); - test_squares.add(test_square); + test_squares.push_back(test_square); Polygon line; line.emplace_back(0, 0); line.emplace_back(100, 0); - test_line.add(line); + test_line.push_back(line); Polygon line_extra_vertices; line_extra_vertices.emplace_back(100, 0); line_extra_vertices.emplace_back(25, 0); line_extra_vertices.emplace_back(0, 0); line_extra_vertices.emplace_back(75, 0); - test_line_extra_vertices.add(line_extra_vertices); + test_line_extra_vertices.push_back(line_extra_vertices); } }; TEST_F(PolygonUtilsTest, spreadDotsSegment) { std::vector supposed; - supposed.emplace_back(Point2LL(50, 0), 0, test_squares[0], 0); - supposed.emplace_back(Point2LL(100, 0), 1, test_squares[0], 0); - supposed.emplace_back(Point2LL(100, 50), 1, test_squares[0], 0); + supposed.emplace_back(Point2LL(50, 0), 0, &test_squares[0], 0); + supposed.emplace_back(Point2LL(100, 0), 1, &test_squares[0], 0); + supposed.emplace_back(Point2LL(100, 50), 1, &test_squares[0], 0); std::vector result; PolygonUtils::spreadDots(PolygonsPointIndex(&test_squares, 0, 0), PolygonsPointIndex(&test_squares, 0, 2), 3, result); @@ -359,14 +359,14 @@ TEST_F(PolygonUtilsTest, spreadDotsSegment) TEST_F(PolygonUtilsTest, spreadDotsFull) { std::vector supposed; - supposed.emplace_back(Point2LL(0, 0), 0, test_squares[0], 0); - supposed.emplace_back(Point2LL(50, 0), 0, test_squares[0], 0); - supposed.emplace_back(Point2LL(100, 0), 1, test_squares[0], 0); - supposed.emplace_back(Point2LL(100, 50), 1, test_squares[0], 0); - supposed.emplace_back(Point2LL(100, 100), 2, test_squares[0], 0); - supposed.emplace_back(Point2LL(50, 100), 2, test_squares[0], 0); - supposed.emplace_back(Point2LL(0, 100), 3, test_squares[0], 0); - supposed.emplace_back(Point2LL(0, 50), 3, test_squares[0], 0); + supposed.emplace_back(Point2LL(0, 0), 0, &test_squares[0], 0); + supposed.emplace_back(Point2LL(50, 0), 0, &test_squares[0], 0); + supposed.emplace_back(Point2LL(100, 0), 1, &test_squares[0], 0); + supposed.emplace_back(Point2LL(100, 50), 1, &test_squares[0], 0); + supposed.emplace_back(Point2LL(100, 100), 2, &test_squares[0], 0); + supposed.emplace_back(Point2LL(50, 100), 2, &test_squares[0], 0); + supposed.emplace_back(Point2LL(0, 100), 3, &test_squares[0], 0); + supposed.emplace_back(Point2LL(0, 50), 3, &test_squares[0], 0); std::vector result; PolygonUtils::spreadDots(PolygonsPointIndex(&test_squares, 0, 0), PolygonsPointIndex(&test_squares, 0, 0), 8, result); @@ -408,7 +408,7 @@ class GetNextParallelIntersectionTest : public testing::TestWithParam