diff --git a/src/bresenham.c b/src/bresenham.c new file mode 100644 index 0000000..38e3ce2 --- /dev/null +++ b/src/bresenham.c @@ -0,0 +1,31 @@ +ucoord3list * bline (ucoord3 p1, ucoord3 p2) { +float deltax = p2[0] - p1[0]; +int signx = sgnf(deltax); +float deltay = p2[1] - p1[1]; +int signy = sgnf(deltay); +float deltaz = p2[2] - p1[2]; +int signz = sgnf(deltaz); +ucoordlist3 * output = ucoordlist3__new(p1); +ucoordlist3 * output_tail = output; + +if ( (fabs(deltay) ≤ 1.0) && (fabs(deltaz) ≤ 1.0) ) { + float deltaerrory = fabs(deltay / deltax); + float errory = 0.0; + float deltaerrorz = fabs(deltaz / deltax); + float errorz = 0.0; + int x,y,z; + forever { + output_tail = ucoordlist3__tail_push_int(output_tail,x,y,z); + errory += deltaerrory; + if (errory ≥ 0.5) {y += signy;} + errorz += deltaerrorz; + if (errorz ≥ 0.5) {z += signz;} + x += signz; + if (signx < 0) { + if (x ≤ p2[0]) {return output} + } else { + if (x ≥ p2[0] {return output} + } + } + +/*same for y, z*/ diff --git a/src/coord3list.messy b/src/coord3list.messy index 9339174..d8d9aa7 100644 --- a/src/coord3list.messy +++ b/src/coord3list.messy @@ -15,6 +15,15 @@ ucoord3list * ucoord3list__new (ucoord3 data) { new->z = data[2]; return new; +ucoord3list * ucoord3list__new_int (int x,int y,int z) { + ucoord3list * new = malloc(sizeof(ucoord3list)); + new->prev = NULL; + new->next = NULL; + new->x = x; + new->y = y; + new->z = z; + return new; + ucoord3list * ucoord3list__head_push_raw (ucoord3list * head,ucoord3list * new) { new->prev = NULL; @@ -23,7 +32,8 @@ ucoord3list * ucoord3list__head_push_raw (ucoord3list * head,ucoord3list * new) return new; } -#define ucoord3list__head_push_new(X,Y) ucoord3list__head_push_raw(X,ucoord3list__new(Y)) +#define ucoord3list__head_push_new(A,B) ucoord3list__head_push_raw(A,ucoord3list__new(B)) +#define ucoord3list__head_push_int(A,X,Y,Z) ucoord3list__head_push_raw(A,ucoord3list__new_int(X,Y,Z)) ucoord3list * ucoord3list__head_pop (ucoord3list * head) { ucoord3list * output = head->next; @@ -63,7 +73,8 @@ ucoord3list * ucoord3list__tail_push_raw (ucoord3list * tail,ucoord3list * new) return new; } -#define ucoord3list__tail_push_new(X,Y) ucoord3list__tail_push_raw(X,ucoord3list__new(Y)) +#define ucoord3list__tail_push_new(A,B) ucoord3list__tail_push_raw(A,ucoord3list__new(B)) +#define ucoord3list__tail_push_int(A,X,Y,Z) ucoord3list__tail_push_raw(A,ucoord3list__new_int(X,Y,Z)) ucoord3list * ucoord3list__tail_pop(ucoord3list * tail) { ucoord3list * output = tail->prev; @@ -112,7 +123,8 @@ ucoord3list * ucoord3list__insert_after_raw (ucoord3list * after,ucoord3list * n } } -#define ucoord3list__insert_after_new(X,Y) ucoord3list__insert_after_raw(X,ucoord3list__new(Y)) +#define ucoord3list__insert_after_new(A,B) ucoord3list__insert_after_raw(A,ucoord3list__new(B)) +#define ucoord3list__insert_after_int(A,X,Y,Z) ucoord3list__insert_after_raw(A,ucoord3list__new_int(X,Y,Z)) ucoord3list * ucoord3list__insert_before(ucoord3list * before,ucoord3list * new) { if (before->next == NULL) { @@ -129,7 +141,8 @@ ucoord3list * ucoord3list__insert_before(ucoord3list * before,ucoord3list * new) } } -#define ucoord3list__insert_before_new(X,Y) ucoord3list__insert_before_raw(X,ucoord3list__new(Y)) +#define ucoord3list__insert_before_new(A,B) ucoord3list__insert_before_raw(A,ucoord3list__new(B)) +#define ucoord3list__insert_before_int(A,X,Y,Z) ucoord3list__insert_before_raw(X,ucoord3list__new_int(X,Y,Z)) ucoord3list * ucoord3list__drop(ucoord3list * deadbeef) { if (deadbeef->next != NULL) { @@ -227,7 +240,8 @@ scoord3list * scoord3list__head_push_raw (scoord3list * head,scoord3list * new) return new; } -#define scoord3list__head_push_new(X,Y) scoord3list__head_push_raw(X,scoord3list__new(Y)) +#define scoord3list__head_push_new(A,B) scoord3list__head_push_raw(A,scoord3list__new(B)) +#define scoord3list__head_push_int(A,X,Y,Z) scoord3list__head_push_raw(A,scoord3list__new_int(X,Y,Z)) scoord3list * scoord3list__head_pop (scoord3list * head) { scoord3list * output = head->next; @@ -267,7 +281,8 @@ scoord3list * scoord3list__tail_push_raw (scoord3list * tail,scoord3list * new) return new; } -#define scoord3list__tail_push_new(X,Y) scoord3list__tail_push_raw(X,scoord3list__new(Y)) +#define scoord3list__tail_push_new(A,B) scoord3list__tail_push_raw(A,scoord3list__new(B)) +#define scoord3list__tail_push_int(A,X,Y,Z) scoord3list__tail_push_raw(X,scoord3list__new_int(X,Y,Z)) scoord3list * scoord3list__tail_pop(scoord3list * tail) { scoord3list * output = tail->prev; @@ -316,7 +331,8 @@ scoord3list * scoord3list__insert_after_raw (scoord3list * after,scoord3list * n } } -#define scoord3list__insert_after_new(X,Y) scoord3list__insert_after_raw(X,scoord3list__new(Y)) +#define scoord3list__insert_after_new(X,Y) scoord3list__insert_after_raw(A,scoord3list__new(B)) +#define scoord3list__insert_after_int(A,X,Y,Z) scoord3list__insert_after_raw(A,scoord3list__new_int(X,Y,Z)) scoord3list * scoord3list__insert_before(scoord3list * before,scoord3list * new) { if (before->next == NULL) { @@ -333,7 +349,8 @@ scoord3list * scoord3list__insert_before(scoord3list * before,scoord3list * new) } } -#define scoord3list__insert_before_new(X,Y) scoord3list__insert_before_raw(X,scoord3list__new(Y)) +#define scoord3list__insert_before_new(A,B) scoord3list__insert_before_raw(A,scoord3list__new(B)) +#define scoord3list__insert_before_int(A,X,Y,Z) scoord3list__insert_before_raw(A,scoord3list__new_int(X,Y,Z)) scoord3list * scoord3list__drop(scoord3list * deadbeef) { if (deadbeef->next != NULL) { diff --git a/src/drawline.c b/src/drawline.c index 2be9404..c4dc418 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -1,4 +1,4 @@ -ucoord3list * attractorline(ucoord3 p1, ucoord3 p2,int glyph) { +ucoord3list * attractorline(ucoord3 p1, ucoord3 p2) { x = p2[0] - p1[0]; y = p2[1] - p1[1]; @@ -34,48 +34,3 @@ tail->prev = head; } return head; } - - -/*unfinished*/ -breshamline(char args,ucoord3 p1,ucoord3 p2,int glyph) - int deltx = p1[0] - p0[0]; - int xdir = sgn(deltx); - if (xdir < 0) { - deltx *= -1; - } - int delty = p1[1] - p0[1]; - int ydir = sgn(delty); - if (ydir < 0) { - delty *= -1; - } - int deltz = p1[2] - p0[2]; - int zdir = sgn(deltz); - if (zdir < 0) { - deltz *= -1; - } - - /*HR*/ - - if ((abs(delty) ≤ 1) && (abs(deltz) ≤ 1)) { - goto(goforx); - } - else if ((abs(deltx) ≤ 1) && (abs(deltz) ≤ 1)) { - goto(gofory); - } - else if ((abs(deltx) ≤ 1) && (abs(delty) ≤ 1)) { - goto(goforz); - } - - /*HR*/ - - goforx: - /*for*/{ - int n = 0; - int x = p0[0]; - - while ((x != p1[0]) && (n < 100)) { - - /*and then*/ - x += xdir; - n++; - } \ No newline at end of file