DDA: reduce code duplication and simplify.
There are three locations in the code that repeat a pattern of "If z=0 then use 2d-approx(dx,dy), else if x==0 && y==0 then use dz, else use 3d-approx". Teach approx_distance_3 to detect these conditions for us and apply the same logic. Replace the three call locations with a simple call to approx_distance_3. Binary size for the LOOKAHEAD case drops by almost 400 bytes: old: FLASH : 21242 bytes 149% 70% 34% 17% new: FLASH : 20844 bytes 146% 68% 33% 17% The size for non-LOOKAHEAD drops by 40 bytes: old: FLASH : 16592 bytes 116% 55% 27% 13% new: FLASH : 16552 bytes 116% 54% 27% 13% We can actually do a little better if we consider the zero-ness of all three axes, but this does make the code a little bit bigger. Another change will consider that option. This change simply tries to mimic the existing functionality.
This commit is contained in:
parent
ed9f56a9d8
commit
88b6101e9a
|
|
@ -183,29 +183,15 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) {
|
|||
|
||||
// Find out movement distances.
|
||||
// TODO: remember these from dda_start();
|
||||
if (prev->delta_um.Z == 0)
|
||||
prev_distance = approx_distance(
|
||||
prev->x_direction ? prev->delta_um.X : - prev->delta_um.X,
|
||||
prev->y_direction ? prev->delta_um.Y : - prev->delta_um.Y);
|
||||
else if (prev->delta_um.X == 0 && prev->delta_um.Y == 0)
|
||||
prev_distance = prev->z_direction ? prev->delta_um.Z : - prev->delta_um.Z;
|
||||
else
|
||||
prev_distance = approx_distance_3(
|
||||
prev->x_direction ? prev->delta_um.X : - prev->delta_um.X,
|
||||
prev->y_direction ? prev->delta_um.Y : - prev->delta_um.Y,
|
||||
prev->z_direction ? prev->delta_um.Z : - prev->delta_um.Z);
|
||||
prev_distance = approx_distance_3(
|
||||
prev->x_direction ? prev->delta_um.X : - prev->delta_um.X,
|
||||
prev->y_direction ? prev->delta_um.Y : - prev->delta_um.Y,
|
||||
prev->z_direction ? prev->delta_um.Z : - prev->delta_um.Z);
|
||||
|
||||
if (current->delta_um.Z == 0)
|
||||
curr_distance = approx_distance(
|
||||
current->x_direction ? current->delta_um.X : - current->delta_um.X,
|
||||
current->y_direction ? current->delta_um.Y : - current->delta_um.Y);
|
||||
else if (current->delta_um.X == 0 && current->delta_um.Y == 0)
|
||||
curr_distance = current->z_direction ? current->delta_um.Z : - current->delta_um.Z;
|
||||
else
|
||||
curr_distance = approx_distance_3(
|
||||
current->x_direction ? current->delta_um.X : - current->delta_um.X,
|
||||
current->y_direction ? current->delta_um.Y : - current->delta_um.Y,
|
||||
current->z_direction ? current->delta_um.Z : - current->delta_um.Z);
|
||||
curr_distance = approx_distance_3(
|
||||
current->x_direction ? current->delta_um.X : - current->delta_um.X,
|
||||
current->y_direction ? current->delta_um.Y : - current->delta_um.Y,
|
||||
current->z_direction ? current->delta_um.Z : - current->delta_um.Z);
|
||||
|
||||
if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
|
||||
sersendf_P(PSTR("Distance: %lu, then %lu\n"), prev_distance, curr_distance);
|
||||
|
|
|
|||
Loading…
Reference in New Issue