diff options
-rw-r--r-- | ArcWelder/segmented_arc.cpp | 2 | ||||
-rw-r--r-- | ArcWelder/segmented_shape.cpp | 11 | ||||
-rw-r--r-- | GcodeProcessorLib/gcode_parser.cpp | 1 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.cpp | 13 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.h | 3 |
5 files changed, 23 insertions, 7 deletions
diff --git a/ArcWelder/segmented_arc.cpp b/ArcWelder/segmented_arc.cpp index 5f8701f..de12932 100644 --- a/ArcWelder/segmented_arc.cpp +++ b/ArcWelder/segmented_arc.cpp @@ -248,7 +248,7 @@ std::string segmented_arc::get_shape_gcode_(bool has_e, double e, double f) cons // We may need to add a z coordinate double z_initial = current_arc_.start_point.z; double z_final = current_arc_.end_point.z; - if (!utilities::is_equal(z_initial, z_final, std::pow(10, -1 * xyz_precision_))) + if (!utilities::is_equal(z_initial, z_final, std::pow(10.0, -1.0 * xyz_precision_))) { // The z axis has changed within the precision of the gcode coordinates gcode += " Z"; diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp index 77448c0..76bcca1 100644 --- a/ArcWelder/segmented_shape.cpp +++ b/ArcWelder/segmented_shape.cpp @@ -25,6 +25,7 @@ #include "segmented_shape.h" #include <stdio.h> +#include "utilities.h" #include <cmath> #include <iostream> #pragma region Operators for Vector and Point @@ -245,7 +246,7 @@ bool circle::try_create_circle(const array_list<point>& points, const double max double circle::get_radians(const point& p1, const point& p2) const { - double distance_sq = pow(utilities::get_cartesian_distance(p1.x, p1.y, p2.x, p2.y), 2.0); + double distance_sq = std::pow(utilities::get_cartesian_distance(p1.x, p1.y, p2.x, p2.y), 2.0); double two_r_sq = 2.0 * radius * radius; return acos((two_r_sq - distance_sq) / two_r_sq); } @@ -288,7 +289,7 @@ bool circle::is_over_deviation(const array_list<point>& points, const double res if (z_step_per_distance == 0){ z_step_per_distance = current_z_stepper_distance; } - if (!utilities::is_equal(z_step_per_distance, current_z_stepper_distance, std::pow(10, -1.0 * xyz_precision))) + if (!utilities::is_equal(z_step_per_distance, current_z_stepper_distance, std::pow(10.0, -1.0 * xyz_precision))) { // The z step is uneven, can't create arc return true; @@ -387,7 +388,7 @@ bool arc::try_create_arc( // We may be traveling in 3 space, calculate the arc_length of the spiral if (start_point.z != end_point.z) { - arc_length = std::hypot(arc_length, end_point.z - start_point.z); + arc_length = utilities::hypot(arc_length, end_point.z - start_point.z); } } // Calculate the percent difference of the original path @@ -409,7 +410,7 @@ bool arc::try_create_arc( // We may be traveling in 3 space, calculate the arc_length of the spiral if (start_point.z != end_point.z) { - test_arc_length = std::hypot(arc_length, end_point.z - start_point.z); + test_arc_length = utilities::hypot(arc_length, end_point.z - start_point.z); } } difference = (test_arc_length - approximate_length) / approximate_length; @@ -425,7 +426,7 @@ bool arc::try_create_arc( if (allow_z_axis_changes) { // Ensure the perimeter of the arc is less than that of a full circle - double perimeter = std::hypot(c.radius * 2.0 * PI_DOUBLE, end_point.z - start_point.z); + double perimeter = utilities::hypot(c.radius * 2.0 * PI_DOUBLE, end_point.z - start_point.z); if (perimeter <= approximate_length) { return false; } diff --git a/GcodeProcessorLib/gcode_parser.cpp b/GcodeProcessorLib/gcode_parser.cpp index 2cc49f7..8d2e68a 100644 --- a/GcodeProcessorLib/gcode_parser.cpp +++ b/GcodeProcessorLib/gcode_parser.cpp @@ -479,7 +479,6 @@ bool gcode_parser::try_extract_double(char ** p_p_gcode, double * p_double, unsi } ++p; } - //r += f / pow(10.0, n); r += f / ten_pow(n); *p_precision = n; } diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp index 6ff083f..2818eee 100644 --- a/GcodeProcessorLib/utilities.cpp +++ b/GcodeProcessorLib/utilities.cpp @@ -345,3 +345,16 @@ bool utilities::get_temp_file_path_for_file(const std::string& file_path, std::s temp_file_path += ".tmp"; return true; } + +double utilities::hypot(double x, double y) +{ + if (x < 0) x = -x; + if (y < 0) y = -y; + if (x < y) { + double tmp = x; + x = y; y = tmp; + } + if (y == 0.0) return x; + y /= x; + return x * sqrt(1.0 + y * y); +} diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h index f93ac53..c7fdcfb 100644 --- a/GcodeProcessorLib/utilities.h +++ b/GcodeProcessorLib/utilities.h @@ -59,6 +59,9 @@ public: static bool get_file_path(const std::string& file_path, std::string& path); static bool get_temp_file_path_for_file(const std::string& file_path, std::string& temp_file_path); static std::string create_uuid(); + // Man I can't wait till I can drop python 2.7 support so I can stop doing everything myself. s + // td::hypot doesn't work for msvc for python 2.7.... + static double hypot(double x, double y); protected: |