Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
bresenham
Browse files Browse the repository at this point in the history
  • Loading branch information
GeneralGuy4872 committed Jan 1, 2020
1 parent 94baa5f commit 6d520c9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 54 deletions.
31 changes: 31 additions & 0 deletions src/bresenham.c
Original file line number Diff line number Diff line change
@@ -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 (errory0.5) {y += signy;}
errorz += deltaerrorz;
if (errorz0.5) {z += signz;}
x += signz;
if (signx < 0) {
if (xp2[0]) {return output}
} else {
if (xp2[0] {return output}
}
}

/*same for y, z*/
33 changes: 25 additions & 8 deletions src/coord3list.messy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
47 changes: 1 addition & 46 deletions src/drawline.c
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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++;
}

0 comments on commit 6d520c9

Please sign in to comment.