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-11-13 19:49:44 +0300
committerFormerLurker <hochgebe@gmail.com>2021-11-13 19:49:44 +0300
commit00df4c1dd984e294108fd77359af6f8771143fc7 (patch)
tree7d5c4e31e5d9e43157ae819448c91ac1378ae3f7 /ArcWelder
parentb57d34b8e69d6d5680ba271d6040734899295d05 (diff)
Continue moving math calls to utilities
Diffstat (limited to 'ArcWelder')
-rw-r--r--ArcWelder/arc_welder.cpp4
-rw-r--r--ArcWelder/segmented_arc.cpp6
-rw-r--r--ArcWelder/segmented_shape.cpp26
3 files changed, 19 insertions, 17 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp
index b966b62..fe129b4 100644
--- a/ArcWelder/arc_welder.cpp
+++ b/ArcWelder/arc_welder.cpp
@@ -495,7 +495,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
// Calculate R
if (r == 0)
{
- r = std::sqrt(i * i + j * j);
+ r = utilities::sqrt(i * i + j * j);
}
// Now we know the radius and the chord length;
movement_length_mm = utilities::get_arc_distance(p_pre_pos->x, p_pre_pos->y, p_pre_pos->z, p_cur_pos->x, p_cur_pos->y, p_cur_pos->z, i, j, r, p_cur_pos->command.command == "G2");
@@ -535,7 +535,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
mm_extruded_per_mm_travel = extruder_current.e_relative / movement_length_mm;
if (previous_extrusion_rate_ > 0)
{
- extrusion_rate_change_percent = std::fabs(utilities::get_percent_change(previous_extrusion_rate_, mm_extruded_per_mm_travel));
+ extrusion_rate_change_percent = utilities::abs(utilities::get_percent_change(previous_extrusion_rate_, mm_extruded_per_mm_travel));
}
}
if (previous_extrusion_rate_ != 0 && utilities::greater_than(extrusion_rate_change_percent, extrusion_rate_variance_percent_))
diff --git a/ArcWelder/segmented_arc.cpp b/ArcWelder/segmented_arc.cpp
index 6f238a5..527ad3a 100644
--- a/ArcWelder/segmented_arc.cpp
+++ b/ArcWelder/segmented_arc.cpp
@@ -240,10 +240,12 @@ bool segmented_arc::try_add_point_internal_(printer_point p)
// Apply firmware compensation
// See how many arcs will be interpolated
double circumference = 2.0 * PI_DOUBLE * current_arc_.radius;
- int num_segments = (int)std::floor(circumference / min_arc_segments_);
+ // TODO: Should this be ceil?
+ int num_segments = (int)utilities::floor(circumference / min_arc_segments_);
if (num_segments < min_arc_segments_) {
//num_segments = (int)std::ceil(circumference/approximate_length) * (int)std::ceil(approximate_length / mm_per_arc_segment);
- num_segments = (int)std::floor(circumference / original_shape_length_);
+ // TODO: Should this be ceil?
+ num_segments = (int)utilities::floor(circumference / original_shape_length_);
if (num_segments < min_arc_segments_) {
abort_arc = true;
num_firmware_compensations_++;
diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp
index 447cfbe..dd422a4 100644
--- a/ArcWelder/segmented_shape.cpp
+++ b/ArcWelder/segmented_shape.cpp
@@ -83,7 +83,7 @@ point point::get_midpoint(point p1, point p2)
bool point::is_near_collinear(const point& p1, const point& p2, const point& p3, double tolerance)
{
- return fabs((p1.y - p2.y) * (p1.x - p3.x) - (p1.y - p3.y) * (p1.x - p2.x)) <= 1e-9;
+ return utilities::abs((p1.y - p2.y) * (p1.x - p3.x) - (p1.y - p3.y) * (p1.x - p2.x)) <= 1e-9;
}
double point::cartesian_distance(const point& p1, const point& p2)
@@ -124,7 +124,7 @@ bool segment::get_closest_perpendicular_point(const point& p1, const point& p2,
#pragma region Vector Functions
double vector::get_magnitude()
{
- return sqrt(x * x + y * y + z * z);
+ return utilities::sqrt(x * x + y * y + z * z);
}
double vector::cross_product_magnitude(vector v1, vector v2)
@@ -144,9 +144,9 @@ double vector::cross_product_magnitude(vector v1, vector v2)
// Users of this code must verify correctness for their application.
// dot product (3D) which allows vector operations in arguments
#define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
-#define dotxy(u,v) ((u).x * (v).x + (u).y * (v).y)
-#define norm(v) sqrt(dot(v,v)) // norm = length of vector
-#define d(u,v) norm(u-v) // distance = norm of difference
+//#define dotxy(u,v) ((u).x * (v).x + (u).y * (v).y)
+//#define norm(v) utilities::sqrt(dot(v,v)) // norm = length of vector
+//#define d(u,v) norm(u-v) // distance = norm of difference
#pragma endregion Distance Calculation Source
@@ -259,7 +259,7 @@ bool circle::try_create_circle(const array_list<printer_point>& points, const do
double circle::get_polar_radians(const point& p1) const
{
- double polar_radians = atan2(p1.y - center.y, p1.x - center.x);
+ double polar_radians = utilities::atan2(p1.y - center.y, p1.x - center.x);
if (polar_radians < 0)
polar_radians = (2.0 * PI_DOUBLE) + polar_radians;
return polar_radians;
@@ -290,7 +290,7 @@ bool circle::get_deviation_sum_squared(const array_list<printer_point>& points,
return false;
}
}
- double deviation = std::fabs(distance_from_center - radius);
+ double deviation = utilities::abs(distance_from_center - radius);
total_deviation += deviation * deviation;
if (deviation > resolution_mm)
{
@@ -305,7 +305,7 @@ bool circle::get_deviation_sum_squared(const array_list<printer_point>& points,
if (segment::get_closest_perpendicular_point(points[index], 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);
- double deviation = std::fabs(distance - radius);
+ double deviation = utilities::abs(distance - radius);
total_deviation += deviation * deviation;
if (deviation > resolution_mm)
{
@@ -346,7 +346,7 @@ bool circle::is_over_deviation(const array_list<printer_point>& points, const do
return true;
}
}
- if (std::fabs(distance_from_center - radius) > resolution_mm)
+ if (utilities::abs(distance_from_center - radius) > resolution_mm)
{
return true;
}
@@ -357,7 +357,7 @@ bool circle::is_over_deviation(const array_list<printer_point>& points, const do
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)
+ if (utilities::abs(distance - radius) > resolution_mm)
{
return true;
}
@@ -457,7 +457,7 @@ bool arc::try_create_arc(
// see if an arc moving in the opposite direction had the correct length.
// Find the rest of the angle across the circle
- double test_radians = std::fabs(angle_radians - 2 * PI_DOUBLE);
+ double test_radians = utilities::abs(angle_radians - 2 * PI_DOUBLE);
// Calculate the length of that arc
double test_arc_length = c.radius * test_radians;
if (allow_3d_arcs)
@@ -667,7 +667,7 @@ bool arc::ray_intersects_segment(const point rayOrigin, const point rayDirection
vector v3 = vector(-rayDirection.y, rayDirection.x, 0);
double dot = dot(v2, v3);
- if (std::fabs(dot) < 0.000001)
+ if (utilities::abs(dot) < 0.000001)
return false;
double t1 = vector::cross_product_magnitude(v2, v1) / dot;
@@ -727,7 +727,7 @@ void segmented_shape::set_xyz_precision(unsigned char precision)
void segmented_shape::set_xyz_tolerance_from_precision()
{
- xyz_tolerance_ = std::pow(10.0, -1.0 * static_cast<double>(xyz_precision_));
+ xyz_tolerance_ = utilities::pow(10, -1.0 * static_cast<double>(xyz_precision_));
}
void segmented_shape::reset_precision()