Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFormerLurker <hochgebe@gmail.com>2021-01-18 20:14:41 +0300
committerFormerLurker <hochgebe@gmail.com>2021-01-18 20:14:41 +0300
commitb35d6aa16d9dae8350a36ac0256bf68a1ac51cef (patch)
treef46bdf33c00d59c8c1de76f76a6ccab005fdba9b
parent4d7375393fa603d3a2b14425a9c269ca521823ee (diff)
Minor performance enhancements
-rw-r--r--ArcWelder/arc_welder.cpp4
-rw-r--r--ArcWelder/segmented_shape.cpp51
-rw-r--r--ArcWelder/unwritten_command.h20
3 files changed, 40 insertions, 35 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp
index 74f98ce..733c49e 100644
--- a/ArcWelder/arc_welder.cpp
+++ b/ArcWelder/arc_welder.cpp
@@ -716,7 +716,7 @@ std::string arc_welder::get_comment_for_arc()
std::string comment;
for (; comment_index < unwritten_commands_.count(); comment_index++)
{
- std::string old_comment = unwritten_commands_[comment_index].command.comment;
+ std::string old_comment = unwritten_commands_[comment_index].comment;
if (old_comment != comment && old_comment.length() > 0)
{
if (comment.length() > 0)
@@ -756,7 +756,7 @@ int arc_welder::write_unwritten_gcodes_to_file()
{
segment_statistics_.update(p.extrusion_length, false);
}
- lines_to_write.append(p.command.to_string()).append("\n");
+ lines_to_write.append(p.to_string()).append("\n");
}
output_file_ << lines_to_write;
diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp
index 0ec050b..1964526 100644
--- a/ArcWelder/segmented_shape.cpp
+++ b/ArcWelder/segmented_shape.cpp
@@ -303,36 +303,41 @@ bool circle::is_over_deviation(const array_list<printer_point>& points, const do
{
// We need to ensure that the Z steps are constand per linear travel unit
double z_step_per_distance = 0;
+ // shared point to test
+ point point_to_test;
+ point current_point;
+ int max_index = points.count() - 1;
// Skip the first and last points since they will fit perfectly.
- for (int index = 1; index < points.count() - 1; index++)
+ for (int index = 0; index < max_index; index++)
{
- // Make sure the length from the center of our circle to the test point is
- // at or below our max distance.
- double distance_from_center = utilities::get_cartesian_distance(points[index].x, points[index].y, center.x, center.y);
- if (allow_3d_arcs) {
- double z1 = points[index - 1].z;
- double z2 = points[index].z;
-
- double current_z_stepper_distance = (z2 - z1) / distance_from_center;
- if (index == 1) {
- z_step_per_distance = current_z_stepper_distance;
+ current_point = points[index];
+ if (index != 0)
+ {
+ // Make sure the length from the center of our circle to the test point is
+ // at or below our max distance.
+ double distance_from_center = utilities::get_cartesian_distance(current_point.x, current_point.y, center.x, center.y);
+ if (allow_3d_arcs) {
+ double z1 = points[index - 1].z;
+ double z2 = current_point.z;
+
+ double current_z_stepper_distance = (z2 - z1) / distance_from_center;
+ if (index == 1) {
+ z_step_per_distance = current_z_stepper_distance;
+ }
+ else if (!utilities::is_equal(z_step_per_distance, current_z_stepper_distance, xyz_tolerance))
+ {
+ // The z step is uneven, can't create arc
+ return true;
+ }
}
- else if (!utilities::is_equal(z_step_per_distance, current_z_stepper_distance, xyz_tolerance))
+ if (std::fabs(distance_from_center - radius) > resolution_mm)
{
- // The z step is uneven, can't create arc
return true;
}
}
- if (std::fabs(distance_from_center - radius) > resolution_mm)
- {
- return true;
- }
- }
- // Check the point perpendicular from the segment to the circle's center, if any such point exists
- for (int index = 0; index < points.count() - 1; index++)
- {
- point point_to_test;
- if (segment::get_closest_perpendicular_point(points[index], points[index + 1], center, point_to_test))
+
+ // Check the point perpendicular from the segment to the circle's center, if any such point exists
+ if (segment::get_closest_perpendicular_point(current_point, points[index + 1], center, point_to_test))
{
double distance = utilities::get_cartesian_distance(point_to_test.x, point_to_test.y, center.x, center.y);
if (std::fabs(distance - radius) > resolution_mm)
diff --git a/ArcWelder/unwritten_command.h b/ArcWelder/unwritten_command.h
index 5c6f151..0bfea2d 100644
--- a/ArcWelder/unwritten_command.h
+++ b/ArcWelder/unwritten_command.h
@@ -35,7 +35,8 @@ struct unwritten_command
}
unwritten_command(parsed_command &cmd, bool is_relative, double command_length) {
is_extruder_relative = is_relative;
- command = cmd;
+ gcode = cmd.gcode;
+ comment = cmd.comment;
extrusion_length = command_length;
}
unwritten_command(position* p, double command_length) {
@@ -43,25 +44,24 @@ struct unwritten_command
e_relative = p->get_current_extruder().e_relative;
offset_e = p->get_current_extruder().get_offset_e();
is_extruder_relative = p->is_extruder_relative;
- command = p->command;
+ gcode = p->command.gcode;
+ comment = p->command.comment;
extrusion_length = command_length;
}
bool is_extruder_relative;
double e_relative;
double offset_e;
double extrusion_length;
- parsed_command command;
+ std::string gcode;
+ std::string comment;
- std::string to_string(bool rewrite, std::string additional_comment)
+ std::string to_string()
{
- command.comment.append(additional_comment);
-
- if (rewrite)
+ if (comment.size() > 0)
{
- return command.rewrite_gcode_string();
+ return gcode + ";" + comment;
}
-
- return command.to_string();
+ return gcode;
}
};