-
Notifications
You must be signed in to change notification settings - Fork 0
/
bresenham.c
43 lines (35 loc) · 945 Bytes
/
bresenham.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @file bresenham.c
* @brief Interpolate using Bresenhams line drawing algorothm.
* Interpolate one point at a time.
*
* See: http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
* For a good primer.
*
*/
#include "bresenham.h"
// Call to reset the kernel.
void interp_reset(tInterpKernel *kernel) {
kernel->error = kernel->denominator / 2;
}
void interp_init(tInterpKernel *kernel, unsigned num, unsigned denom) {
if ( num > denom ) {
kernel->fixed = num / denom;
num -= kernel->fixed * denom;
}
else {
kernel->fixed = 0;
}
kernel->numerator = num;
kernel->denominator = denom;
interp_reset(kernel);
}
unsigned interp_next(tInterpKernel *kernel) {
unsigned ret = kernel->fixed;
kernel->error -= kernel->numerator;
if ( kernel->error < 0 ) {
ret++;
kernel->error += kernel->denominator;
}
return(ret);
}