From b35d6aa16d9dae8350a36ac0256bf68a1ac51cef Mon Sep 17 00:00:00 2001 From: FormerLurker Date: Mon, 18 Jan 2021 11:14:41 -0600 Subject: Minor performance enhancements --- ArcWelder/arc_welder.cpp | 4 ++-- ArcWelder/segmented_shape.cpp | 51 ++++++++++++++++++++++++------------------- ArcWelder/unwritten_command.h | 20 ++++++++--------- 3 files changed, 40 insertions(+), 35 deletions(-) (limited to 'ArcWelder') 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& 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; } }; -- cgit v1.2.3