diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index a94d90f91b..6850250b6a 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -36,6 +36,9 @@ #include "../module/scara.h" #endif +// Error margin to work around float imprecision +constexpr float slop = 0.0001; + extern bool relative_mode; extern float current_position[XYZE], // High-level current tool position @@ -265,22 +268,16 @@ void homeaxis(const AxisEnum axis); #else // CARTESIAN - // Return true if the given position is within the machine bounds. + // Return true if the given position is within the machine bounds. inline bool position_is_reachable(const float &rx, const float &ry) { + if (!WITHIN(ry, Y_MIN_POS - slop, Y_MAX_POS + slop)) return false; #if ENABLED(DUAL_X_CARRIAGE) - if (active_extruder == 0) { - // Add 0.001 margin to deal with float imprecision - return WITHIN(rx, X1_MIN_POS - 0.001f, X1_MAX_POS + 0.001f) - && WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f); - } else { - // Add 0.001 margin to deal with float imprecision - return WITHIN(rx, X2_MIN_POS - 0.001f, X2_MAX_POS + 0.001f) - && WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f); - } + if (active_extruder) + return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop); + else + return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop); #else - // Add 0.001 margin to deal with float imprecision - return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f) - && WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f); + return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop); #endif } @@ -294,8 +291,8 @@ void homeaxis(const AxisEnum axis); */ inline bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER)) - && WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f) - && WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f); + && WITHIN(rx, MIN_PROBE_X - slop, MAX_PROBE_X + slop) + && WITHIN(ry, MIN_PROBE_Y - slop, MAX_PROBE_Y + slop); } #endif