From 406a83ff2db9b06b5b6d09984b981b3ddfb18cd1 Mon Sep 17 00:00:00 2001
From: Hans Raaf <hara@oderwat.de>
Date: Fri, 21 Apr 2017 20:04:23 +0200
Subject: [PATCH] Fix for Meshpositions if printer has negative endstop
 positions

---
 Marlin/Configuration_adv.h | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index 30e40fbffb..af6b815dd3 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -657,14 +657,30 @@
 // Below are the macros that are used to define the borders for the mesh area,
 // made available here for specialized needs, ie dual extruder setup.
 #if ENABLED(MESH_BED_LEVELING)
-  #define MESH_MIN_X (X_MIN_POS + MESH_INSET)
+  #if X_MIN_POS < 0
+    #define MESH_MIN_X (MESH_INSET)
+  #else
+    #define MESH_MIN_X (X_MIN_POS + (MESH_INSET))
+  #endif
   #define MESH_MAX_X (X_MAX_POS - (MESH_INSET))
-  #define MESH_MIN_Y (Y_MIN_POS + MESH_INSET)
+  #if Y_MIN_POS < 0
+    #define MESH_MIN_Y (MESH_INSET)
+  #else
+    #define MESH_MIN_Y (Y_MIN_POS + (MESH_INSET))
+  #endif
   #define MESH_MAX_Y (Y_MAX_POS - (MESH_INSET))
 #elif ENABLED(AUTO_BED_LEVELING_UBL)
-  #define UBL_MESH_MIN_X (X_MIN_POS + UBL_MESH_INSET)
+  #if X_MIN_POS < 0
+    #define UBL_MESH_MIN_X (UBL_MESH_INSET)
+  #else
+    #define UBL_MESH_MIN_X (X_MIN_POS + (UBL_MESH_INSET))
+  #endif
   #define UBL_MESH_MAX_X (X_MAX_POS - (UBL_MESH_INSET))
-  #define UBL_MESH_MIN_Y (Y_MIN_POS + UBL_MESH_INSET)
+  #if Y_MIN_POS < 0
+    #define UBL_MESH_MIN_Y (UBL_MESH_INSET)
+  #else
+    #define UBL_MESH_MIN_Y (Y_MIN_POS + (UBL_MESH_INSET))
+  #endif
   #define UBL_MESH_MAX_Y (Y_MAX_POS - (UBL_MESH_INSET))
 #endif