diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-06 02:19:49 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-20 10:48:50 -0500 |
commit | 17195b300a3b565c01ee1faf4f58e39bd2901540 (patch) | |
tree | 08530f083b34d7ddbaa8c03bb397c62b646e5f40 | |
parent | d0e134ff45e728a1697f871e99fcb85c8f98e2d8 (diff) |
Track error in e * dy
-rw-r--r-- | dda.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -68,11 +68,13 @@ dda (test_data_t *testdata) double y1 = testdata->segment.y1; int i = 0; - double dxdy = (x1 - x0) / (y1 - y0); + double dx = (x1 - x0); + double dy = (y1 - y0); + double dxdy = dx / dy; double y = next_sample_y (y0); double x = (y - y0) * dxdy + x0; double xi = next_sample_x (x); - double e = xi - x; + double e = (xi - x) * dy; #if 0 printf ("= = = = %f %f %f %f = = = = \n", x0, y0, x1, y1); @@ -87,8 +89,7 @@ dda (test_data_t *testdata) exit (-1); } - e -= sample_step_y (y) * dxdy; - x += sample_step_y (y) * dxdy; + e -= sample_step_y (y) * dxdy * dy; if (dxdy >= 0) { @@ -96,7 +97,7 @@ dda (test_data_t *testdata) { double s = sample_step_x_forward (xi); - e += s; + e += s * dy; xi += s; } } @@ -104,9 +105,9 @@ dda (test_data_t *testdata) { double s = sample_step_x_backward (xi); - while (e > s) + while (e > s * dy) { - e -= s; + e -= s * dy; xi -= s; s = sample_step_x_backward (xi); |