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-01-17 23:54:03 +0300
committerFormerLurker <hochgebe@gmail.com>2021-01-17 23:54:03 +0300
commit1b1dd123064761d07c2182edf75ffab325f217a2 (patch)
tree6bfc7b3835769f259f54f10774c1451813f51916
parentd4852e3e537ab891309f4a6c6d25cae4954c9225 (diff)
Debug are_points_within_slice.
-rw-r--r--ArcWelder/segmented_shape.cpp66
-rw-r--r--ArcWelderTest/ArcWelderTest.cpp2
-rw-r--r--ArcWelderTest/ArcWelderTest.h6
3 files changed, 54 insertions, 20 deletions
diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp
index 6fc83df..dc07470 100644
--- a/ArcWelder/segmented_shape.cpp
+++ b/ArcWelder/segmented_shape.cpp
@@ -596,18 +596,31 @@ bool arc::try_create_arc(
bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_point>& points)
{
-
+
+
// Loop through the points and see if they fit inside of the angles
double previous_polar = test_arc.polar_start_theta;
+ bool will_cross_zero = false;
bool crossed_zero = false;
+ const int point_count = points.count();
point start_norm((test_arc.start_point.x - test_arc.center.x) / test_arc.radius, (test_arc.start_point.y - test_arc.center.y) / test_arc.radius, 0.0);
point end_norm((test_arc.end_point.x - test_arc.center.x) / test_arc.radius, (test_arc.end_point.y - test_arc.center.y) / test_arc.radius, 0.0);
-
- for (int index = 1; index < points.count(); index++)
+
+ if (test_arc.direction == DirectionEnum::COUNTERCLOCKWISE)
+ {
+ will_cross_zero = test_arc.polar_start_theta > test_arc.polar_end_theta;
+ }
+ else
+ {
+ will_cross_zero = test_arc.polar_start_theta < test_arc.polar_end_theta;
+ }
+
+ // Need to see if point 1 to point 2 cross zero
+ for (int index = 1; index < point_count; index++)
{
double polar_test;
- if (index < points.count() - 1)
+ if (index < point_count - 1)
{
polar_test = test_arc.get_polar_radians(points[index]);
}
@@ -620,14 +633,16 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
if (test_arc.direction == DirectionEnum::COUNTERCLOCKWISE)
{
// Only check to see if we are within the arc if this isn't the endpoint
- if (index < points.count() - 1)
+ if (index < point_count - 1)
{
- // First test to see if this point lies within the arc
- if (test_arc.polar_start_theta < test_arc.polar_end_theta && !(test_arc.polar_start_theta < polar_test && polar_test < test_arc.polar_end_theta))
+ if (will_cross_zero)
{
- return false;
+ if (!(polar_test > test_arc.polar_start_theta || polar_test < test_arc.polar_end_theta))
+ {
+ return false;
+ }
}
- else if (test_arc.polar_start_theta > test_arc.polar_end_theta && !(polar_test > test_arc.polar_start_theta || polar_test < test_arc.polar_end_theta))
+ else if (!(test_arc.polar_start_theta < polar_test && polar_test < test_arc.polar_end_theta))
{
return false;
}
@@ -635,6 +650,11 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
// Now make sure the angles are increasing
if (previous_polar > polar_test)
{
+ if (!will_cross_zero)
+ {
+ return false;
+ }
+
// Allow the angle to cross zero once
if (crossed_zero)
{
@@ -643,23 +663,29 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
crossed_zero = true;
}
}
- else
+ else
{
- if (index < points.count() - 1)
+ if (index < point_count - 1)
{
- if (test_arc.polar_start_theta > test_arc.polar_end_theta && !(test_arc.polar_start_theta > polar_test && polar_test > test_arc.polar_end_theta))
+ if (will_cross_zero)
{
- return false;
+ if (!(polar_test < test_arc.polar_start_theta || polar_test > test_arc.polar_end_theta))
+ {
+ return false;
+ }
}
- else if (test_arc.polar_start_theta < test_arc.polar_end_theta && !(polar_test < test_arc.polar_start_theta || polar_test > test_arc.polar_end_theta))
+ else if (!(test_arc.polar_start_theta > polar_test && polar_test > test_arc.polar_end_theta))
{
return false;
}
}
-
// Now make sure the angles are decreasing
if (previous_polar < polar_test)
{
+ if (!will_cross_zero)
+ {
+ return false;
+ }
// Allow the angle to cross zero once
if (crossed_zero)
{
@@ -670,10 +696,16 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
}
// Now see if the segment intersects either of the vector from the center of the circle to the endpoints of the arc
- if ((index != 1 && ray_intersects_segment(test_arc.center, start_norm, points[index-1], points[index])) || (index != points.count()-1 && ray_intersects_segment(test_arc.center, end_norm, points[index-1], points[index])))
+ if ((index != 1 && ray_intersects_segment(test_arc.center, start_norm, points[index - 1], points[index])) || (index != point_count - 1 && ray_intersects_segment(test_arc.center, end_norm, points[index - 1], points[index])))
return false;
previous_polar = polar_test;
}
+ // Ensure that all arcs that cross zero do, and that all arcs that should not did not.
+ if (will_cross_zero != crossed_zero)
+ {
+ return false;
+ }
+
return true;
}
@@ -689,7 +721,7 @@ bool arc::ray_intersects_segment(const point rayOrigin, const point rayDirection
return false;
double t1 = vector::cross_product_magnitude(v2, v1) / dot;
- double t2 = dot(v1,v3) / dot;
+ double t2 = dot(v1, v3) / dot;
if (t1 >= 0.0 && (t2 >= 0.0 && t2 <= 1.0))
return true;
diff --git a/ArcWelderTest/ArcWelderTest.cpp b/ArcWelderTest/ArcWelderTest.cpp
index dee0fed..c5426ab 100644
--- a/ArcWelderTest/ArcWelderTest.cpp
+++ b/ArcWelderTest/ArcWelderTest.cpp
@@ -292,7 +292,7 @@ static void TestAntiStutter(std::string filePath)
//arc_welder arc_welder_obj(BENCHY_0_5_MM_NO_WIPE, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode", p_logger, max_resolution, false, 50, static_cast<progress_callback>(on_progress));
//arc_welder arc_welder_obj(SIX_SPEED_TEST, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode", p_logger, max_resolution, false, 50, on_progress);
arc_welder arc_welder_obj(
- BARBARIAN,
+ WIPER_TEST,
"C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode",
p_logger,
max_resolution,
diff --git a/ArcWelderTest/ArcWelderTest.h b/ArcWelderTest/ArcWelderTest.h
index 47f704f..b29b2a0 100644
--- a/ArcWelderTest/ArcWelderTest.h
+++ b/ArcWelderTest/ArcWelderTest.h
@@ -96,10 +96,12 @@ static std::string ISSUE_99 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutte
static std::string CONE_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\ConeTest.gcode";
static std::string CONE_TEST_VASE = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\ConeTestVase.gcode";
-static std::string BAD_ARC_DIRECTIONS = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BadArcDirections.gcode";
static std::string UNICODE_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BenchyMinRadiusTest_with_unicode.gcode";
-
+static std::string BAD_ARC_DIRECTIONS = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BadArcDirections.gcode";
+static std::string BAD_ARC_DIRECTIONS_2 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BadArcDirections2.gcode";
+static std::string WIPER_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\wiper_test.gcode";
+static std::string SLOW_COUPLER = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\Rob_Coupler.gcode";