Skip to content

Commit

Permalink
Fixed unit tests build
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Nov 22, 2023
1 parent 4749362 commit fda3e1b
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 347 deletions.
12 changes: 6 additions & 6 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path, Path> no_order_requirements_;

Expand All @@ -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,
Expand Down Expand Up @@ -268,23 +268,23 @@ 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.
*
* 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.
*
* 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.
Expand Down
35 changes: 17 additions & 18 deletions include/utils/Simplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
49 changes: 29 additions & 20 deletions tests/ExtruderPlanTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <numeric> //For calculating averages.

#include <gtest/gtest.h>
#include <numeric> //For calculating averages.

#include "LayerPlan.h" //Code under test.
#include "pathPlanning/SpeedDerivatives.h"

// NOLINTBEGIN(*-magic-numbers)
namespace cura
Expand Down Expand Up @@ -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<SliceMeshStorage> mesh = nullptr;
constexpr Ratio flow_1 = 1.0_r;
Expand Down Expand Up @@ -363,22 +372,22 @@ class ExtruderPlanTest : public testing::Test
*/
TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationZeroIsUncompensated)
{
extruder_plan.paths = GetParam();
extruder_plan.paths_ = GetParam();
std::vector<Ratio> original_widths;
std::vector<Ratio> 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);
}

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.";
}
}

Expand All @@ -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))
{
Expand All @@ -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<double> original_flows;
for (GCodePath& path : extruder_plan.paths)
for (GCodePath& path : extruder_plan.paths_)
{
if (! shouldCountPath(path))
{
Expand All @@ -441,7 +450,7 @@ TEST_P(ExtruderPlanPathsParameterizedTest, BackPressureCompensationHalf)

// Calculate the new flow rates.
std::vector<double> new_flows;
for (GCodePath& path : extruder_plan.paths)
for (GCodePath& path : extruder_plan.paths_)
{
if (! shouldCountPath(path))
{
Expand Down Expand Up @@ -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)
Loading

0 comments on commit fda3e1b

Please sign in to comment.