From 24437de5913901bbca13e20fd2eaf1922877b194 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Sun, 3 Dec 2017 00:10:54 -0600
Subject: [PATCH] Use custom segment length for UBL Cartesian

---
 .../src/feature/bedlevel/ubl/ubl_motion.cpp   | 25 +++++++++++++------
 Marlin/src/inc/Conditionals_post.h            | 15 -----------
 2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
index 466bf463a2..d8fbe284ac 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
+++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
@@ -484,8 +484,8 @@
 
       #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
 
-        inverse_kinematics(raw); // this writes delta[ABC] from raw[XYZE]
-                                 // should move the feedrate scaling to scara inverse_kinematics
+        inverse_kinematics(raw);  // this writes delta[ABC] from raw[XYZE]
+                                  // should move the feedrate scaling to scara inverse_kinematics
 
         const float adiff = FABS(delta[A_AXIS] - scara_oldA),
                     bdiff = FABS(delta[B_AXIS] - scara_oldB);
@@ -500,9 +500,19 @@
         planner._buffer_line(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], raw[E_AXIS], fr, active_extruder);
 
       #endif
-
     }
 
+    #if IS_SCARA
+      #define DELTA_SEGMENT_MIN_LENGTH 0.25 // SCARA minimum segment size is 0.25mm
+    #elif ENABLED(DELTA)
+      #define DELTA_SEGMENT_MIN_LENGTH 0.10 // mm (still subject to DELTA_SEGMENTS_PER_SECOND)
+    #else // CARTESIAN
+      #ifdef LEVELED_SEGMENT_LENGTH
+        #define DELTA_SEGMENT_MIN_LENGTH LEVELED_SEGMENT_LENGTH
+      #else
+        #define DELTA_SEGMENT_MIN_LENGTH 1.00 // mm (similar to G2/G3 arc segmentation)
+      #endif
+    #endif
 
     /**
      * Prepare a segmented linear move for DELTA/SCARA/CARTESIAN with UBL and FADE semantics.
@@ -633,10 +643,11 @@
           if (--segments == 0)                      // if this is last segment, use rtarget for exact
             COPY(raw, rtarget);
 
-          float z_cxcy = z_cxy0 + z_cxym * cy;      // interpolated mesh z height along cx at cy
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
-            z_cxcy *= fade_scaling_factor;          // apply fade factor to interpolated mesh height
-          #endif
+          const float z_cxcy = (z_cxy0 + z_cxym * cy) // interpolated mesh z height along cx at cy
+            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+              * fade_scaling_factor                   // apply fade factor to interpolated mesh height
+            #endif
+          ;
 
           const float z = raw[Z_AXIS];
           raw[Z_AXIS] += z_cxcy;
diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h
index 569b58551a..5b169ad178 100644
--- a/Marlin/src/inc/Conditionals_post.h
+++ b/Marlin/src/inc/Conditionals_post.h
@@ -1153,21 +1153,6 @@
   #define LCD_TIMEOUT_TO_STATUS 15000
 #endif
 
-/**
- * DELTA_SEGMENT_MIN_LENGTH for UBL_DELTA
- */
-#if UBL_DELTA
-  #ifndef DELTA_SEGMENT_MIN_LENGTH
-    #if IS_SCARA
-      #define DELTA_SEGMENT_MIN_LENGTH 0.25 // SCARA minimum segment size is 0.25mm
-    #elif ENABLED(DELTA)
-      #define DELTA_SEGMENT_MIN_LENGTH 0.10 // mm (still subject to DELTA_SEGMENTS_PER_SECOND)
-    #else // CARTESIAN
-      #define DELTA_SEGMENT_MIN_LENGTH 1.00 // mm (similar to G2/G3 arc segmentation)
-    #endif
-  #endif
-#endif
-
 // Shorthand
 #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))