summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-06 02:56:12 -0500
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2010-12-20 10:48:50 -0500
commitdd1b71a792b8fafdc9b729b7a2de345b07874ef3 (patch)
tree3894e842d3e1bd6026f13a1a2979139bdf0e8058
parentb87ea4c1d5ecd243717232d89df051db52de5f60 (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.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/dda.c b/dda.c
index 1b0cfa5..8e4d79e 100644
--- a/dda.c
+++ b/dda.c
@@ -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);