Browse Source

Followup to #8713

Fix indentation, use min for constraint, remove obsolete error check
Scott Lahteine 7 years ago
parent
commit
7251850028
1 changed files with 30 additions and 44 deletions
  1. 30
    44
      Marlin/ubl.h

+ 30
- 44
Marlin/ubl.h View File

@@ -205,25 +205,25 @@
205 205
        */
206 206
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
207 207
         if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
208
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
209
-          if (DEBUGGING(LEVELING)) {
210
-          serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
211
-          SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0);
212
-          SERIAL_ECHOPAIR(",x1_i=", x1_i);
213
-          SERIAL_ECHOPAIR(",yi=", yi);
214
-          SERIAL_CHAR(')');
215
-          SERIAL_EOL();
216
-          }
217
-        #endif
208
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
209
+            if (DEBUGGING(LEVELING)) {
210
+              serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1_i") : PSTR("yi") );
211
+              SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0);
212
+              SERIAL_ECHOPAIR(",x1_i=", x1_i);
213
+              SERIAL_ECHOPAIR(",yi=", yi);
214
+              SERIAL_CHAR(')');
215
+              SERIAL_EOL();
216
+            }
217
+          #endif
218 218
           return NAN;
219 219
         }
220 220
 
221 221
         const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)),
222 222
                     z1 = z_values[x1_i][yi];
223 223
 
224
-        return z1 + xratio * (z_values[x1_i < GRID_MAX_POINTS_X - 1 ? x1_i + 1 : x1_i][yi] - z1);  // Don't allow x1_i+1 to be past the end of the array
225
-                                                                                                   // If it is, it is clamped to the last element of the 
226
-                                                                                                   // z_values[][] array and no correction is applied.
224
+        return z1 + xratio * (z_values[min(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array
225
+                                                                                        // If it is, it is clamped to the last element of the 
226
+                                                                                        // z_values[][] array and no correction is applied.
227 227
       }
228 228
 
229 229
       //
@@ -231,25 +231,25 @@
231 231
       //
232 232
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
233 233
         if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
234
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
235
-          if (DEBUGGING(LEVELING)) {
236
-          serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
237
-          SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0);
238
-          SERIAL_ECHOPAIR(", xi=", xi);
239
-          SERIAL_ECHOPAIR(", y1_i=", y1_i);
240
-          SERIAL_CHAR(')');
241
-          SERIAL_EOL();
242
-          }
243
-        #endif
234
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
235
+            if (DEBUGGING(LEVELING)) {
236
+              serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("y1_i") );
237
+              SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0);
238
+              SERIAL_ECHOPAIR(", xi=", xi);
239
+              SERIAL_ECHOPAIR(", y1_i=", y1_i);
240
+              SERIAL_CHAR(')');
241
+              SERIAL_EOL();
242
+            }
243
+          #endif
244 244
           return NAN;
245 245
         }
246 246
 
247 247
         const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (MESH_Y_DIST)),
248 248
                     z1 = z_values[xi][y1_i];
249 249
 
250
-        return z1 + yratio * (z_values[xi][y1_i < GRID_MAX_POINTS_Y - 1 ? y1_i + 1 : y1_i] - z1);  // Don't allow y1_i+1 to be past the end of the array
251
-                                                                                                   // If it is, it is clamped to the last element of the 
252
-                                                                                                   // z_values[][] array and no correction is applied.
250
+        return z1 + yratio * (z_values[xi][min(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array
251
+                                                                                        // If it is, it is clamped to the last element of the 
252
+                                                                                        // z_values[][] array and no correction is applied.
253 253
       }
254 254
 
255 255
       /**
@@ -260,29 +260,15 @@
260 260
        */
261 261
       static float get_z_correction(const float &rx0, const float &ry0) {
262 262
         const int8_t cx = get_cell_index_x(rx0),
263
-                     cy = get_cell_index_y(ry0);
264
-
265
-        if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 1)) {
266
-
267
-          SERIAL_ECHOPAIR("? in get_z_correction(rx0=", rx0);
268
-          SERIAL_ECHOPAIR(", ry0=", ry0);
269
-          SERIAL_CHAR(')');
270
-          SERIAL_EOL();
271
-
272
-          #if ENABLED(ULTRA_LCD)
273
-            strcpy(lcd_status_message, "get_z_correction() indexes out of range.");
274
-            lcd_quick_feedback();
275
-          #endif
276
-          return NAN;
277
-        }
263
+                     cy = get_cell_index_y(ry0); // return values are clamped
278 264
 
279 265
         const float z1 = calc_z0(rx0,
280 266
                                  mesh_index_to_xpos(cx), z_values[cx][cy],
281
-                                 mesh_index_to_xpos(cx + 1), z_values[cx < GRID_MAX_POINTS_X - 1 ? cx + 1 : cx][cy]);
267
+                                 mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][cy]);
282 268
 
283 269
         const float z2 = calc_z0(rx0,
284
-                                 mesh_index_to_xpos(cx), z_values[cx][cy < GRID_MAX_POINTS_Y - 1 ? cy + 1 : cy],
285
-                                 mesh_index_to_xpos(cx + 1), z_values[cx < GRID_MAX_POINTS_X - 1 ? cx + 1 : cx][cy<GRID_MAX_POINTS_Y - 1 ? cy + 1 : cy]);
270
+                                 mesh_index_to_xpos(cx), z_values[cx][min(cy, GRID_MAX_POINTS_X - 2) + 1],
271
+                                 mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][min(cy, GRID_MAX_POINTS_X - 2) + 1]);
286 272
 
287 273
         float z0 = calc_z0(ry0,
288 274
                            mesh_index_to_ypos(cy), z1,

Loading…
Cancel
Save