53 static int polycmpX(
const void*,
const void*);
54 static int polycmpY(
const void*,
const void*);
74 long left, bottom, right, top;
100 n = (poly->nvertices << 1) - 2;
101 for (i = 0; i < n; i += 2) {
102 Newlink->
pa_x = poly->xy[i];
103 Newlink->
pa_y = poly->xy[i+1];
110 if (pa->
pa_x != poly->xy[i] || pa->
pa_y != poly->xy[i+1]) {
111 Newlink->
pa_x = poly->xy[i];
112 Newlink->
pa_y = poly->xy[i+1];
146 if (Polycurrent == Newpoly) {
152 pp = pa = Polycurrent->
pl_pair;
179 struct pair *pa, *
pp, *pfirst, *plast, *pnext;
181 long x, y, xnext, ynext;
184 for (list = Polybuf; list < end; list++) {
193 if (pp->
pa_x > right)
212 if (xnext <= right && x > right) {
215 y += (ynext - y)*(((
double)(right - x))/(xnext - x));
217 y += ((right-x)*(ynext-y))/(xnext-x);
221 if (x != xnext || y != ynext) {
239 if (pp->
pa_x > right) {
251 y += (ynext - y)*(((
double)(right - x))/(xnext - x));
253 y += ((right-x)*(ynext-y))/(xnext-x);
257 if (x != xnext || y != ynext) {
270 if (pfirst->
pa_next != plast) {
285 if (pointer < Newpoly)
290 for (list = end, end = Polybuf; list <
Newpoly; list++) {
293 end->pl_start =
NULL;
306 struct pair *pa, *
pp, *pfirst, *plast, *pnext;
308 long x, y, xnext, ynext;
311 for (list = Polybuf; list < end; list++) {
339 if (xnext >= left && x < left) {
342 y += (ynext - y)*(((
double)(left - x))/(xnext - x));
344 y += ((left - x) * (ynext - y))/(xnext - x);
348 if (x != xnext || y != ynext) {
366 if (pp->
pa_x < left) {
378 y += (ynext - y)*(((
double)(left - x))/(xnext - x));
380 y += ((left - x) * (ynext - y))/(xnext - x);
384 if (x != xnext || y != ynext) {
397 if (pfirst->
pa_next != plast) {
412 if (pointer < Newpoly)
417 for (list = end, end = Polybuf; list <
Newpoly; list++) {
420 end->pl_start =
NULL;
433 struct pair *pa, *
pp, *pfirst, *plast, *pnext;
435 long x, y, xnext, ynext;
438 for (list = Polybuf; list < end; list++) {
447 if (pp->
pa_y < bottom)
466 if (ynext >= bottom && y < bottom) {
469 x += (xnext - x)*(((
double)(bottom - y))/(ynext - y));
471 x += ((bottom - y) * (xnext - x))/(ynext - y);
475 if (x != xnext || y != ynext) {
493 if (pp->
pa_y < bottom) {
505 x += (xnext - x)*(((
double)(bottom - y))/(ynext - y));
507 x += ((bottom - y) * (xnext - x))/(ynext - y);
511 if (x != xnext || y != ynext) {
524 if (pfirst->
pa_next != plast) {
539 if (pointer < Newpoly)
544 for (list = end, end = Polybuf; list <
Newpoly; list++) {
547 end->pl_start =
NULL;
560 struct pair *pa, *
pp, *pfirst, *plast, *pnext;
562 long x, y, xnext, ynext;
565 for (list = Polybuf; list < end; list++) {
593 if (ynext <= top && y > top) {
596 x += (xnext - x)*(((
double)(top - y))/(ynext - y));
598 x += ((top - y) * (xnext - x))/(ynext - y);
602 if (x != xnext || y != ynext) {
620 if (pp->
pa_y > top) {
632 x += (xnext - x)*(((
double)(top - y))/(ynext - y));
634 x += ((top - y) * (xnext - x))/(ynext - y);
638 if (x != xnext || y != ynext) {
651 if (pfirst->
pa_next != plast) {
666 if (pointer < Newpoly)
671 for (list = end, end = Polybuf; list <
Newpoly; list++) {
674 end->pl_start =
NULL;
688 struct plist tmp, *b, *bb;
695 for (b = base; b <
Newpoly; b += 2) {
705 (b+1)->pl_pair =
NULL;
706 if (b->
pl_start != (b+1)->pl_start) {
707 for (bb = b+2; bb <
Newpoly; bb++) {
717 if ((b+1)->pl_pair != (b+1)->
pl_start) {
724 (b+1)->pl_pair =
NULL;
725 if (b->
pl_start != (b+1)->pl_start) {
726 for (bb = b+2; bb <
Newpoly; bb++) {
727 if (bb->
pl_start == (b+1)->pl_start) {
749 ((
struct plist *)p2)->pl_pair->pa_x);
763 ((
struct plist *)p2)->pl_pair->pa_y);
778 if (Linkbuf ==
NULL) {
792 Linkbuf = (
struct pair *)
796 Newlink = Linkbuf + num;
797 for (i = 0; i < num; i++) {
798 (Linkbuf+i)->
pa_next = ((Linkbuf+i)->pa_next - oldbuf) + Linkbuf;
799 (Linkbuf+i)->
pa_prev = ((Linkbuf+i)->pa_prev - oldbuf) + Linkbuf;
802 for (i = 0; i < num; i++) {
803 (Polybuf+i)->pl_pair = ((Polybuf+i)->pl_pair - oldbuf) + Linkbuf;
816 if (Polybuf ==
NULL) {
829 Polybuf = (
struct plist *)
833 Newpoly = Polybuf + num;
static struct plist * Newpoly
static struct pair * Newlink
static void clip_bottom()
static struct plist * Polybuf
static struct pair * Linkbuf
int NextPolygon(POLYGON *p)
static struct plist * Polycurrent
void PolygonClip(POLYGON *poly, long left, long bottom, long right, long top)