Apply const args, clean up find_closest_circle_to_print

This commit is contained in:
Scott Lahteine 2017-04-01 23:15:41 -05:00
parent e19fbd27ce
commit 34e2420b9b

View File

@ -156,7 +156,7 @@
// won't leave us in a bad state.
float valid_trig_angle(float);
mesh_index_pair find_closest_circle_to_print(float, float);
mesh_index_pair find_closest_circle_to_print(const float&, const float&);
static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
retraction_multiplier = RETRACTION_MULTIPLIER,
@ -391,8 +391,8 @@
return d;
}
mesh_index_pair find_closest_circle_to_print( float X, float Y) {
float f, mx, my, dx, dy, closest = 99999.99;
mesh_index_pair find_closest_circle_to_print(const float &X, const float &Y) {
float closest = 99999.99;
mesh_index_pair return_val;
return_val.x_index = return_val.y_index = -1;
@ -400,28 +400,27 @@
for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
if (!is_bit_set(circle_flags, i, j)) {
mx = ubl.mesh_index_to_xpos[i]; // We found a circle that needs to be printed
my = ubl.mesh_index_to_ypos[j];
const float mx = ubl.mesh_index_to_xpos[i], // We found a circle that needs to be printed
my = ubl.mesh_index_to_ypos[j];
dx = X - mx; // Get the distance to this intersection
dy = Y - my;
f = HYPOT(dx, dy);
// Get the distance to this intersection
float f = HYPOT(X - mx, Y - my);
dx = x_pos - mx; // It is possible that we are being called with the values
dy = y_pos - my; // to let us find the closest circle to the start position.
f += HYPOT(dx, dy) / 15.0; // But if this is not the case,
// we are going to add in a small
// weighting to the distance calculation to help it choose
// a better place to continue.
// It is possible that we are being called with the values
// to let us find the closest circle to the start position.
// But if this is not the case, add a small weighting to the
// distance calculation to help it choose a better place to continue.
f += HYPOT(x_pos - mx, y_pos - my) / 15.0;
// Add in the specified amount of Random Noise to our search
if (random_deviation > 1.0)
f += random(0.0, random_deviation); // Add in the specified amount of Random Noise to our search
f += random(0.0, random_deviation);
if (f < closest) {
closest = f; // We found a closer location that is still
return_val.x_index = i; // un-printed --- save the data for it
return_val.y_index = j;
return_val.distance= closest;
return_val.distance = closest;
}
}
}