From 3f94b15cef2ffee007a77be5fb278520a538d242 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 26 Oct 2016 18:11:26 -0500 Subject: [PATCH] Fix bilinear grid constraints Followup to #5090 --- Marlin/Marlin_main.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b99ae27df4..22429325a7 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -8310,15 +8310,17 @@ void ok_to_send() { float ratio_x = x / bilinear_grid_spacing[X_AXIS], ratio_y = y / bilinear_grid_spacing[Y_AXIS]; - // Whole unit is the grid box index - const int gridx = constrain(floor(ratio_x), 0, ABL_GRID_POINTS_X - 2), - gridy = constrain(floor(ratio_y), 0, ABL_GRID_POINTS_Y - 2), - nextx = min(gridx + 1, ABL_GRID_POINTS_X - 2), - nexty = min(gridy + 1, ABL_GRID_POINTS_Y - 2); + // Whole units for the grid line indices. Constrained within bounds. + const int gridx = constrain(floor(ratio_x), 0, ABL_GRID_POINTS_X - 1), + gridy = constrain(floor(ratio_y), 0, ABL_GRID_POINTS_Y - 1), + nextx = min(gridx + 1, ABL_GRID_POINTS_X - 1), + nexty = min(gridy + 1, ABL_GRID_POINTS_Y - 1); // Subtract whole to get the ratio within the grid box - ratio_x = constrain(ratio_x - gridx, 0.0, 1.0); - ratio_y = constrain(ratio_y - gridy, 0.0, 1.0); + ratio_x -= gridx; ratio_y -= gridy; + + // Never less than 0.0. (Over 1.0 is fine due to previous contraints.) + NOLESS(ratio_x, 0); NOLESS(ratio_y, 0); // Z at the box corners const float z1 = bed_level_grid[gridx][gridy], // left-front