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-07-17 00:05:32 +0300
committerFormerLurker <hochgebe@gmail.com>2021-07-17 00:05:32 +0300
commit56ea16df55e0e37581688effac94e78ffc10f941 (patch)
treefe73a62fb484b8290550912562c1c8eca84aed9a /GcodeProcessorLib
parent7e315a6ccf1d94802b396738bff015d98042bfa9 (diff)
Fix xyz and e precision in console app. Fix unix->windows line endings resulting in lower compression. Fix g2/g3 length calculation within statistics.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r--GcodeProcessorLib/array_list.h22
-rw-r--r--GcodeProcessorLib/utilities.cpp32
-rw-r--r--GcodeProcessorLib/utilities.h3
3 files changed, 46 insertions, 11 deletions
diff --git a/GcodeProcessorLib/array_list.h b/GcodeProcessorLib/array_list.h
index 53ed43e..a69fc28 100644
--- a/GcodeProcessorLib/array_list.h
+++ b/GcodeProcessorLib/array_list.h
@@ -35,7 +35,7 @@ public:
count_ = 0;
items_ = new T[max_size_];
}
-
+
array_list(int max_size)
{
auto_grow_ = false;
@@ -44,11 +44,11 @@ public:
count_ = 0;
items_ = new T[max_size];
}
-
+
virtual ~array_list() {
delete[] items_;
}
-
+
void resize(int max_size)
{
T* new_items = new T[max_size];
@@ -71,7 +71,7 @@ public:
}
return index_position;
}
-
+
void push_front(T object)
{
if (count_ == max_size_)
@@ -93,7 +93,7 @@ public:
count_++;
items_[front_index_] = object;
}
-
+
void push_back(T object)
{
if (count_ == max_size_)
@@ -110,7 +110,7 @@ public:
items_[pos] = object;
count_++;
}
-
+
T& pop_front()
{
if (count_ == 0)
@@ -135,7 +135,7 @@ public:
{
throw std::exception();
}
- int pos = get_index_position(count_-1);
+ int pos = get_index_position(count_ - 1);
count_--;
return items_[pos];
}
@@ -151,23 +151,23 @@ public:
int opos = get_index_position(index);
return items_[opos];
}
-
+
int count() const
{
return count_;
}
-
+
int get_max_size() const
{
return max_size_;
}
-
+
void clear()
{
count_ = 0;
front_index_ = 0;
}
-
+
void copy(const array_list<T>& source)
{
if (max_size_ < source.max_size_)
diff --git a/GcodeProcessorLib/utilities.cpp b/GcodeProcessorLib/utilities.cpp
index 4db0f6a..e4b8526 100644
--- a/GcodeProcessorLib/utilities.cpp
+++ b/GcodeProcessorLib/utilities.cpp
@@ -87,6 +87,30 @@ double utilities::get_cartesian_distance(double x1, double y1, double z1, double
return std::sqrt(dist_squared);
}
+double utilities::get_arc_distance(double x1, double y1, double z1, double x2, double y2, double z2, double i, double j, double r, bool is_clockwise)
+{
+ double center_x = x1 - i;
+ double center_y = y1 - j;
+ double radius = hypot(i, j);
+ double z_dist = z2-z1;
+ double rt_x = x2 - center_x;
+ double rt_y = y2 - center_y;
+ double angular_travel_total = std::atan2(i * rt_y - j * rt_x, i * rt_x + j * rt_y);
+ if (angular_travel_total < 0) { angular_travel_total += (double)(2.0 * PI_DOUBLE); }
+ // Adjust the angular travel if the direction is clockwise
+ if (is_clockwise) { angular_travel_total -= (float)(2 * PI_DOUBLE); }
+ // Full circle fix.
+ if (x1 == x2 && y1 == y2 && angular_travel_total == 0)
+ {
+ angular_travel_total += (float)(2 * PI_DOUBLE);
+ }
+
+ // 20200417 - FormerLurker - rename millimeters_of_travel to millimeters_of_travel_arc to better describe what we are
+ // calculating here
+ return hypot(angular_travel_total * radius, std::fabs(z_dist));
+
+}
+
std::string utilities::to_string(double value)
{
std::ostringstream os;
@@ -220,6 +244,14 @@ int utilities::get_num_digits(int x)
(x < 10000000000 ? 10 : -1))))))))));
}
+int utilities::get_num_digits(double x, int precision)
+{
+ return get_num_digits(
+ (int) std::ceil(x * std::pow(10, (double)precision) - .4999999999999)
+ / std::pow(10, (double)precision)
+ );
+}
+
int utilities::get_num_digits(double x)
{
return get_num_digits((int) x);
diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h
index 3261f91..cf3a97b 100644
--- a/GcodeProcessorLib/utilities.h
+++ b/GcodeProcessorLib/utilities.h
@@ -28,6 +28,7 @@
// Had to increase the zero tolerance because prusa slicer doesn't always
// retract enough while wiping.
#define ZERO_TOLERANCE 0.000005
+#define PI_DOUBLE 3.14159265358979323846264338327950288
class utilities{
public:
@@ -41,6 +42,7 @@ public:
static double get_cartesian_distance(double x1, double y1, double x2, double y2);
static double get_cartesian_distance(double x1, double y1, double z1, double x2, double y2, double z2);
+ static double get_arc_distance(double x1, double y1, double z1, double x2, double y2, double z2, double i, double j, double r, bool is_clockwise);
/* Todo: Implement for gcode comment processor
static bool case_insensitive_compare_char(char& c1, char& c2);
static bool case_insensitive_compare(std::string& str1, std::string& str2);
@@ -57,6 +59,7 @@ public:
static std::string get_percent_change_string(int v1, int v2, int precision);
static int get_num_digits(int x);
static int get_num_digits(double x);
+ static int get_num_digits(double x, int precision);
static std::vector<std::string> splitpath(const std::string& str);
static bool get_file_path(const std::string& file_path, std::string& path);