Delphi 2005 pro
C conversion
Polygon
Clipping
CSG
2D
Hello,
2D gives more chalenges then i expected.
Now i am trying to merge 2 polygon shapes to a new one.
Doing a search on the inet i found the following: http://davis.wpi.edu/~matt/courses/clipping/ That looks doable. But looking at the c source i get somewhat confused again as:
Code: typedef struct _node { int x, y; struct _node *next; struct _node *prev; struct _node *nextPoly; /* pointer to the next polygon */ struct _node *neighbor; /* the coresponding intersection point */ int intersect; /* 1 if an intersection point, 0 otherwise */ int entry; /* 1 if an entry point, 0 otherwise */ int visited; /* 1 if the node has been visited, 0 otherwise */ float alpha; /* intersection point placemet */ } node;
In delphi that could be written as:
Code: type tnode = class; pnode = ^tnode; tnode = class x, y: single; next: pnode; prev: pnode; nextPoly: pnode; // pointer to the next polygon */ neighbor : pnode; // the coresponding intersection point */ intersect: bool; // 1 if an intersection point, 0 otherwise */ entry: bool; // 1 if an entry point, 0 otherwise */ visited: bool; // 1 if the node has been visited, 0 otherwise */ alpha: single; // intersection point placemet */ end;
Now i would rather use a record. But this does not work:
Code: tnode = record; pnode = ^tnode;
Now this is initialized as:
Code: node *s=0, *c=0, *root=0;
What is happening here assing 0 to record? I gues i have just to create my object and/or record here. The following also confuses me ( i think i either adds point for polygon a or for polygon b).
Code: void add(Widget w, int which_button, int x, int y, void *data) { node *new; if (!DRAW) return; if (which_button == 1) { new = malloc(sizeof(node)); new->x = x; new->y = y; new->prev = 0; /* not need to initialize with 0 after malloc ... */ new->nextPoly = 0; new->neighbor = 0; new->intersect = 0; new->entry = 0; new->visited = 0; new->alpha = 0.; if (DRAW == 1) { new->next = s; if (s) s->prev = new; s = new; } else /* DRAW == 2 */ { new->next = c; if (c) c->prev = new; c = new; } redisplay(W[3], X, Y, NULL); } else if (which_button == 3) { DRAW = DRAW==1 ? 2:0; redisplay(W[3], X, Y, NULL); } }
What is happinging here:
Code: if (DRAW == 1) { new->next = s; if (s) s->prev = new; s = new; }
the s that was created empty before is assigned to next.
now the prev of s is compared to new that is the point that is currently added? Or is s compared to prev of s and if that is the case it is made the new value? aarghh....
finaly the new is made the new s. I am getting confused here.
Thank for your help in advance.
|