From fda3e1bb8e712fc83a8e2f17d96881ad6d4a42c9 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 22 Nov 2023 15:39:51 +0100 Subject: [PATCH] Fixed unit tests build --- include/PathOrderOptimizer.h | 12 +- include/utils/Simplify.h | 35 ++-- tests/ExtruderPlanTest.cpp | 49 +++-- tests/GCodeExportTest.cpp | 128 ++++++------ tests/PathOrderOptimizerTest.cpp | 12 +- tests/arcus/ArcusCommunicationPrivateTest.cpp | 28 +-- tests/arcus/MockCommunication.h | 34 ++-- tests/integration/SlicePhaseTest.cpp | 4 +- tests/settings/SettingsTest.cpp | 22 ++- tests/utils/LinearAlg2DTest.cpp | 184 ++++++++++-------- tests/utils/PolygonUtilsTest.cpp | 150 ++++++++------ tests/utils/SimplifyTest.cpp | 35 ++-- tests/utils/SparseGridTest.cpp | 133 +++++++++---- 13 files changed, 479 insertions(+), 347 deletions(-) diff --git a/include/PathOrderOptimizer.h b/include/PathOrderOptimizer.h index a65d3bba87..9bd8288a95 100644 --- a/include/PathOrderOptimizer.h +++ b/include/PathOrderOptimizer.h @@ -80,12 +80,12 @@ class PathOrderOptimizer * The location where the nozzle is assumed to start from before printing * these parts. */ - const Point2LL start_point_; + Point2LL start_point_; /*! * Seam settings. */ - const ZSeamConfig seam_config_; + ZSeamConfig seam_config_; static const std::unordered_multimap no_order_requirements_; @@ -104,7 +104,7 @@ class PathOrderOptimizer * \param combing_boundary Boundary to avoid when making travel moves. */ PathOrderOptimizer( - const Point2LL start_point, + const Point2LL& start_point, const ZSeamConfig seam_config = ZSeamConfig(), const bool detect_loops = false, const Polygons* combing_boundary = nullptr, @@ -268,7 +268,7 @@ class PathOrderOptimizer * polygons. This then allows the optimizer to decide on a seam location * that is not one of the endpoints of the polyline. */ - const bool detect_loops_; + bool detect_loops_; /*! * Whether to reverse the ordering completely. @@ -276,7 +276,7 @@ class PathOrderOptimizer * This reverses the order in which parts are printed, and inverts the * direction of each path as well. */ - const bool reverse_direction_; + bool reverse_direction_; /* * Whether to print all outer walls in a group, one after another. @@ -284,7 +284,7 @@ class PathOrderOptimizer * If this is enabled outer walls will be printed first and then all other * walls will be printed. If reversed they will be printed last. */ - const bool _group_outer_walls; + bool _group_outer_walls; /*! * Order requirements on the paths. diff --git a/include/utils/Simplify.h b/include/utils/Simplify.h index 91c0eeca61..3ca5b0009d 100644 --- a/include/utils/Simplify.h +++ b/include/utils/Simplify.h @@ -40,6 +40,23 @@ namespace cura class Simplify { public: + /*! + * Line segments shorter than this size should be considered for removal. + */ + coord_t max_resolution_; + + /*! + * If removing a vertex causes a deviation further than this, it may not be + * removed. + */ + coord_t max_deviation_; + + /*! + * If removing a vertex causes the covered area of the line segments to + * change by more than this, it may not be removed. + */ + coord_t max_area_deviation_; + /*! * Construct a simplifier, storing the simplification parameters in the * instance (as a factory pattern). @@ -471,24 +488,6 @@ class Simplify * \return The area deviation that would be caused by removing the vertex. */ coord_t getAreaDeviation(const ExtrusionJunction& before, const ExtrusionJunction& vertex, const ExtrusionJunction& after) const; - -private: - /*! - * Line segments shorter than this size should be considered for removal. - */ - coord_t max_resolution_; - - /*! - * If removing a vertex causes a deviation further than this, it may not be - * removed. - */ - coord_t max_deviation_; - - /*! - * If removing a vertex causes the covered area of the line segments to - * change by more than this, it may not be removed. - */ - coord_t max_area_deviation_; }; } // namespace cura diff --git a/tests/ExtruderPlanTest.cpp b/tests/ExtruderPlanTest.cpp index 2aa6f6e59d..ed15fc4a9f 100644 --- a/tests/ExtruderPlanTest.cpp +++ b/tests/ExtruderPlanTest.cpp @@ -1,11 +1,12 @@ // Copyright (c) 2023 UltiMaker // CuraEngine is released under the terms of the AGPLv3 or higher -#include "LayerPlan.h" //Code under test. -#include "pathPlanning/SpeedDerivatives.h" +#include //For calculating averages. #include -#include //For calculating averages. + +#include "LayerPlan.h" //Code under test. +#include "pathPlanning/SpeedDerivatives.h" // NOLINTBEGIN(*-magic-numbers) namespace cura @@ -71,8 +72,16 @@ class ExtruderPlanTestPathCollection GCodePathConfig travel_config; ExtruderPlanTestPathCollection() - : extrusion_config(GCodePathConfig{ .type = PrintFeatureType::OuterWall, .line_width = 400, .layer_thickness = 100, .flow = 1.0_r, .speed_derivatives = SpeedDerivatives { .speed = 50.0, .acceleration = 1000.0, .jerk = 10.0 } }) - , travel_config(GCodePathConfig{ .type = PrintFeatureType::MoveCombing, .line_width = 0, .layer_thickness = 100, .flow = 0.0_r, .speed_derivatives = SpeedDerivatives { .speed = 120.0, .acceleration = 5000.0, .jerk = 30.0 } }) + : extrusion_config(GCodePathConfig{ .type = PrintFeatureType::OuterWall, + .line_width = 400, + .layer_thickness = 100, + .flow = 1.0_r, + .speed_derivatives = SpeedDerivatives{ .speed = 50.0, .acceleration = 1000.0, .jerk = 10.0 } }) + , travel_config(GCodePathConfig{ .type = PrintFeatureType::MoveCombing, + .line_width = 0, + .layer_thickness = 100, + .flow = 0.0_r, + .speed_derivatives = SpeedDerivatives{ .speed = 120.0, .acceleration = 5000.0, .jerk = 30.0 } }) { std::shared_ptr mesh = nullptr; constexpr Ratio flow_1 = 1.0_r; @@ -363,10 +372,10 @@ class ExtruderPlanTest : public testing::Test */ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationZeroIsUncompensated) { - extruder_plan.paths = GetParam(); + extruder_plan.paths_ = GetParam(); std::vector original_widths; std::vector original_speeds; - for (const GCodePath& path : extruder_plan.paths) + for (const GCodePath& path : extruder_plan.paths_) { original_widths.push_back(path.width_factor); original_speeds.push_back(path.speed_factor); @@ -374,11 +383,11 @@ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationZeroIsUncompe extruder_plan.applyBackPressureCompensation(0.0_r); - ASSERT_EQ(extruder_plan.paths.size(), original_widths.size()) << "Number of paths may not have changed."; - for (size_t i = 0; i < extruder_plan.paths.size(); ++i) + ASSERT_EQ(extruder_plan.paths_.size(), original_widths.size()) << "Number of paths may not have changed."; + for (size_t i = 0; i < extruder_plan.paths_.size(); ++i) { - EXPECT_NEAR(original_widths[i], extruder_plan.paths[i].width_factor, error_margin) << "The width did not change. Back pressure compensation doesn't adjust line width."; - EXPECT_NEAR(original_speeds[i], extruder_plan.paths[i].speed_factor, error_margin) << "The speed factor did not change, since the compensation factor was 0."; + EXPECT_NEAR(original_widths[i], extruder_plan.paths_[i].width_factor, error_margin) << "The width did not change. Back pressure compensation doesn't adjust line width."; + EXPECT_NEAR(original_speeds[i], extruder_plan.paths_[i].speed_factor, error_margin) << "The speed factor did not change, since the compensation factor was 0."; } } @@ -388,24 +397,24 @@ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationZeroIsUncompe */ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationFull) { - extruder_plan.paths = GetParam(); + extruder_plan.paths_ = GetParam(); extruder_plan.applyBackPressureCompensation(1.0_r); auto first_extrusion = std::find_if( - extruder_plan.paths.begin(), - extruder_plan.paths.end(), + extruder_plan.paths_.begin(), + extruder_plan.paths_.end(), [&](GCodePath& path) { return shouldCountPath(path); }); - if (first_extrusion == extruder_plan.paths.end()) // Only travel moves in this plan. + if (first_extrusion == extruder_plan.paths_.end()) // Only travel moves in this plan. { return; } // All flow rates must be equal to this one. const double first_flow_mm3_per_sec = calculatePathWidth(*first_extrusion); - for (GCodePath& path : extruder_plan.paths) + for (GCodePath& path : extruder_plan.paths_) { if (! shouldCountPath(path)) { @@ -422,11 +431,11 @@ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationFull) */ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationHalf) { - extruder_plan.paths = GetParam(); + extruder_plan.paths_ = GetParam(); // Calculate what the flow rates were originally. std::vector original_flows; - for (GCodePath& path : extruder_plan.paths) + for (GCodePath& path : extruder_plan.paths_) { if (! shouldCountPath(path)) { @@ -441,7 +450,7 @@ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationHalf) // Calculate the new flow rates. std::vector new_flows; - for (GCodePath& path : extruder_plan.paths) + for (GCodePath& path : extruder_plan.paths_) { if (! shouldCountPath(path)) { @@ -471,7 +480,7 @@ TEST_F(ExtruderPlanTest, BackPressureCompensationEmptyPlan) // The extruder plan starts off empty. So immediately try applying back-pressure compensation. extruder_plan.applyBackPressureCompensation(0.5_r); - EXPECT_TRUE(extruder_plan.paths.empty()) << "The paths in the extruder plan should remain empty. Also it shouldn't crash."; + EXPECT_TRUE(extruder_plan.paths_.empty()) << "The paths in the extruder plan should remain empty. Also it shouldn't crash."; } } // namespace cura // NOLINTEND(*-magic-numbers) diff --git a/tests/GCodeExportTest.cpp b/tests/GCodeExportTest.cpp index e43ba1fee9..b8ae6bb7ca 100644 --- a/tests/GCodeExportTest.cpp +++ b/tests/GCodeExportTest.cpp @@ -241,7 +241,7 @@ class GriffinHeaderTest : public testing::TestWithParam TEST_P(GriffinHeaderTest, HeaderGriffinFormat) { const size_t num_extruders = GetParam(); - gcode.flavor = EGCodeFlavor::GRIFFIN; + gcode.flavor_ = EGCodeFlavor::GRIFFIN; for (size_t extruder_index = 0; extruder_index < num_extruders; extruder_index++) { Application::getInstance().current_slice_->scene.extruders.emplace_back(extruder_index, nullptr); @@ -270,7 +270,7 @@ TEST_P(GriffinHeaderTest, HeaderGriffinFormat) EXPECT_EQ(Date::getDate().toStringDashed(), token.substr(22)); std::getline(result, token, '\n'); EXPECT_EQ(std::string(";TARGET_MACHINE.NAME:"), token.substr(0, 21)); - EXPECT_EQ(gcode.machine_name, token.substr(21)); + EXPECT_EQ(gcode.machine_name_, token.substr(21)); for (size_t extruder_nr = 0; extruder_nr < num_extruders; extruder_nr++) { @@ -317,7 +317,7 @@ INSTANTIATE_TEST_SUITE_P(GriffinHeaderTestInstantiation, GriffinHeaderTest, test */ TEST_F(GCodeExportTest, HeaderUltiGCode) { - gcode.flavor = EGCodeFlavor::ULTIGCODE; + gcode.flavor_ = EGCodeFlavor::ULTIGCODE; constexpr size_t num_extruders = 2; const std::vector extruder_is_used(num_extruders, true); constexpr Duration print_time = 1337; @@ -328,7 +328,7 @@ TEST_F(GCodeExportTest, HeaderUltiGCode) ExtruderTrain& train = Application::getInstance().current_slice_->scene.extruders.back(); train.settings_.add("machine_nozzle_size", "0.4"); } - gcode.total_bounding_box = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); + gcode.total_bounding_box_ = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used); @@ -341,14 +341,14 @@ TEST_F(GCodeExportTest, HeaderUltiGCode) TEST_F(GCodeExportTest, HeaderRepRap) { Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.123"); - gcode.flavor = EGCodeFlavor::REPRAP; - gcode.extruder_attr[0].filament_area = 5.0; - gcode.extruder_attr[1].filament_area = 4.0; + gcode.flavor_ = EGCodeFlavor::REPRAP; + gcode.extruder_attr_[0].filament_area_ = 5.0; + gcode.extruder_attr_[1].filament_area_ = 4.0; constexpr size_t num_extruders = 2; const std::vector extruder_is_used(num_extruders, true); constexpr Duration print_time = 1337; const std::vector filament_used = { 100, 200 }; - gcode.total_bounding_box = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); + gcode.total_bounding_box_ = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used); @@ -361,14 +361,14 @@ TEST_F(GCodeExportTest, HeaderRepRap) TEST_F(GCodeExportTest, HeaderMarlin) { Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.123"); - gcode.flavor = EGCodeFlavor::MARLIN; - gcode.extruder_attr[0].filament_area = 5.0; - gcode.extruder_attr[1].filament_area = 4.0; + gcode.flavor_ = EGCodeFlavor::MARLIN; + gcode.extruder_attr_[0].filament_area_ = 5.0; + gcode.extruder_attr_[1].filament_area_ = 4.0; constexpr size_t num_extruders = 2; const std::vector extruder_is_used(num_extruders, true); constexpr Duration print_time = 1337; const std::vector filament_used = { 100, 200 }; - gcode.total_bounding_box = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); + gcode.total_bounding_box_ = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used); @@ -381,12 +381,12 @@ TEST_F(GCodeExportTest, HeaderMarlin) TEST_F(GCodeExportTest, HeaderMarlinVolumetric) { Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.123"); - gcode.flavor = EGCodeFlavor::MARLIN_VOLUMATRIC; + gcode.flavor_ = EGCodeFlavor::MARLIN_VOLUMATRIC; constexpr size_t num_extruders = 2; const std::vector extruder_is_used(num_extruders, true); constexpr Duration print_time = 1337; const std::vector filament_used = { 100, 200 }; - gcode.total_bounding_box = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); + gcode.total_bounding_box_ = AABB3D(Point3LL(0, 0, 0), Point3LL(1000, 1000, 1000)); std::string result = gcode.getFileHeader(extruder_is_used, &print_time, filament_used); @@ -403,8 +403,8 @@ TEST_F(GCodeExportTest, HeaderMarlinVolumetric) TEST_F(GCodeExportTest, EVsMmVolumetric) { constexpr double filament_area = 10.0; - gcode.extruder_attr[0].filament_area = filament_area; - gcode.is_volumetric = true; + gcode.extruder_attr_[0].filament_area_ = filament_area; + gcode.is_volumetric_ = true; constexpr double mm3_input = 15.0; EXPECT_EQ(gcode.mm3ToE(mm3_input), mm3_input) << "Since the E is volumetric and the input mm3 is also volumetric, the output needs to be the same."; @@ -428,8 +428,8 @@ TEST_F(GCodeExportTest, EVsMmVolumetric) TEST_F(GCodeExportTest, EVsMmLinear) { constexpr double filament_area = 10.0; - gcode.extruder_attr[0].filament_area = filament_area; - gcode.is_volumetric = false; + gcode.extruder_attr_[0].filament_area_ = filament_area; + gcode.is_volumetric_ = false; EXPECT_EQ(gcode.mmToE(15.0), 15.0) << "Since the E is linear and the input mm is also linear, the output needs to be the same."; EXPECT_EQ(gcode.eToMm(15.0), 15.0) << "Since the E is linear and the output mm is also linear, the output needs to be the same."; @@ -460,22 +460,22 @@ TEST_F(GCodeExportTest, SwitchExtruderSimple) scene.extruders.emplace_back(0, nullptr); ExtruderTrain& train1 = scene.extruders.back(); - train1.settings.add("machine_extruder_start_code", ";FIRST EXTRUDER START G-CODE!"); - train1.settings.add("machine_extruder_end_code", ";FIRST EXTRUDER END G-CODE!"); - train1.settings.add("machine_extruder_start_code_duration", "0.0"); - train1.settings.add("machine_extruder_end_code_duration", "0.0"); - train1.settings.add("machine_firmware_retract", "True"); - train1.settings.add("retraction_enable", "True"); + train1.settings_.add("machine_extruder_start_code", ";FIRST EXTRUDER START G-CODE!"); + train1.settings_.add("machine_extruder_end_code", ";FIRST EXTRUDER END G-CODE!"); + train1.settings_.add("machine_extruder_start_code_duration", "0.0"); + train1.settings_.add("machine_extruder_end_code_duration", "0.0"); + train1.settings_.add("machine_firmware_retract", "True"); + train1.settings_.add("retraction_enable", "True"); scene.extruders.emplace_back(1, nullptr); ExtruderTrain& train2 = scene.extruders.back(); - train2.settings.add("machine_extruder_start_code", ";SECOND EXTRUDER START G-CODE!"); - train2.settings.add("machine_extruder_end_code", ";SECOND EXTRUDER END G-CODE!"); - train2.settings.add("machine_extruder_start_code_duration", "0.0"); - train2.settings.add("machine_extruder_end_code_duration", "0.0"); - train2.settings.add("machine_firmware_retract", "True"); - train2.settings.add("retraction_enable", "True"); + train2.settings_.add("machine_extruder_start_code", ";SECOND EXTRUDER START G-CODE!"); + train2.settings_.add("machine_extruder_end_code", ";SECOND EXTRUDER END G-CODE!"); + train2.settings_.add("machine_extruder_start_code_duration", "0.0"); + train2.settings_.add("machine_extruder_end_code_duration", "0.0"); + train2.settings_.add("machine_firmware_retract", "True"); + train2.settings_.add("retraction_enable", "True"); RetractionConfig no_retraction; no_retraction.distance = 0; @@ -496,8 +496,8 @@ TEST_F(GCodeExportTest, WriteZHopStartZero) TEST_F(GCodeExportTest, WriteZHopStartDefaultSpeed) { Application::getInstance().current_slice_->scene.extruders.emplace_back(0, nullptr); - Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder].settings_.add("speed_z_hop", "1"); // 60mm/min. - gcode.current_layer_z = 2000; + Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder_].settings_.add("speed_z_hop", "1"); // 60mm/min. + gcode.current_layer_z_ = 2000; constexpr coord_t hop_height = 3000; gcode.writeZhopStart(hop_height); EXPECT_EQ(std::string("G1 F60 Z5\n"), output.str()); @@ -506,8 +506,8 @@ TEST_F(GCodeExportTest, WriteZHopStartDefaultSpeed) TEST_F(GCodeExportTest, WriteZHopStartCustomSpeed) { Application::getInstance().current_slice_->scene.extruders.emplace_back(0, nullptr); - Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder].settings_.add("speed_z_hop", "1"); // 60mm/min. - gcode.current_layer_z = 2000; + Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder_].settings_.add("speed_z_hop", "1"); // 60mm/min. + gcode.current_layer_z_ = 2000; constexpr coord_t hop_height = 3000; constexpr Velocity speed{ 4.0 }; // 240 mm/min. gcode.writeZhopStart(hop_height, speed); @@ -516,7 +516,7 @@ TEST_F(GCodeExportTest, WriteZHopStartCustomSpeed) TEST_F(GCodeExportTest, WriteZHopEndZero) { - gcode.is_z_hopped = 0; + gcode.is_z_hopped_ = 0; gcode.writeZhopEnd(); EXPECT_EQ(std::string(""), output.str()) << "Zero length z hop shouldn't affect gcode output."; } @@ -524,9 +524,9 @@ TEST_F(GCodeExportTest, WriteZHopEndZero) TEST_F(GCodeExportTest, WriteZHopEndDefaultSpeed) { Application::getInstance().current_slice_->scene.extruders.emplace_back(0, nullptr); - Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder].settings_.add("speed_z_hop", "1"); // 60mm/min. - gcode.current_layer_z = 2000; - gcode.is_z_hopped = 3000; + Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder_].settings_.add("speed_z_hop", "1"); // 60mm/min. + gcode.current_layer_z_ = 2000; + gcode.is_z_hopped_ = 3000; gcode.writeZhopEnd(); EXPECT_EQ(std::string("G1 F60 Z2\n"), output.str()); } @@ -534,9 +534,9 @@ TEST_F(GCodeExportTest, WriteZHopEndDefaultSpeed) TEST_F(GCodeExportTest, WriteZHopEndCustomSpeed) { Application::getInstance().current_slice_->scene.extruders.emplace_back(0, nullptr); - Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder].settings_.add("speed_z_hop", "1"); - gcode.current_layer_z = 2000; - gcode.is_z_hopped = 3000; + Application::getInstance().current_slice_->scene.extruders[gcode.current_extruder_].settings_.add("speed_z_hop", "1"); + gcode.current_layer_z_ = 2000; + gcode.is_z_hopped_ = 3000; constexpr Velocity speed{ 4.0 }; // 240 mm/min. gcode.writeZhopEnd(speed); EXPECT_EQ(std::string("G1 F240 Z2\n"), output.str()) << "Custom provided speed should be used."; @@ -544,9 +544,9 @@ TEST_F(GCodeExportTest, WriteZHopEndCustomSpeed) TEST_F(GCodeExportTest, insertWipeScriptSingleMove) { - gcode.currentPosition = Point3LL(1000, 1000, 1000); - gcode.current_layer_z = 1000; - gcode.use_extruder_offset_to_offset_coords = false; + gcode.current_position_ = Point3LL(1000, 1000, 1000); + gcode.current_layer_z_ = 1000; + gcode.use_extruder_offset_to_offset_coords_ = false; Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.2"); WipeScriptConfig config; @@ -576,9 +576,9 @@ TEST_F(GCodeExportTest, insertWipeScriptSingleMove) TEST_F(GCodeExportTest, insertWipeScriptMultipleMoves) { - gcode.currentPosition = Point3LL(1000, 1000, 1000); - gcode.current_layer_z = 1000; - gcode.use_extruder_offset_to_offset_coords = false; + gcode.current_position_ = Point3LL(1000, 1000, 1000); + gcode.current_layer_z_ = 1000; + gcode.use_extruder_offset_to_offset_coords_ = false; Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.2"); WipeScriptConfig config; @@ -614,9 +614,9 @@ TEST_F(GCodeExportTest, insertWipeScriptMultipleMoves) TEST_F(GCodeExportTest, insertWipeScriptOptionalDelay) { - gcode.currentPosition = Point3LL(1000, 1000, 1000); - gcode.current_layer_z = 1000; - gcode.use_extruder_offset_to_offset_coords = false; + gcode.current_position_ = Point3LL(1000, 1000, 1000); + gcode.current_layer_z_ = 1000; + gcode.use_extruder_offset_to_offset_coords_ = false; Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.2"); WipeScriptConfig config; @@ -645,15 +645,15 @@ TEST_F(GCodeExportTest, insertWipeScriptOptionalDelay) TEST_F(GCodeExportTest, insertWipeScriptRetractionEnable) { - gcode.currentPosition = Point3LL(1000, 1000, 1000); - gcode.current_layer_z = 1000; - gcode.current_e_value = 100; - gcode.use_extruder_offset_to_offset_coords = false; - gcode.is_volumetric = false; - gcode.current_extruder = 0; - gcode.extruder_attr[0].filament_area = 10.0; - gcode.relative_extrusion = false; - gcode.currentSpeed = 1.0; + gcode.current_position_ = Point3LL(1000, 1000, 1000); + gcode.current_layer_z_ = 1000; + gcode.current_e_value_ = 100; + gcode.use_extruder_offset_to_offset_coords_ = false; + gcode.is_volumetric_ = false; + gcode.current_extruder_ = 0; + gcode.extruder_attr_[0].filament_area_ = 10.0; + gcode.relative_extrusion_ = false; + gcode.current_speed_ = 1.0; Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.2"); Application::getInstance().current_slice_->scene.extruders.emplace_back(0, &Application::getInstance().current_slice_->scene.current_mesh_group->settings); Application::getInstance().current_slice_->scene.extruders.back().settings_.add("machine_firmware_retract", "false"); @@ -663,7 +663,7 @@ TEST_F(GCodeExportTest, insertWipeScriptRetractionEnable) config.retraction_config.distance = 1; config.retraction_config.speed = 2.0; // 120 mm/min. config.retraction_config.primeSpeed = 3.0; // 180 mm/min. - config.retraction_config.prime_volume = gcode.extruder_attr[0].filament_area * 4; // 4mm in linear dimensions + config.retraction_config.prime_volume = gcode.extruder_attr_[0].filament_area_ * 4; // 4mm in linear dimensions config.retraction_config.retraction_count_max = 100; // Practically no limit. config.retraction_config.retraction_extrusion_window = 1; config.retraction_config.retraction_min_travel_distance = 0; // Don't limit retractions for being too short. @@ -693,10 +693,10 @@ TEST_F(GCodeExportTest, insertWipeScriptRetractionEnable) TEST_F(GCodeExportTest, insertWipeScriptHopEnable) { - gcode.currentPosition = Point3LL(1000, 1000, 1000); - gcode.current_layer_z = 1000; - gcode.use_extruder_offset_to_offset_coords = false; - gcode.currentSpeed = 1.0; + gcode.current_position_ = Point3LL(1000, 1000, 1000); + gcode.current_layer_z_ = 1000; + gcode.use_extruder_offset_to_offset_coords_ = false; + gcode.current_speed_ = 1.0; Application::getInstance().current_slice_->scene.current_mesh_group->settings.add("layer_height", "0.2"); WipeScriptConfig config; diff --git a/tests/PathOrderOptimizerTest.cpp b/tests/PathOrderOptimizerTest.cpp index 3b895e1360..b4d4a32ee1 100644 --- a/tests/PathOrderOptimizerTest.cpp +++ b/tests/PathOrderOptimizerTest.cpp @@ -2,6 +2,7 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "PathOrderOptimizer.h" //The code under test. + #include //To run the tests. // NOLINTBEGIN(*-magic-numbers) @@ -21,7 +22,8 @@ class PathOrderOptimizerTest : public testing::Test */ Polygon triangle; - PathOrderOptimizerTest() : optimizer(Point2LL(0, 0)) + PathOrderOptimizerTest() + : optimizer(Point2LL(0, 0)) { } @@ -43,7 +45,7 @@ class PathOrderOptimizerTest : public testing::Test TEST_F(PathOrderOptimizerTest, OptimizeWhileEmpty) { optimizer.optimize(); // Don't crash. - EXPECT_EQ(optimizer.paths.size(), 0) << "Still empty!"; + EXPECT_EQ(optimizer.paths_.size(), 0) << "Still empty!"; } /*! @@ -66,9 +68,9 @@ TEST_F(PathOrderOptimizerTest, ThreeTrianglesShortestOrder) optimizer.optimize(); - EXPECT_EQ(optimizer.paths[0].vertices->front(), Point2LL(100, 100)) << "Nearest triangle first."; - EXPECT_EQ(optimizer.paths[1].vertices->front(), Point2LL(500, 500)) << "Middle triangle second."; - EXPECT_EQ(optimizer.paths[2].vertices->front(), Point2LL(1000, 1000)) << "Far triangle last."; + EXPECT_EQ(optimizer.paths_[0].vertices_->front(), Point2LL(100, 100)) << "Nearest triangle first."; + EXPECT_EQ(optimizer.paths_[1].vertices_->front(), Point2LL(500, 500)) << "Middle triangle second."; + EXPECT_EQ(optimizer.paths_[2].vertices_->front(), Point2LL(1000, 1000)) << "Far triangle last."; } } // namespace cura diff --git a/tests/arcus/ArcusCommunicationPrivateTest.cpp b/tests/arcus/ArcusCommunicationPrivateTest.cpp index 29d33d94c0..12652958ca 100644 --- a/tests/arcus/ArcusCommunicationPrivateTest.cpp +++ b/tests/arcus/ArcusCommunicationPrivateTest.cpp @@ -2,17 +2,20 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "communication/ArcusCommunicationPrivate.h" //The class we're testing. -#include "Application.h" -#include "ExtruderTrain.h" -#include "MockSocket.h" -#include "Slice.h" -#include "utils/Coord_t.h" + #include #include #include #include + #include +#include "Application.h" +#include "ExtruderTrain.h" +#include "MockSocket.h" +#include "Slice.h" +#include "utils/Coord_t.h" + // NOLINTBEGIN(*-magic-numbers) namespace cura { @@ -193,7 +196,8 @@ TEST_F(ArcusCommunicationPrivateTest, ReadMeshGroupMessage) // - - Add settings to the mesh: std::map mesh_settings = { - { "extruder_nr", "0" }, { "center_object", "1" }, { "mesh_position_x", "0" }, { "mesh_position_y", "0" }, { "mesh_position_z", "0" }, { "infill_mesh", "0" }, { "cutting_mesh", "0" }, { "anti_overhang_mesh", "0" }, + { "extruder_nr", "0" }, { "center_object", "1" }, { "mesh_position_x", "0" }, { "mesh_position_y", "0" }, + { "mesh_position_z", "0" }, { "infill_mesh", "0" }, { "cutting_mesh", "0" }, { "anti_overhang_mesh", "0" }, }; for (std::pair key_value : mesh_settings) { @@ -234,12 +238,12 @@ TEST_F(ArcusCommunicationPrivateTest, ReadMeshGroupMessage) std::array max_coords = { std::numeric_limits::min(), std::numeric_limits::min(), std::numeric_limits::min() }; for (const auto& vertex : vertices) { - min_coords[0] = std::min(vertex.p_.x, min_coords[0]); - min_coords[1] = std::min(vertex.p_.y, min_coords[1]); - min_coords[2] = std::min(vertex.p_.z, min_coords[2]); - max_coords[0] = std::max(vertex.p_.x, max_coords[0]); - max_coords[1] = std::max(vertex.p_.y, max_coords[1]); - max_coords[2] = std::max(vertex.p_.z, max_coords[2]); + min_coords[0] = std::min(vertex.p_.x_, min_coords[0]); + min_coords[1] = std::min(vertex.p_.y_, min_coords[1]); + min_coords[2] = std::min(vertex.p_.z_, min_coords[2]); + max_coords[0] = std::max(vertex.p_.x_, max_coords[0]); + max_coords[1] = std::max(vertex.p_.y_, max_coords[1]); + max_coords[2] = std::max(vertex.p_.z_, max_coords[2]); } // - Then, just compare: diff --git a/tests/arcus/MockCommunication.h b/tests/arcus/MockCommunication.h index 1db835ffb7..f2401025fd 100644 --- a/tests/arcus/MockCommunication.h +++ b/tests/arcus/MockCommunication.h @@ -4,11 +4,12 @@ #ifndef MOCKCOMMUNICATION_H #define MOCKCOMMUNICATION_H +#include + #include "communication/Communication.h" //The interface we're implementing. +#include "settings/types/LayerIndex.h" #include "utils/Coord_t.h" #include "utils/polygon.h" //In the signature of Communication. -#include -#include "settings/types/LayerIndex.h" namespace cura { @@ -21,27 +22,14 @@ class MockCommunication : public Communication public: MOCK_CONST_METHOD0(hasSlice, bool()); MOCK_CONST_METHOD0(isSequential, bool()); - MOCK_CONST_METHOD1(sendProgress, void(const float& progress)); + 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(sendPolygon, - void(const PrintFeatureType& type, - const ConstPolygonRef& polygon, - const coord_t& line_width, - const coord_t& line_thickness, - const Velocity& velocity)); - MOCK_METHOD5(sendLineTo, - void(const PrintFeatureType& type, - const Point& to, - const coord_t& line_width, - const coord_t& line_thickness, - const Velocity& velocity)); - MOCK_METHOD1(sendCurrentPosition, void(const Point& position)); + 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( + sendPolygon, + void(const PrintFeatureType& type, const ConstPolygonRef& 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)); MOCK_METHOD1(setExtruderForSend, void(const ExtruderTrain& extruder)); MOCK_METHOD1(setLayerForSend, void(const LayerIndex::value_type& layer_nr)); MOCK_METHOD0(sendOptimizedLayerData, void()); @@ -56,4 +44,4 @@ class MockCommunication : public Communication } // namespace cura -#endif // MOCKCOMMUNICATION_H \ No newline at end of file +#endif // MOCKCOMMUNICATION_H diff --git a/tests/integration/SlicePhaseTest.cpp b/tests/integration/SlicePhaseTest.cpp index 291c2acd15..95fd638fa1 100644 --- a/tests/integration/SlicePhaseTest.cpp +++ b/tests/integration/SlicePhaseTest.cpp @@ -79,7 +79,7 @@ TEST_F(SlicePhaseTest, Cube) const auto initial_layer_thickness = scene.settings.get("layer_height_0"); constexpr bool variable_layer_height = false; constexpr std::vector* variable_layer_height_values = nullptr; - const size_t num_layers = (cube_mesh.getAABB().max_.z - initial_layer_thickness) / layer_thickness + 1; + const size_t num_layers = (cube_mesh.getAABB().max_.z_ - initial_layer_thickness) / layer_thickness + 1; Slicer slicer(&cube_mesh, layer_thickness, num_layers, variable_layer_height, variable_layer_height_values); ASSERT_EQ(slicer.layers.size(), num_layers) << "The number of layers in the output must equal the requested number of layers."; @@ -140,7 +140,7 @@ TEST_F(SlicePhaseTest, Cylinder1000) const auto initial_layer_thickness = scene.settings.get("layer_height_0"); constexpr bool variable_layer_height = false; constexpr std::vector* variable_layer_height_values = nullptr; - const size_t num_layers = (cylinder_mesh.getAABB().max_.z - initial_layer_thickness) / layer_thickness + 1; + const size_t num_layers = (cylinder_mesh.getAABB().max_.z_ - initial_layer_thickness) / layer_thickness + 1; Slicer slicer(&cylinder_mesh, layer_thickness, num_layers, variable_layer_height, variable_layer_height_values); ASSERT_EQ(slicer.layers.size(), num_layers) << "The number of layers in the output must equal the requested number of layers."; diff --git a/tests/settings/SettingsTest.cpp b/tests/settings/SettingsTest.cpp index 8486ce2292..c8f7814db8 100644 --- a/tests/settings/SettingsTest.cpp +++ b/tests/settings/SettingsTest.cpp @@ -3,6 +3,11 @@ #include "settings/Settings.h" //The class under test. +#include //For std::numbers::pi. +#include //For shared_ptr. + +#include + #include "Application.h" //To test extruder train settings. #include "ExtruderTrain.h" #include "Slice.h" @@ -17,10 +22,6 @@ #include "utils/Coord_t.h" #include "utils/Matrix4x3D.h" //Testing matrix transformation settings. -#include //For std::numbers::pi. -#include -#include //For shared_ptr. - // NOLINTBEGIN(*-magic-numbers) namespace cura { @@ -124,7 +125,8 @@ TEST_F(SettingsTest, AddSettingAngleRadians) EXPECT_DOUBLE_EQ(AngleRadians(std::numbers::pi), settings.get("test_setting")) << "180 degrees is 1 pi radians."; settings.add("test_setting", "810"); - EXPECT_NEAR(AngleRadians(std::numbers::pi / 2.0), settings.get("test_setting"), 0.00000001) << "810 degrees in clock arithmetic is 90 degrees, which is 0.5 pi radians."; + EXPECT_NEAR(AngleRadians(std::numbers::pi / 2.0), settings.get("test_setting"), 0.00000001) + << "810 degrees in clock arithmetic is 90 degrees, which is 0.5 pi radians."; } TEST_F(SettingsTest, AddSettingAngleDegrees) @@ -142,7 +144,7 @@ TEST_F(SettingsTest, AddSettingTemperature) TEST_F(SettingsTest, AddSettingVelocity) { settings.add("test_setting", "12.345"); - EXPECT_DOUBLE_EQ(Velocity { 12.345 }, settings.get("test_setting")); + EXPECT_DOUBLE_EQ(Velocity{ 12.345 }, settings.get("test_setting")); settings.add("test_setting", "-78"); EXPECT_DOUBLE_EQ(Velocity{ -78.0 }, settings.get("test_setting")); @@ -151,16 +153,16 @@ TEST_F(SettingsTest, AddSettingVelocity) TEST_F(SettingsTest, AddSettingRatio) { settings.add("test_setting", "1.618"); - EXPECT_DOUBLE_EQ(Ratio { 0.01618 }, settings.get("test_setting")) << "With ratios, the input is interpreted in percentages."; + EXPECT_DOUBLE_EQ(Ratio{ 0.01618 }, settings.get("test_setting")) << "With ratios, the input is interpreted in percentages."; } TEST_F(SettingsTest, AddSettingDuration) { settings.add("test_setting", "1234.5678"); - EXPECT_DOUBLE_EQ(Duration { 1234.5678 }, settings.get("test_setting")); + EXPECT_DOUBLE_EQ(Duration{ 1234.5678 }, settings.get("test_setting")); settings.add("test_setting", "-1234.5678"); - EXPECT_DOUBLE_EQ(Duration { 0 }, settings.get("test_setting")) << "Negative duration doesn't exist, so it gets rounded to 0."; + EXPECT_DOUBLE_EQ(Duration{ 0 }, settings.get("test_setting")) << "Negative duration doesn't exist, so it gets rounded to 0."; } TEST_F(SettingsTest, AddSettingFlowTempGraph) @@ -244,7 +246,7 @@ TEST_F(SettingsTest, LimitToExtruder) // Add a setting to the extruder this is limiting to. const std::string limit_extruder_value = "I was gonna tell a time travelling joke but you didn't like it."; - current_slice->scene.extruders[2].settings.add("test_setting", limit_extruder_value); + current_slice->scene.extruders[2].settings_.add("test_setting", limit_extruder_value); current_slice->scene.limit_to_extruder.emplace("test_setting", ¤t_slice->scene.extruders[2]); // Add a decoy setting to the main scene to make sure that we aren't getting the global setting instead. diff --git a/tests/utils/LinearAlg2DTest.cpp b/tests/utils/LinearAlg2DTest.cpp index 4593c4c57c..b9e4f41bb0 100644 --- a/tests/utils/LinearAlg2DTest.cpp +++ b/tests/utils/LinearAlg2DTest.cpp @@ -2,7 +2,9 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "utils/linearAlg2D.h" + #include + #include // NOLINTBEGIN(*-magic-numbers) @@ -61,43 +63,47 @@ TEST_P(GetDist2FromLineSegmentTest, GetDist2FromLineSegment) const coord_t supposed_distance = LinearAlg2D::getDist2FromLineSegment(line_start, point, line_end, &supposed_is_beyond); // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 - ASSERT_LE(std::fabs(sqrt(double(supposed_distance)) - sqrt(double(actual_distance2))), maximum_error) << "Line [" << line_start.X << ", " << line_start.Y << "] -- [" << line_end.X << ", " << line_end.Y << "], point [" << point.X << ", " - << point.Y << "], squared distance was " << supposed_distance << " rather than " << actual_distance2 << "."; - ASSERT_EQ(supposed_is_beyond, actual_is_beyond) << "Line [" << line_start.X << ", " << line_start.Y << "] -- [" << line_end.X << ", " << line_end.Y << "], point [" << point.X << ", " << point.Y << "], check whether it is beyond was " - << static_cast(supposed_is_beyond) << " rather than " << static_cast(actual_is_beyond) << "."; + ASSERT_LE(std::fabs(sqrt(double(supposed_distance)) - sqrt(double(actual_distance2))), maximum_error) + << "Line [" << line_start.X << ", " << line_start.Y << "] -- [" << line_end.X << ", " << line_end.Y << "], point [" << point.X << ", " << point.Y + << "], squared distance was " << supposed_distance << " rather than " << actual_distance2 << "."; + ASSERT_EQ(supposed_is_beyond, actual_is_beyond) << "Line [" << line_start.X << ", " << line_start.Y << "] -- [" << line_end.X << ", " << line_end.Y << "], point [" << point.X + << ", " << point.Y << "], check whether it is beyond was " << static_cast(supposed_is_beyond) << " rather than " + << static_cast(actual_is_beyond) << "."; } -INSTANTIATE_TEST_CASE_P(GetDist2FromLineSegmentInstantiation, - GetDist2FromLineSegmentTest, - testing::Values(GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(25, 3), 9, 0), // Nearby a horizontal line. - GetDist2FromLineSegmentParametersPoint2LLt(0, 0)Point2LLnt(100, 0)Point2LLnt(25, 0), 0, 0), // On a horizontal line. - Point2LLst2FromLineSegmentParameters(Point(0, 0Point2LLint(100, 0Point2LLint(200, 0), 10000, 1), // Beyond a horizontal line. - GetDist2FromLineSegmentParametersPoint2LLt(0, PointPoint2LLnt(100, PointPoint2LLnt(-100, 0), 10000, -1)Point2LLBefore a horizontal line. - GetDist2FromLineSegmentParametersPoint2LLt(0Point2LPoint2LLnt(100Point2LPoint2LLnt(-1, -1), 2, -1Point2LL In a corner near a horizontal line. - GetDist2FromLineSegmentParameters(Point(Point2LL, Point(Point2LL0), Point(0, 3), 9, Point2LL/ Perpendicular to a horizontal line. - GetDist2FromLineSegmentParameters(PointPoint2LL), PointPoint2LL00), Point(5, 25), 25Point2LL // Nearby a vertical line. - GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point(0, 25), Point2LL, // On a vertical line. - GetDist2FromLineSegmentParametersPoint2LLt(0, 0)Point2LLnt(0, 100), Point(0, 200)Point2LL00Point2LL // Beyond a vertical line. - Point2LLst2FromLineSegmentParameters(Point2LL(0, 0Point2Point2LL(0, 100), Point(0, -100)Point2LL00, Point2LL// Before a vertical line. - GetDist2FromLineSegmentParameters(Point2LL(0, Point2LPoint2LL(0, 100), Point(-1, -1Point2LL -1)Point2LLIn a corner near a vertical line. - GetDist2FromLineSegmentParameters(Point(0Point2LL Point(0, 100), Point(3Point2LL 9, 0Point2LL Perpendicular to a vertical line. - GetDist2FromLineSegmentParameters(Point(Point2LL, Point(100, 100), Point(Point2LL0), 50, Point2LL/ Nearby a diagonal line. - GetDist2FromLineSegmentParameters(PointPoint2LL), Point(100, 100), PointPoint2LL25), 0Point2LL // On a diagonal line. - GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point(100, 100), Point2LL(200Point2LL), Point2LL, 1Point2LL Beyond a diagonal line. - GetDist2FromLineSegmentParametersPoint2LLt(Point2LL, Point(100, 100), Point(Point2LPoint2LL0), Point2LL, Point2LL// Before a diagonal line. - Point2LLst2FromLineSegmentParameters(Point2LL(0, 0), Point(100, 100), Point2LLPoint2LL0)PointPoint2LL), // In a corner near a diagonal line. - Point2LLst2FromLineSegmentParameters(Point(0, 0), Point(100, 100Point2LLint(3, -Point2LL, 0)Point2LLPerpendicular to a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), Point(100Point2LL, Point(20Point2LL, 320, 0Point2LL Nearby a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), Point(Point2LL50), Point(Point2LL0), 0, Point2LL/ On a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), PointPoint2LL 50), PointPoint2LL), 0Point2LL // On one of the vertices of the diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), Point2LL(100Point2LL, Point2LL(200Point2LL), Point2LL, 1Point2LL Beyond a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), Point(Point2LLPoint2LLPoint(Point2LPoint2LL), Point2LL, Point2LL// Before a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0), Point2LLPoint2LL 50), Point2LLPoint2LL0)PointPoint2LL), // In a corner near a diagonal line. - GetDist2FromLineSegmentParameters(Point(0, 0Point2LLint(100, 50Point2LLint(-2, Point2LL0, 0), // Perpendicular to a diagonal line. - GetDist2FromLineSegmentParameters(Point(0Point2LL Point(10000Point2LL0), Point(2000Point2LL0), 3200000, 0), // Longer distances. - GetDist2FromLineSegmentParameters(Point(Point2LL, Point(Point2LL, Point(Point2LL), 400, 0), // Near a line of length 0. - GetDist2FromLineSegmentParameters(Point(0, 0), Point(0, 0), Point(0, 0), 0, 0) // On a line of length 0. - )); +INSTANTIATE_TEST_CASE_P( + GetDist2FromLineSegmentInstantiation, + GetDist2FromLineSegmentTest, + testing::Values( + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(25, 3), 9, 0), // Nearby a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(25, 0), 0, 0), // On a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(200, 0), 10000, 1), // Beyond a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(-100, 0), 10000, -1), // Before a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(-1, -1), 2, -1), // In a corner near a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 0), Point2LL(0, 3), 9, 0), // Perpendicular to a horizontal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(5, 25), 25, 0), // Nearby a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(0, 25), 0, 0), // On a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(0, 200), 10000, 1), // Beyond a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(0, -100), 10000, -1), // Before a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(-1, -1), 2, -1), // In a corner near a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 100), Point2LL(3, 0), 9, 0), // Perpendicular to a vertical line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(30, 20), 50, 0), // Nearby a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(25, 25), 0, 0), // On a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(200, 200), 20000, 1), // Beyond a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(-100, -100), 20000, -1), // Before a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(-3, 0), 9, -1), // In a corner near a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 100), Point2LL(3, -3), 9, 0), // Perpendicular to a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(20, 30), 320, 0), // Nearby a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(40, 20), 0, 0), // On a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(0, 0), 0, 0), // On one of the vertices of the diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(200, 100), 12500, 1), // Beyond a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(-100, -50), 12500, -1), // Before a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(-3, 0), 9, -1), // In a corner near a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(100, 50), Point2LL(-2, 4), 20, 0), // Perpendicular to a diagonal line. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(10000, 5000), Point2LL(2000, 3000), 3200000, 0), // Longer distances. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 0), Point2LL(20, 0), 400, 0), // Near a line of length 0. + GetDist2FromLineSegmentParameters(Point2LL(0, 0), Point2LL(0, 0), Point2LL(0, 0), 0, 0) // On a line of length 0. + )); // NOLINTBEGIN(misc-non-private-member-variables-in-classes) struct GetAngleParameters @@ -107,7 +113,11 @@ struct GetAngleParameters Point2LL c; double angle; // In degrees. - GetAngleParameters(Point2LL a, Point2LL b, Point2LL c, double angle) : a(a), b(b), c(c), angle(angle) + GetAngleParameters(Point2LL a, Point2LL b, Point2LL c, double angle) + : a(a) + , b(b) + , c(c) + , angle(angle) { } }; @@ -135,20 +145,23 @@ TEST_P(GetAngleTest, GetAngle) const double angle = angle_degrees * std::numbers::pi / 180.0; const double supposed_angle = LinearAlg2D::getAngleLeft(a, b, c); - ASSERT_LE(std::fabs(angle - supposed_angle), maximum_error) << "Corner in " << a << " - " << b << " - " << c << " was computed to have an angle of " << supposed_angle << " instead of " << angle << "."; + ASSERT_LE(std::fabs(angle - supposed_angle), maximum_error) + << "Corner in " << a << " - " << b << " - " << c << " was computed to have an angle of " << supposed_angle << " instead of " << angle << "."; } -INSTANTIATE_TEST_CASE_P(GetAngleInstantiation, - GetAngleTest, - testing::Values(GetAngleParameters(Point2LL(-100, 0)Point2LLnt2LL(0, 0), Point2LL(100, Point2LL80), // Almost straight line. - GetAngleParametersPoint2LLt(-100, 0Point2LLt2LLnt(0, 0)Point2LLnt(100Point2LL 180), // Completely straight line. - Point2LLgleParameters(Point(-100, Point2LLt2LLint(0, 0Point2LLint(-100Point2LL0), 315), //-45 degrees. - GetAngleParameters(Point(-100Point2LLnt2LLoint(0, Point2LLoint(Point2LL00), 270)Point2LL90 degrees. - GetAngleParameters(Point(-Point2LLint2LL Point(0Point2LL Point2LL(0, 100), 90Point2LL Straight angle. - GetAngleParameters(Point(Point2LLt2LL0), Point(Point2LL, Point2LL(-100, 1), Point2LL/ Almost straight back. - GetAngleParameters(PointPoint2LLt2LL 0), PointPoint2LL), Point2LL(-100, -1)Point2LL), // Almost straight back but the other way around. - GetAngleParameters(Point2LLPoint2LL, 0), Point2LL(0, 0), Point(-100, 0), 0) // Completely straight back. - )); +INSTANTIATE_TEST_CASE_P( + GetAngleInstantiation, + GetAngleTest, + testing::Values( + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(100, 1), 180), // Almost straight line. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(100, 0), 180), // Completely straight line. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(-100, -100), 315), //-45 degrees. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(0, -100), 270), //-90 degrees. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(0, 100), 90), // Straight angle. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(-100, 1), 0), // Almost straight back. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(-100, -1), 360), // Almost straight back but the other way around. + GetAngleParameters(Point2LL(-100, 0), Point2LL(0, 0), Point2LL(-100, 0), 0) // Completely straight back. + )); TEST(GetAngleTest, GetAngleLeftAABTest) { @@ -175,8 +188,9 @@ TEST(PointIsLeftOfLineTest, LeftOfLine) const coord_t supposed = LinearAlg2D::pointIsLeftOfLine(p, a, b); // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 - ASSERT_TRUE(actual * supposed > 0 || (actual == 0 && supposed == 0)) << "Point " << p << " was computed as lying " << ((supposed == 0) ? "on" : ((supposed < 0) ? "left" : "right")) << " the line from " << a << " to " << b - << ", instead of " << ((actual == 0) ? "on" : ((actual < 0) ? "left" : "right")); + ASSERT_TRUE(actual * supposed > 0 || (actual == 0 && supposed == 0)) + << "Point " << p << " was computed as lying " << ((supposed == 0) ? "on" : ((supposed < 0) ? "left" : "right")) << " the line from " << a << " to " << b << ", instead of " + << ((actual == 0) ? "on" : ((actual < 0) ? "left" : "right")); } TEST(PointIsLeftOfLineTest, Sharp) @@ -188,8 +202,9 @@ TEST(PointIsLeftOfLineTest, Sharp) const coord_t supposed = LinearAlg2D::pointIsLeftOfLine(p, a, b); // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 - ASSERT_TRUE(actual * supposed > 0 || (actual == 0 && supposed == 0)) << "Point " << p << " was computed as lying " << ((supposed == 0) ? "on" : ((supposed < 0) ? "left" : "right")) << " the line from " << a << " to " << b - << ", instead of " << ((actual == 0) ? "on" : ((actual < 0) ? "left" : "right")); + ASSERT_TRUE(actual * supposed > 0 || (actual == 0 && supposed == 0)) + << "Point " << p << " was computed as lying " << ((supposed == 0) ? "on" : ((supposed < 0) ? "left" : "right")) << " the line from " << a << " to " << b << ", instead of " + << ((actual == 0) ? "on" : ((actual < 0) ? "left" : "right")); } // NOLINTBEGIN(misc-non-private-member-variables-in-classes) @@ -202,7 +217,13 @@ struct GetPointOnLineWithDistParameters Point2LL actual_result; bool actual_returned; - GetPointOnLineWithDistParameters(Point2LL p, Point2LL a, Point2LL b, coord_t dist, Point2LL actual_result, bool actual_returned) : p(p), a(a), b(b), dist(dist), actual_result(actual_result), actual_returned(actual_returned) + GetPointOnLineWithDistParameters(Point2LL p, Point2LL a, Point2LL b, coord_t dist, Point2LL actual_result, bool actual_returned) + : p(p) + , a(a) + , b(b) + , dist(dist) + , actual_result(actual_result) + , actual_returned(actual_returned) { } }; @@ -233,7 +254,8 @@ TEST_P(GetPointOnLineWithDistTest, GetPointOnLineWithDist) if (actual_returned) { EXPECT_TRUE(supposed_returned) << "Point " << p << " wasn't projected on (" << a << " - " << b << ") instead of projecting to " << actual_result << "."; - EXPECT_LT(vSize2(actual_result - supposed_result), 10 * 10) << "Point " << p << " was projected on (" << a << " - " << b << ") to " << supposed_result << " instead of " << actual_result << "."; + EXPECT_LT(vSize2(actual_result - supposed_result), 10 * 10) + << "Point " << p << " was projected on (" << a << " - " << b << ") to " << supposed_result << " instead of " << actual_result << "."; EXPECT_LT(std::abs(supposed_dist - dist), 10) << "Projection distance of " << p << " onto (" << a << " - " << b << ") was " << supposed_dist << " instead of " << dist << "."; // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 } @@ -243,15 +265,17 @@ TEST_P(GetPointOnLineWithDistTest, GetPointOnLineWithDist) } } -INSTANTIATE_TEST_CASE_P(GetPointOnLineWithDistInstantiation, - GetPointOnLineWithDistTest, - testing::Values(GetPointOnLineWithDistParameters(Point2LL(110, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), true), - GetPointOnLineWithDistParameters(Point2LL(90, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(50, 0), true), - GetPointOnLineWithDistParameters(Point2LL(10, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(50, 0), true), - GetPointOnLineWithDistParameters(Point2LL(-10, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(30, 0), true), - GetPointOnLineWithDistParameters(Point2LL(50, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(10, 0), true), - GetPointOnLineWithDistParameters(Point2LL(210, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), false), - GetPointOnLineWithDistParameters(Point2LL(110, 130), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), false))); +INSTANTIATE_TEST_CASE_P( + GetPointOnLineWithDistInstantiation, + GetPointOnLineWithDistTest, + testing::Values( + GetPointOnLineWithDistParameters(Point2LL(110, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), true), + GetPointOnLineWithDistParameters(Point2LL(90, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(50, 0), true), + GetPointOnLineWithDistParameters(Point2LL(10, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(50, 0), true), + GetPointOnLineWithDistParameters(Point2LL(-10, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(30, 0), true), + GetPointOnLineWithDistParameters(Point2LL(50, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(10, 0), true), + GetPointOnLineWithDistParameters(Point2LL(210, 30), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), false), + GetPointOnLineWithDistParameters(Point2LL(110, 130), Point2LL(0, 0), Point2LL(100, 0), 50, Point2LL(70, 0), false))); // NOLINTBEGIN(misc-non-private-member-variables-in-classes) struct RotateAroundParameters @@ -261,7 +285,11 @@ struct RotateAroundParameters double angle; Point2LL actual_result; - RotateAroundParameters(Point2LL point, Point2LL origin, double angle, Point2LL actual_result) : point(point), origin(origin), angle(angle), actual_result(actual_result) + RotateAroundParameters(Point2LL point, Point2LL origin, double angle, Point2LL actual_result) + : point(point) + , origin(origin) + , angle(angle) + , actual_result(actual_result) { } }; @@ -285,19 +313,23 @@ TEST_P(RotateAroundTest, RotateAround) const Point3Matrix mat = LinearAlg2D::rotateAround(origin, angle); const Point2LL supposed_result = mat.apply(point); - ASSERT_LT(vSize(supposed_result - actual_result), 2) << "LinearAlg2D::rotateAround failed: Rotating " << point << " around " << origin << " for " << angle << " degrees resulted in " << supposed_result << " instead of expected " - << actual_result << "."; + ASSERT_LT(vSize(supposed_result - actual_result), 2) << "LinearAlg2D::rotateAround failed: Rotating " << point << " around " << origin << " for " << angle + << " degrees resulted in " << supposed_result << " instead of expected " << actual_result << "."; } -INSTANTIATE_TEST_SUITE_P(RotateAroundInstantiation, - RotateAroundTest, - testing::Values(RotateAroundParameters(Point2LL(25, 30), Point2LL(10, 17), 90, Point2LL(-3, 32)), // 90 degrees rotation. - RotateAroundParameters(Point2LL(25, 30), Point2LL(10, 17), -90, Point2LL(23, 2)), //-90 degrees rotation. - RotateAroundParameters(Point2LL(-67, 14), Point2LL(50, 50), 0, Point2LL(-67, 14)), // No rotation at all. - RotateAroundParameters(Point2LL(-67, 14), Point2LL(50, 50), 12, Point2LL(-57, -9)) // 12 degrees rotation. Actually ends up at [-57, -9.5]! - )); - -class Temp {}; +INSTANTIATE_TEST_SUITE_P( + RotateAroundInstantiation, + RotateAroundTest, + testing::Values( + RotateAroundParameters(Point2LL(25, 30), Point2LL(10, 17), 90, Point2LL(-3, 32)), // 90 degrees rotation. + RotateAroundParameters(Point2LL(25, 30), Point2LL(10, 17), -90, Point2LL(23, 2)), //-90 degrees rotation. + RotateAroundParameters(Point2LL(-67, 14), Point2LL(50, 50), 0, Point2LL(-67, 14)), // No rotation at all. + RotateAroundParameters(Point2LL(-67, 14), Point2LL(50, 50), 12, Point2LL(-57, -9)) // 12 degrees rotation. Actually ends up at [-57, -9.5]! + )); + +class Temp +{ +}; TEST(Temp, LineDistTests) { @@ -306,7 +338,7 @@ TEST(Temp, LineDistTests) { const Point2LL p{ 500000 + (std::rand() % 4000) - 2000, 500000 + (std::rand() % 4000) - 2000 }; - const coord_t d = (std::rand() % 2000) - 1000 /2; + const coord_t d = (std::rand() % 2000) - 1000 / 2; const double rang = std::rand() / (static_cast(RAND_MAX) / 6.29); const Point2LL x{ p.X + static_cast(d * std::cos(rang)), p.Y - static_cast(d * std::sin(rang)) }; diff --git a/tests/utils/PolygonUtilsTest.cpp b/tests/utils/PolygonUtilsTest.cpp index 04f668cab2..f859a48c08 100644 --- a/tests/utils/PolygonUtilsTest.cpp +++ b/tests/utils/PolygonUtilsTest.cpp @@ -2,10 +2,12 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "utils/polygonUtils.h" // The class under test. + +#include + #include "utils/Coord_t.h" #include "utils/Point2LL.h" // Creating and testing with points. #include "utils/polygon.h" // Creating polygons to test with. -#include // NOLINTBEGIN(*-magic-numbers) namespace cura @@ -17,7 +19,10 @@ struct MoveInsideParameters coord_t distance; Point2LL supposed; - MoveInsideParameters(Point2LL close_to, const coord_t distance, Point2LL supposed) : close_to(close_to), distance(distance), supposed(supposed) + MoveInsideParameters(Point2LL close_to, const coord_t distance, Point2LL supposed) + : close_to(close_to) + , distance(distance) + , supposed(supposed) { } }; @@ -55,9 +60,11 @@ TEST_P(MoveInsideTest, MoveInside) Point2LL result = PolygonUtils::moveInside(cpp, parameters.distance); // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 - ASSERT_LE(vSize(result - parameters.supposed), 10) << parameters.close_to << " moved with " << parameters.distance << " micron inside to " << result << " rather than " << parameters.supposed << ".\n" - << "\tPS: dist to boundary computed = " << vSize(cpp.location - result) << "; vs supposed = " << vSize(cpp.location - parameters.supposed) << ".\n" - << "\tclosest_point = " << cpp.location << " at index " << cpp.point_idx << "."; + ASSERT_LE(vSize(result - parameters.supposed), 10) << parameters.close_to << " moved with " << parameters.distance << " micron inside to " << result << " rather than " + << parameters.supposed << ".\n" + << "\tPS: dist to boundary computed = " << vSize(cpp.location_ - result) + << "; vs supposed = " << vSize(cpp.location_ - parameters.supposed) << ".\n" + << "\tclosest_point = " << cpp.location_ << " at index " << cpp.point_idx_ << "."; } TEST_P(MoveInsideTest, MoveInside2) @@ -67,21 +74,24 @@ TEST_P(MoveInsideTest, MoveInside2) polys.add(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 " << parameters.supposed << "."; + ASSERT_LE(vSize(result - parameters.supposed), 10) << parameters.close_to << " moved with " << parameters.distance << " micron inside to " << result << "rather than " + << parameters.supposed << "."; } -INSTANTIATE_TEST_SUITE_P(MoveInsideInstantiation, - MoveInsideTest, - testing::Values(MoveInsideParameters(Point2LL(110, 110), 28, Point2LL(80, 80)), // Near a corner, moving inside. - MoveInsideParameters(Point2LL(50, 110), 20, Point2LL(50, 80)), // Near an edge, moving inside. - MoveInsideParameters(Point2LL(110, 110), -28, Point2LL(120, 120)), // Near a corner, moving outside. - MoveInsideParameters(Point2LL(50, 110), -20, Point2LL(50, 120)), // Near an edge, moving outside. - MoveInsideParameters(Point2LL(110, 105), 28, Point2LL(80, 80)), // Near a corner but not exactly diagonal. - MoveInsideParameters(Point2LL(100, 50), 20, Point2LL(80, 50)), // Starting on the border. - MoveInsideParameters(Point2LL(80, 50), 20, Point2LL(80, 50)), // Already inside. - MoveInsideParameters(Point2LL(110, 50), 0, Point2LL(100, 50)), // Not keeping any distance from the border. - MoveInsideParameters(Point2LL(110, 50), 100000, Point2LL(-99900, 50)) // A very far move. - )); +INSTANTIATE_TEST_SUITE_P( + MoveInsideInstantiation, + MoveInsideTest, + testing::Values( + MoveInsideParameters(Point2LL(110, 110), 28, Point2LL(80, 80)), // Near a corner, moving inside. + MoveInsideParameters(Point2LL(50, 110), 20, Point2LL(50, 80)), // Near an edge, moving inside. + MoveInsideParameters(Point2LL(110, 110), -28, Point2LL(120, 120)), // Near a corner, moving outside. + MoveInsideParameters(Point2LL(50, 110), -20, Point2LL(50, 120)), // Near an edge, moving outside. + MoveInsideParameters(Point2LL(110, 105), 28, Point2LL(80, 80)), // Near a corner but not exactly diagonal. + MoveInsideParameters(Point2LL(100, 50), 20, Point2LL(80, 50)), // Starting on the border. + MoveInsideParameters(Point2LL(80, 50), 20, Point2LL(80, 50)), // Already inside. + MoveInsideParameters(Point2LL(110, 50), 0, Point2LL(100, 50)), // Not keeping any distance from the border. + MoveInsideParameters(Point2LL(110, 50), 100000, Point2LL(-99900, 50)) // A very far move. + )); TEST_F(MoveInsideTest, cornerEdgeTest) { @@ -97,8 +107,9 @@ TEST_F(MoveInsideTest, cornerEdgeTest) // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 ASSERT_TRUE(vSize(result - supposed1) <= maximum_error || vSize(result - supposed2) <= maximum_error) << close_to << " moved with " << distance << " micron inside to " << result << " rather than " << supposed1 << " or " << supposed2 << ".\n" - << "\tPS: dist to boundary computed = " << vSize(cpp.location - result) << "; vs supposed = " << vSize(cpp.location - supposed1) << " or " << vSize(cpp.location - supposed2) << ".\n" - << "\tclosest point = " << cpp.location << " at index " << cpp.point_idx << "."; + << "\tPS: dist to boundary computed = " << vSize(cpp.location_ - result) << "; vs supposed = " << vSize(cpp.location_ - supposed1) << " or " + << vSize(cpp.location_ - supposed2) << ".\n" + << "\tclosest point = " << cpp.location_ << " at index " << cpp.point_idx_ << "."; } TEST_F(MoveInsideTest, middleTest) @@ -115,11 +126,14 @@ TEST_F(MoveInsideTest, middleTest) constexpr coord_t maximum_error = 10; // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 - ASSERT_TRUE(vSize(result - supposed1) <= maximum_error || vSize(result - supposed2) <= maximum_error || vSize(result - supposed3) <= maximum_error || vSize(result - supposed4) <= maximum_error) - << close_to << " moved with " << distance << " micron inside to " << result << " rather than " << supposed1 << ", " << supposed2 << ", " << supposed3 << " or " << supposed4 << ".\n" - << "\tPS: dist to boundary computed = " << vSize(cpp.location - result) << "; vs supposed = " << vSize(cpp.location - supposed1) << ", " << vSize(cpp.location - supposed2) << ", " << vSize(cpp.location - supposed3) << " or " - << vSize(cpp.location - supposed4) << ".\n" - << "\tclosest point = " << cpp.location << " at index " << cpp.point_idx << "."; + ASSERT_TRUE( + vSize(result - supposed1) <= maximum_error || vSize(result - supposed2) <= maximum_error || vSize(result - supposed3) <= maximum_error + || vSize(result - supposed4) <= maximum_error) + << close_to << " moved with " << distance << " micron inside to " << result << " rather than " << supposed1 << ", " << supposed2 << ", " << supposed3 << " or " << supposed4 + << ".\n" + << "\tPS: dist to boundary computed = " << vSize(cpp.location_ - result) << "; vs supposed = " << vSize(cpp.location_ - supposed1) << ", " + << vSize(cpp.location_ - supposed2) << ", " << vSize(cpp.location_ - supposed3) << " or " << vSize(cpp.location_ - supposed4) << ".\n" + << "\tclosest point = " << cpp.location_ << " at index " << cpp.point_idx_ << "."; } TEST_F(MoveInsideTest, middleTestPenalty) @@ -128,13 +142,20 @@ TEST_F(MoveInsideTest, middleTestPenalty) const Point2LL supposed(80, 50); const Point2LL preferred_dir(120, 60); constexpr coord_t distance = 20; - const ClosestPolygonPoint cpp = PolygonUtils::findClosest(close_to, test_square, [preferred_dir](Point2LL candidate) { return vSize2(candidate - preferred_dir); }); + const ClosestPolygonPoint cpp = PolygonUtils::findClosest( + close_to, + test_square, + [preferred_dir](Point2LL candidate) + { + return vSize2(candidate - preferred_dir); + }); const Point2LL result = PolygonUtils::moveInside(cpp, distance); // FIXME: Clean-up message with ftm when CURA-8258 is implemented or when we use C++20 ASSERT_LE(vSize(result - supposed), 10) << close_to << " moved with " << distance << " micron inside to " << result << " rather than " << supposed << ".\n" - << "\tPS: dist to boundary computed = " << vSize(cpp.location - result) << "; vs supposed = " << vSize(cpp.location - supposed) << ".\n" - << "\tclosest point = " << cpp.location << " at index " << cpp.point_idx << "."; + << "\tPS: dist to boundary computed = " << vSize(cpp.location_ - result) << "; vs supposed = " << vSize(cpp.location_ - supposed) + << ".\n" + << "\tclosest point = " << cpp.location_ << " at index " << cpp.point_idx_ << "."; } TEST_F(MoveInsideTest, cornerEdgeTest2) @@ -161,8 +182,8 @@ TEST_F(MoveInsideTest, pointyCorner) inside.add(pointy_square); ClosestPolygonPoint cpp = PolygonUtils::ensureInsideOrOutside(inside, result, 10); - ASSERT_NE(cpp.point_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; - ASSERT_NE(cpp.poly_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.poly_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; ASSERT_TRUE(inside.inside(result)) << from << " couldn't be moved inside."; } @@ -175,8 +196,8 @@ TEST_F(MoveInsideTest, pointyCornerFail) inside.add(pointy_square); ClosestPolygonPoint cpp = PolygonUtils::moveInside2(inside, result, 10); - ASSERT_NE(cpp.point_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; - ASSERT_NE(cpp.poly_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.poly_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; ASSERT_FALSE(inside.inside(result)) << from << " could be moved inside, while it was designed to fail."; } @@ -189,8 +210,8 @@ TEST_F(MoveInsideTest, outsidePointyCorner) inside.add(pointy_square); const ClosestPolygonPoint cpp = PolygonUtils::ensureInsideOrOutside(inside, result, -10); - ASSERT_NE(cpp.point_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; - ASSERT_NE(cpp.poly_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.poly_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; ASSERT_TRUE(! inside.inside(result)) << from << " couldn't be moved outside."; } @@ -204,8 +225,8 @@ TEST_F(MoveInsideTest, outsidePointyCornerFail) inside.add(pointy_square); const ClosestPolygonPoint cpp = PolygonUtils::moveInside2(inside, result, -10); - ASSERT_NE(cpp.point_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; - ASSERT_NE(cpp.poly_idx, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.point_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; + ASSERT_NE(cpp.poly_idx_, NO_INDEX) << "Couldn't ensure point inside close to " << from << "."; ASSERT_FALSE(! inside.inside(result)) << from << " could be moved outside to " << result << ", while it was designed to fail."; } @@ -214,9 +235,9 @@ struct FindCloseParameters Point2LL close_to; Point2LL supposed; coord_t cell_size; - std::function* penalty_function; + std::function* penalty_function; - FindCloseParameters(const Point2LL close_to, const Point2LL supposed, const coord_t cell_size, std::function* penalty_function = nullptr) + FindCloseParameters(const Point2LL close_to, const Point2LL supposed, const coord_t cell_size, std::function* penalty_function = nullptr) : close_to(close_to) , supposed(supposed) , cell_size(cell_size) @@ -260,7 +281,7 @@ TEST_P(FindCloseTest, FindClose) if (cpp) { - const Point2LL result = cpp->location; + const Point2LL result = cpp->location_; ASSERT_LE(vSize(result - parameters.supposed), 10) << "Close to " << parameters.close_to << " we found " << result << " rather than " << parameters.supposed << ".\n"; } else @@ -272,18 +293,20 @@ TEST_P(FindCloseTest, FindClose) /* * Test penalty function to use with findClose. */ -std::function testPenalty( +std::function testPenalty( [](Point2LL candidate) { return -vSize2(candidate - Point2LL(50, 100)); // The further from 50, 100, the lower the penalty. }); -INSTANTIATE_TEST_SUITE_P(FindCloseInstantiation, - FindCloseTest, - testing::Values(FindCloseParameters(Point2LL(110, 110), Point2LL(100, 100), 15), // Near a corner. - FindCloseParameters(Point2LL(50, 110), Point2LL(50, 100), 15), // Near a side. - FindCloseParameters(Point2LL(50, 50), Point2LL(50, 0), 60, &testPenalty) // Using a penalty function. - )); +INSTANTIATE_TEST_SUITE_P( + FindCloseInstantiation, + FindCloseTest, + testing::Values( + FindCloseParameters(Point2LL(110, 110), Point2LL(100, 100), 15), // Near a corner. + FindCloseParameters(Point2LL(50, 110), Point2LL(50, 100), 15), // Near a side. + FindCloseParameters(Point2LL(50, 50), Point2LL(50, 0), 60, &testPenalty) // Using a penalty function. + )); // NOLINTBEGIN(misc-non-private-member-variables-in-classes) class PolygonUtilsTest : public testing::Test @@ -403,18 +426,20 @@ TEST_P(GetNextParallelIntersectionTest, GetNextParallelIntersection) } } -INSTANTIATE_TEST_SUITE_P(GetNextParallelIntersectionInstantiation, - GetNextParallelIntersectionTest, - testing::Values(GetNextParallelIntersectionParameters(Point2LL(0, 40), Point2LL(20, 100), Point2LL(150, 200), true, 35), - GetNextParallelIntersectionParameters(Point2LL(37, 100), Point2LL(80, 100), Point2LL(150, 200), true, 35), - GetNextParallelIntersectionParameters(Point2LL(70, 100), Point2LL(20, 100), Point2LL(120, 200), false, 35), - GetNextParallelIntersectionParameters(Point2LL(0, 0), Point2LL(50, 100), Point2LL(150, 200), true, 35), - GetNextParallelIntersectionParameters(Point2LL(60, 0), Point2LL(10, 0), Point2LL(-90, -100), true, 35), - GetNextParallelIntersectionParameters(Point2LL(0, 40), Point2LL(10, 0), Point2LL(-90, -100), false, 35), - GetNextParallelIntersectionParameters(Point2LL(0, 75), Point2LL(50, 100), Point2LL(150, 100), true, 25), - GetNextParallelIntersectionParameters(Point2LL(25, 100), Point2LL(50, 100), Point2LL(50, 200), true, 25), - GetNextParallelIntersectionParameters(std::optional(), Point2LL(100, 100), Point2LL(200, 200), true, 80), - GetNextParallelIntersectionParameters(Point2LL(0, 45), Point2LL(5, 100), Point2LL(105, 200), true, 35))); +INSTANTIATE_TEST_SUITE_P( + GetNextParallelIntersectionInstantiation, + GetNextParallelIntersectionTest, + testing::Values( + GetNextParallelIntersectionParameters(Point2LL(0, 40), Point2LL(20, 100), Point2LL(150, 200), true, 35), + GetNextParallelIntersectionParameters(Point2LL(37, 100), Point2LL(80, 100), Point2LL(150, 200), true, 35), + GetNextParallelIntersectionParameters(Point2LL(70, 100), Point2LL(20, 100), Point2LL(120, 200), false, 35), + GetNextParallelIntersectionParameters(Point2LL(0, 0), Point2LL(50, 100), Point2LL(150, 200), true, 35), + GetNextParallelIntersectionParameters(Point2LL(60, 0), Point2LL(10, 0), Point2LL(-90, -100), true, 35), + GetNextParallelIntersectionParameters(Point2LL(0, 40), Point2LL(10, 0), Point2LL(-90, -100), false, 35), + GetNextParallelIntersectionParameters(Point2LL(0, 75), Point2LL(50, 100), Point2LL(150, 100), true, 25), + GetNextParallelIntersectionParameters(Point2LL(25, 100), Point2LL(50, 100), Point2LL(50, 200), true, 25), + GetNextParallelIntersectionParameters(std::optional(), Point2LL(100, 100), Point2LL(200, 200), true, 80), + GetNextParallelIntersectionParameters(Point2LL(0, 45), Point2LL(5, 100), Point2LL(105, 200), true, 35))); TEST_F(PolygonUtilsTest, RelativeHammingSquaresOverlap) { @@ -456,9 +481,10 @@ TEST_F(PolygonUtilsTest, RelativeHammingQuarterOverlap) */ TEST_F(PolygonUtilsTest, RelativeHammingLineSquare) { - ASSERT_EQ(PolygonUtils::relativeHammingDistance(test_squares, test_line), 1.0) << "The difference between the polygons is 100% because the area of the difference encompasses the area of the one polygon that " - "has " - "area."; + ASSERT_EQ(PolygonUtils::relativeHammingDistance(test_squares, test_line), 1.0) + << "The difference between the polygons is 100% because the area of the difference encompasses the area of the one polygon that " + "has " + "area."; } /* @@ -493,4 +519,4 @@ TEST_F(PolygonUtilsTest, DISABLED_RelativeHammingLineLineDifferentVerts) // Disa } } // namespace cura -// NOLINTEND(*-magic-numbers) \ No newline at end of file +// NOLINTEND(*-magic-numbers) diff --git a/tests/utils/SimplifyTest.cpp b/tests/utils/SimplifyTest.cpp index 1e45d8e9fb..3b80885267 100644 --- a/tests/utils/SimplifyTest.cpp +++ b/tests/utils/SimplifyTest.cpp @@ -2,9 +2,11 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "utils/Simplify.h" // The unit under test. + +#include + #include "utils/Coord_t.h" #include "utils/polygonUtils.h" // Helper functions for testing deviation. -#include // NOLINTBEGIN(*-magic-numbers) namespace cura @@ -32,7 +34,8 @@ class SimplifyTest : public testing::Test Polygon spiral; // A spiral with gradually increasing segment length. Polygon zigzag; // Sawtooth zig-zag pattern. - SimplifyTest() : simplifier(MAX_RESOLUTION, MAX_DEVIATION, MAX_AREA_DEVIATION) + SimplifyTest() + : simplifier(MAX_RESOLUTION, MAX_DEVIATION, MAX_AREA_DEVIATION) { } @@ -119,7 +122,7 @@ class SimplifyTest : public testing::Test */ TEST_F(SimplifyTest, CircleMaxResolution) { - simplifier.max_deviation = 999999; // For this test, the maximum deviation should not be an issue. + simplifier.max_deviation_ = 999999; // For this test, the maximum deviation should not be an issue. circle = simplifier.polygon(circle); for (size_t point_index = 1; point_index + 1 < circle.size(); point_index++) // Don't check the last vertex. Due to odd-numbered vertices it has to be shorter than the minimum. @@ -138,7 +141,7 @@ TEST_F(SimplifyTest, CircleMaxResolution) */ TEST_F(SimplifyTest, CircleMaxDeviation) { - simplifier.max_resolution = 999999; // For this test, the maximum resolution should not be an issue. + simplifier.max_resolution_ = 999999; // For this test, the maximum resolution should not be an issue. Polygon simplified = simplifier.polygon(circle); // Check on each vertex if it didn't deviate too much. @@ -147,7 +150,7 @@ TEST_F(SimplifyTest, CircleMaxDeviation) Point2LL moved_point = v; PolygonUtils::moveInside(simplified, moved_point); const coord_t deviation = vSize(moved_point - v); - EXPECT_LE(deviation, simplifier.max_deviation); + EXPECT_LE(deviation, simplifier.max_deviation_); } // Also check the other way around, since the longest distance may also be on a vertex of the new polygon. for (Point2LL v : simplified) @@ -155,7 +158,7 @@ TEST_F(SimplifyTest, CircleMaxDeviation) Point2LL moved_point = v; PolygonUtils::moveInside(circle, moved_point); const coord_t deviation = vSize(moved_point - v); - EXPECT_LE(deviation, simplifier.max_deviation); + EXPECT_LE(deviation, simplifier.max_deviation_); } } @@ -168,7 +171,7 @@ TEST_F(SimplifyTest, CircleMaxDeviation) */ TEST_F(SimplifyTest, Zigzag) { - simplifier.max_resolution = 9999999; + simplifier.max_resolution_ = 9999999; Polygon simplified = simplifier.polyline(zigzag); EXPECT_EQ(simplified.size(), 2) << "All zigzagged lines can be erased because they deviate less than the maximum deviation, leaving only the endpoints."; } @@ -182,12 +185,12 @@ TEST_F(SimplifyTest, Zigzag) */ TEST_F(SimplifyTest, LimitedLength) { - simplifier.max_deviation = 999999; // Maximum deviation should have no effect. + simplifier.max_deviation_ = 999999; // Maximum deviation should have no effect. // Find from where on the segments become longer than the maximum resolution. size_t limit_vertex; for (limit_vertex = 1; limit_vertex < spiral.size(); ++limit_vertex) { - if (vSize2(spiral[limit_vertex] - spiral[limit_vertex - 1]) > simplifier.max_resolution * simplifier.max_resolution) + if (vSize2(spiral[limit_vertex] - spiral[limit_vertex - 1]) > simplifier.max_resolution_ * simplifier.max_resolution_) { limit_vertex--; break; @@ -217,21 +220,21 @@ TEST_F(SimplifyTest, LimitedLength) */ TEST_F(SimplifyTest, LimitedError) { - simplifier.max_resolution = 9999999; + simplifier.max_resolution_ = 9999999; // Generate a zig-zag with gradually increasing deviation. Polygon increasing_zigzag; increasing_zigzag.add(Point2LL(0, 0)); constexpr coord_t amplitude_step = 1; // Every 2 vertices, the amplitude increases by this much. constexpr coord_t y_step = 100; - const coord_t amplitude_limit = simplifier.max_deviation * 2; // Increase amplitude up to this point. About half of the vertices should get removed. + const coord_t amplitude_limit = simplifier.max_deviation_ * 2; // Increase amplitude up to this point. About half of the vertices should get removed. for (coord_t amplitude = 0; amplitude < amplitude_limit; amplitude += amplitude_step) { increasing_zigzag.add(Point2LL(amplitude, increasing_zigzag.size() * y_step)); increasing_zigzag.add(Point2LL(0, increasing_zigzag.size() * y_step)); } - size_t limit_vertex = 2 * simplifier.max_deviation / amplitude_step + 3; // 2 vertices per zag. Deviation/step zags. Add 3 since deviation equal to max +- epsilon is allowed. + size_t limit_vertex = 2 * simplifier.max_deviation_ / amplitude_step + 3; // 2 vertices per zag. Deviation/step zags. Add 3 since deviation equal to max +- epsilon is allowed. Polygon simplified = simplifier.polyline(increasing_zigzag); @@ -267,13 +270,13 @@ TEST_F(SimplifyTest, LongEdgesNotMoved) // Verify that all small segments are removed. for (size_t i = 1; i < simplified.size(); ++i) { - EXPECT_GE(vSize(simplified[i] - simplified[i - 1]), simplifier.max_resolution) << "There may not be any segment smaller than max resolution."; + EXPECT_GE(vSize(simplified[i] - simplified[i - 1]), simplifier.max_resolution_) << "There may not be any segment smaller than max resolution."; } // Verify that all long segments are still present. for (size_t i = 0; i < polyline.size() - 1; ++i) { - if (vSize(polyline[i] - polyline[i + 1]) > simplifier.max_resolution) + if (vSize(polyline[i] - polyline[i + 1]) > simplifier.max_resolution_) { // Both endpoints of this line segment must have a distance to the simplified polygon of 0, theoretically. // Due to rounding errors we'll allow up to 1 unit. @@ -331,7 +334,7 @@ TEST_F(SimplifyTest, LongEdgesButTooMuchDeviation) */ TEST_F(SimplifyTest, Sine) { - simplifier.max_resolution = 9999999; + simplifier.max_resolution_ = 9999999; Polygon simplified = simplifier.polyline(sine); EXPECT_EQ(simplified.size(), 2) << "All zigzagged lines can be erased because they deviate less than the maximum deviation, leaving only the endpoints."; @@ -401,4 +404,4 @@ TEST_F(SimplifyTest, ToDegenerate) } } // namespace cura -// NOLINTEND(*-magic-numbers) \ No newline at end of file +// NOLINTEND(*-magic-numbers) diff --git a/tests/utils/SparseGridTest.cpp b/tests/utils/SparseGridTest.cpp index 5f60ec5491..00f013ed61 100644 --- a/tests/utils/SparseGridTest.cpp +++ b/tests/utils/SparseGridTest.cpp @@ -2,13 +2,16 @@ // CuraEngine is released under the terms of the AGPLv3 or higher. #include "utils/SparseGrid.h" -#include "utils/Coord_t.h" -#include "utils/SparsePointGridInclusive.h" + #include -#include #include #include +#include + +#include "utils/Coord_t.h" +#include "utils/SparsePointGridInclusive.h" + namespace cura { @@ -46,25 +49,47 @@ TEST_P(GetNearbyTest, GetNearby) // Are all near points reported as near? for (const Point2LL point : parameters.expected_near) { - EXPECT_NE(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_NE( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is near " << target << " (distance " << vSize(point - target) << "), but getNearby didn't find it. Grid size: " << grid_size; } // Are all far points NOT reported as near? for (const Point2LL point : parameters.expected_far) { - EXPECT_EQ(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_EQ( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is far from " << target << " (distance " << vSize(point - target) << "), but getNearby thought it was near. Grid size: " << grid_size; } } -INSTANTIATE_TEST_CASE_P(GetNearbyInstantiation, - GetNearbyTest, - testing::Values(Point2LLarbyParameters({ Point2LL(0, 100) }, stdPoint2LLrdered_set(), stdPoint2LLrdered_set(Point2LLnt(95, 100) }), - Point2LLunordered_setPoint2LLt>())Point2LLA near point. - GetNearbyParametersPoint2LLint(100, 100) }Point2LL std::Point2LLered_setPoint2LLt>Point2LLint(100, 100) })Point2LL std::Point2LLered_set()) // On top of the target. - )); +INSTANTIATE_TEST_CASE_P( + GetNearbyInstantiation, + GetNearbyTest, + testing::Values( + GetNearbyParameters({ Point2LL(0, 100) }, std::unordered_set(), std::unordered_set({ Point2LL(0, 100) })), // A far point. + GetNearbyParameters( + { Point2LL(95, 100) }, + std::unordered_set({ Point2LL(95, 100) }), + std::unordered_set()), // A near point. + GetNearbyParameters( + { Point2LL(100, 100) }, + std::unordered_set({ Point2LL(100, 100) }), + std::unordered_set()) // On top of the target. + )); TEST_F(GetNearbyTest, getNearbyLine2) { @@ -100,13 +125,29 @@ TEST_F(GetNearbyTest, getNearbyLine2) // Are all near points reported as near? for (const Point2LL point : near) { - EXPECT_NE(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_NE( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is near " << target << " (distance " << vSize(point - target) << "), but getNearby didn't find it. Grid size: " << grid_size; } // Are all far points NOT reported as near? for (const Point2LL point : far) { - EXPECT_EQ(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_EQ( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is far from " << target << " (distance " << vSize(point - target) << "), but getNearby thought it was near. Grid size: " << grid_size; } } @@ -145,13 +186,29 @@ TEST_F(GetNearbyTest, getNearbyLine) // Are all near points reported as near? for (const Point2LL point : near) { - EXPECT_NE(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_NE( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is near " << target << " (distance " << vSize(point - target) << "), but getNearby didn't find it. Grid size: " << grid_size; } // Are all far points NOT reported as near? for (const Point2LL point : far) { - EXPECT_EQ(result.end(), std::find_if(result.begin(), result.end(), [&point](const typename SparsePointGridInclusive::Elem& elem) { return elem.val == point; })) + EXPECT_EQ( + result.end(), + std::find_if( + result.begin(), + result.end(), + [&point](const typename SparsePointGridInclusive::Elem& elem) + { + return elem.val == point; + })) << "Point " << point << " is far from " << target << " (distance " << vSize(point - target) << "), but getNearby thought it was near. Grid size: " << grid_size; } } @@ -160,9 +217,12 @@ struct GetNearestParameters { std::vector registered_points; Point2LL* result; - std::function::Elem&)> filter; + std::function::Elem&)> filter; - GetNearestParameters(const std::vector registered_points, Point2LL* result, const std::function::Elem&)>& filter = SparsePointGridInclusive::no_precondition) + GetNearestParameters( + const std::vector registered_points, + Point2LL* result, + const std::function::Elem&)>& filter = SparsePointGridInclusive::no_precondition) : registered_points(registered_points) , result(result) , filter(filter) @@ -192,20 +252,26 @@ TEST_P(GetNearestTest, GetNearest) ASSERT_EQ(success, parameters.result != nullptr) << "getNearest returned " << success << " but should've returned " << (parameters.result != nullptr) << "."; if (parameters.result) { - ASSERT_EQ(result.val, *parameters.result) << "getNearest reported the nearest point to be " << result.val << " (distance " << vSize(target - result.val) << "), but it was " << *parameters.result << " (distance " - << vSize(target - *parameters.result) << ")."; + ASSERT_EQ(result.val, *parameters.result) << "getNearest reported the nearest point to be " << result.val << " (distance " << vSize(target - result.val) << "), but it was " + << *parameters.result << " (distance " << vSize(target - *parameters.result) << ")."; } } -INSTANTIATE_TEST_SUITE_P(GetNearestInstantiation, - GetNearestTest, - testing::Values(GetNearestParameters(std::vector({ Point2LL(95, 100), Point2LL(103, 100), Point2LL(200, 100) }), new Point2LL(103, 100)), // Choose the nearest out of 3 points. - GetNearestParameters(std::vector({ Point2LL(95, 100), Point2LL(98, 100), Point2LL(106, 100) }), - new Point2LL(106, 100), - [](const typename SparsePointGridInclusive::Elem& elem) -> bool { return elem.point.X > 100; }), // With a filter. - GetNearestParameters(std::vector(), nullptr), // No points, no answer. - GetNearestParameters(std::vector({ Point2LL(100, 100) }), new Point2LL(100, 100)) // Same point as target. - )); +INSTANTIATE_TEST_SUITE_P( + GetNearestInstantiation, + GetNearestTest, + testing::Values( + GetNearestParameters(std::vector({ Point2LL(95, 100), Point2LL(103, 100), Point2LL(200, 100) }), new Point2LL(103, 100)), // Choose the nearest out of 3 points. + GetNearestParameters( + std::vector({ Point2LL(95, 100), Point2LL(98, 100), Point2LL(106, 100) }), + new Point2LL(106, 100), + [](const typename SparsePointGridInclusive::Elem& elem) -> bool + { + return elem.point.X > 100; + }), // With a filter. + GetNearestParameters(std::vector(), nullptr), // No points, no answer. + GetNearestParameters(std::vector({ Point2LL(100, 100) }), new Point2LL(100, 100)) // Same point as target. + )); TEST_F(GetNearestTest, Equal) { @@ -228,9 +294,10 @@ TEST_F(GetNearestTest, Equal) const bool success = grid.getNearest(target, grid_size, result, SparsePointGridInclusive::no_precondition); ASSERT_TRUE(success); - ASSERT_TRUE(result.val == expected1 || result.val == expected2) << "getNearest reported the nearest point to be " << result.val << " (distance " << vSize(target - result.val) << "), but it should've been " << expected1 << "(distance " - << vSize(expected1 - target) << ") or " << expected2 << " (distance " << vSize(expected2 - target) - << ")."; // FIXME: simplify once fmt or we use C++20 is added as a dependency + ASSERT_TRUE(result.val == expected1 || result.val == expected2) + << "getNearest reported the nearest point to be " << result.val << " (distance " << vSize(target - result.val) << "), but it should've been " << expected1 << "(distance " + << vSize(expected1 - target) << ") or " << expected2 << " (distance " << vSize(expected2 - target) + << ")."; // FIXME: simplify once fmt or we use C++20 is added as a dependency } } // namespace cura