|
@@ -200,10 +200,10 @@ class unified_bed_leveling {
|
200
|
200
|
* the case where the printer is making a vertical line that only crosses horizontal mesh lines.
|
201
|
201
|
*/
|
202
|
202
|
inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
|
203
|
|
- if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
|
|
203
|
+ if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
|
204
|
204
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
205
|
205
|
if (DEBUGGING(LEVELING)) {
|
206
|
|
- serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
|
|
206
|
+ serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1_i") : PSTR("yi") );
|
207
|
207
|
SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0);
|
208
|
208
|
SERIAL_ECHOPAIR(",x1_i=", x1_i);
|
209
|
209
|
SERIAL_ECHOPAIR(",yi=", yi);
|
|
@@ -217,17 +217,19 @@ class unified_bed_leveling {
|
217
|
217
|
const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)),
|
218
|
218
|
z1 = z_values[x1_i][yi];
|
219
|
219
|
|
220
|
|
- return z1 + xratio * (z_values[x1_i + 1][yi] - z1);
|
|
220
|
+ 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
|
|
221
|
+ // If it is, it is clamped to the last element of the
|
|
222
|
+ // z_values[][] array and no correction is applied.
|
221
|
223
|
}
|
222
|
224
|
|
223
|
225
|
//
|
224
|
226
|
// See comments above for z_correction_for_x_on_horizontal_mesh_line
|
225
|
227
|
//
|
226
|
228
|
inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
|
227
|
|
- if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 2)) {
|
|
229
|
+ if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
|
228
|
230
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
229
|
231
|
if (DEBUGGING(LEVELING)) {
|
230
|
|
- serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
|
|
232
|
+ serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("y1_i") );
|
231
|
233
|
SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0);
|
232
|
234
|
SERIAL_ECHOPAIR(", xi=", xi);
|
233
|
235
|
SERIAL_ECHOPAIR(", y1_i=", y1_i);
|
|
@@ -241,7 +243,9 @@ class unified_bed_leveling {
|
241
|
243
|
const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (MESH_Y_DIST)),
|
242
|
244
|
z1 = z_values[xi][y1_i];
|
243
|
245
|
|
244
|
|
- return z1 + yratio * (z_values[xi][y1_i + 1] - z1);
|
|
246
|
+ 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
|
|
247
|
+ // If it is, it is clamped to the last element of the
|
|
248
|
+ // z_values[][] array and no correction is applied.
|
245
|
249
|
}
|
246
|
250
|
|
247
|
251
|
/**
|
|
@@ -252,29 +256,15 @@ class unified_bed_leveling {
|
252
|
256
|
*/
|
253
|
257
|
static float get_z_correction(const float &rx0, const float &ry0) {
|
254
|
258
|
const int8_t cx = get_cell_index_x(rx0),
|
255
|
|
- cy = get_cell_index_y(ry0);
|
256
|
|
-
|
257
|
|
- if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 2)) {
|
258
|
|
-
|
259
|
|
- SERIAL_ECHOPAIR("? in get_z_correction(rx0=", rx0);
|
260
|
|
- SERIAL_ECHOPAIR(", ry0=", ry0);
|
261
|
|
- SERIAL_CHAR(')');
|
262
|
|
- SERIAL_EOL();
|
263
|
|
-
|
264
|
|
- #if ENABLED(ULTRA_LCD)
|
265
|
|
- strcpy(lcd_status_message, "get_z_correction() indexes out of range.");
|
266
|
|
- lcd_quick_feedback();
|
267
|
|
- #endif
|
268
|
|
- return NAN;
|
269
|
|
- }
|
|
259
|
+ cy = get_cell_index_y(ry0); // return values are clamped
|
270
|
260
|
|
271
|
261
|
const float z1 = calc_z0(rx0,
|
272
|
262
|
mesh_index_to_xpos(cx), z_values[cx][cy],
|
273
|
|
- mesh_index_to_xpos(cx + 1), z_values[cx + 1][cy]);
|
|
263
|
+ mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][cy]);
|
274
|
264
|
|
275
|
265
|
const float z2 = calc_z0(rx0,
|
276
|
|
- mesh_index_to_xpos(cx), z_values[cx][cy + 1],
|
277
|
|
- mesh_index_to_xpos(cx + 1), z_values[cx + 1][cy + 1]);
|
|
266
|
+ mesh_index_to_xpos(cx), z_values[cx][min(cy, GRID_MAX_POINTS_Y - 2) + 1],
|
|
267
|
+ mesh_index_to_xpos(cx + 1), z_values[min(cx, GRID_MAX_POINTS_X - 2) + 1][min(cy, GRID_MAX_POINTS_Y - 2) + 1]);
|
278
|
268
|
|
279
|
269
|
float z0 = calc_z0(ry0,
|
280
|
270
|
mesh_index_to_ypos(cy), z1,
|