diff options
author | FormerLurker <hochgebe@gmail.com> | 2020-11-21 03:28:10 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2020-11-21 03:28:10 +0300 |
commit | 3eda30c23a6a8f1679989e1862e6c9d815cdbd7e (patch) | |
tree | 788203409737a52ba39643cc9c3c69499a02a8bd /GcodeProcessorLib | |
parent | 66cc88f965f36fca1c07a4dedafad40f19b2825c (diff) |
Switch to std namespace for math where possible, implement custom hypot for VS for python 2.7.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r-- | GcodeProcessorLib/gcode_parser.cpp | 1 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.cpp | 13 | ||||
-rw-r--r-- | GcodeProcessorLib/utilities.h | 3 |
3 files changed, 16 insertions, 1 deletions
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: |