summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-06 03:04:20 -0500
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-20 10:48:51 -0500
commit34ee35d482c0678d6a5fd505f94a4d8dc26e8d76 (patch)
tree8f5b4cc1124b4621148eccaf5a59a4c32e35427b
parent0b6ece8b8b14d678ab2563c6bd79ac02527d0c32 (diff)
Avoid duplication of code
Instead jump to the middle of the while loop to reuse the error correction code.
-rw-r--r--dda.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/dda.c b/dda.c
index 5c8a3a1..00fa404 100644
--- a/dda.c
+++ b/dda.c
@@ -74,33 +74,12 @@ dda (test_data_t *testdata)
double xi = next_sample_x (x0);
double e = (xi - x0) * dy - (yi - y0) * dx;
- if (dx >= 0)
- {
- while (e <= 0)
- {
- double s = sample_step_x_forward (xi);
-
- e += s * dy;
- xi += s;
- }
- }
- else
- {
- double s = sample_step_x_backward (xi);
-
- while (e > s * dy)
- {
- e -= s * dy;
- xi -= s;
-
- s = sample_step_x_backward (xi);
- }
- }
-
#if 0
printf ("= = = = %f %f %f %f = = = = \n", x0, y0, x1, y1);
#endif
+ goto step;
+
while (yi < next_sample_y (y1))
{
if (testdata->points[i++] != xi ||
@@ -111,7 +90,9 @@ dda (test_data_t *testdata)
}
e -= sample_step_y (yi) * dx;
+ yi += sample_step_y (yi);
+ step:
if (dx >= 0)
{
while (e <= 0)
@@ -134,8 +115,6 @@ dda (test_data_t *testdata)
s = sample_step_x_backward (xi);
}
}
-
- yi += sample_step_y (yi);
}
}