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