diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-06 02:56:12 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-20 10:48:50 -0500 |
commit | dd1b71a792b8fafdc9b729b7a2de345b07874ef3 (patch) | |
tree | 3894e842d3e1bd6026f13a1a2979139bdf0e8058 | |
parent | b87ea4c1d5ecd243717232d89df051db52de5f60 (diff) |
Compute first sample through a micro step from y0 to yi.
Instead of computing the precise X coordinate for the first row
directly, which involves a division, simply compute the error term at
y0, and then do a regular step from y0 to next_sample_y (y0).
-rw-r--r-- | dda.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -73,8 +73,32 @@ dda (test_data_t *testdata) double dxdy = dx / dy; double yi = next_sample_y (y0); double x = (yi - y0) * dxdy + x0; - double xi = next_sample_x (x); - double e = (xi - x) * dy; + double xi = next_sample_x (x0); + double e = (xi - x0) * dy; + + e -= (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); |