diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-05 01:37:57 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-20 10:48:49 -0500 |
commit | 2529df3f65bbb05c67446108e65b9a28338683bd (patch) | |
tree | 0b66b2b4b5d87989699a91e9d9cbbaa8b679906c /dda.c | |
parent | b2ec3fa1439bf60b2873fa0e9c2cc39fc1bf9afe (diff) |
Simple-minded floating point dda
Diffstat (limited to 'dda.c')
-rw-r--r-- | dda.c | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -0,0 +1,57 @@ +#include <stdio.h> +#include <math.h> + +static double +next_sample_x (double x) +{ + return ceil (x - 0.5) + 0.5; +} + +static double +next_sample_y (double y) +{ + return ceil (y - 0.5) + 0.5; +} + +static double +sample_step_x (double x) +{ + (void)x; + + return 1.0; +} + +static double +sample_step_y (double y) +{ + (void)y; + + return 1.0; +} + +static void +dda (double x0, double y0, double x1, double y1) +{ + double y = next_sample_y (y0); + + while (y < next_sample_y (y1)) + { + double x = ((y - y0) / (y1 - y0)) * (x1 - x0) + x0; + double xi = next_sample_x (x); + + y += sample_step_y (y); + } +} + +int +main () +{ + dda (0.5, 0.5, 2.5, 1.6); + dda (0.3, 0.2, 3.7, 2.2); + dda (3.7, 2.2, 7.2, 2.8); + dda (3.7, 2.2, 4.2, 7.2); + dda (0.5, 0.5, 1.5, 1.5); + dda (0.5, 0.5, 2.5, 2.5); + + return 0; +} |