diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-06 02:02:10 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-20 10:48:50 -0500 |
commit | ae105f154bd71864cc318bb50e1ad2473cde218a (patch) | |
tree | d093587f285509aa09816349854659a14c3f4a73 | |
parent | e17f539d3b3017bd310b077a7a5fb93f4e7b70c9 (diff) |
Add error tracking
-rw-r--r-- | dda.c | 53 |
1 files changed, 48 insertions, 5 deletions
@@ -36,7 +36,7 @@ next_sample_y (double y) } static double -sample_step_x (double x) +sample_step_x_forward (double x) { if ((x - floor (x)) == 0.625) return 0.5; @@ -45,9 +45,18 @@ sample_step_x (double x) } static double +sample_step_x_backward (double x) +{ + if ((x - floor (x)) == 0.125) + return 0.5; + else + return 0.25; +} + +static double sample_step_y (double y) { - return sample_step_x (y); + return sample_step_x_forward (y); } static void @@ -63,18 +72,52 @@ dda (test_data_t *testdata) double y = next_sample_y (y0); double x = (y - y0) * dxdy + x0; double xi = next_sample_x (x); + double e = xi - x; + +#if 0 + printf ("= = = = %f %f %f %f = = = = \n", x0, y0, x1, y1); +#endif while (y < next_sample_y (y1)) { if (testdata->points[i++] != xi || testdata->points[i++] != y) { - printf ("error\n"); + printf ("error %f %f %f\n", x, testdata->points[i - 1], xi); exit (-1); } - x += sample_step_y (y) * dxdy; - xi = next_sample_x (x); + if (dxdy >= 0) + { + e -= sample_step_y (y) * dxdy; + x += sample_step_y (y) * dxdy; + + while (e <= 0) + { + double s = sample_step_x_forward (xi); + + e += s; + xi += s; + } + } + else + { + double s; + + e -= sample_step_y (y) * dxdy; + x += sample_step_y (y) * dxdy; + + s = sample_step_x_backward (xi); + + while (e > s) + { + e -= s; + xi -= s; + + s = sample_step_x_backward (xi); + } + } + y += sample_step_y (y); } } |