Jspice3
polyclip.c File Reference
#include "spice.h"
#include "sced.h"
#include "scedmacs.h"
Include dependency graph for polyclip.c:

Go to the source code of this file.

Data Structures

struct  pair
 
struct  plist
 

Macros

#define DO_FLOAT
 

Functions

static void clip_right ()
 
static void clip_left ()
 
static void clip_bottom ()
 
static void clip_top ()
 
static void linkpolys ()
 
static int polycmpX ()
 
static int polycmpY ()
 
static void newlink ()
 
static void newpoly ()
 
void PolygonClip (POLYGON *poly, long left, long bottom, long right, long top)
 
int NextPolygon (POLYGON *p)
 
static void clip_right (long right)
 
static void clip_left (long left)
 
static void clip_bottom (long bottom)
 
static void clip_top (long top)
 
static void linkpolys (struct plist *base, int XorY)
 
static int polycmpX (char *p1, char *p2)
 
static int polycmpY (char *p1, char *p2)
 

Variables

static struct plistPolybuf
 
static struct plistNewpoly
 
static struct plistPolycurrent
 
static int Numpolys
 
static struct pairLinkbuf
 
static struct pairNewlink
 
static int Numlinks
 

Macro Definition Documentation

#define DO_FLOAT

Definition at line 22 of file polyclip.c.

Function Documentation

static void clip_bottom ( )
static
static void clip_bottom ( long  bottom)
static

Definition at line 429 of file polyclip.c.

432 {
433  struct pair *pa, *pp, *pfirst, *plast, *pnext;
434  struct plist *list, *end, *pointer;
435  long x, y, xnext, ynext;
436 
437  end = Newpoly;
438  for (list = Polybuf; list < end; list++) {
439  pointer = Newpoly;
440  pa = list->pl_pair;
441  /*
442  * First, find a vertex outside of the clipping
443  * region.
444  */
445 
446  for (pp = pa;;) {
447  if (pp->pa_y < bottom)
448  break;
449  pp = pp->pa_next;
450  if (pp == pa) {
451  /* no clipping needed */
452  Newpoly->pl_pair = pa;
453  newpoly();
454  goto next;
455  }
456  }
457  /* start with an "outside" point */
458 
459  for (pa = pp;;) {
460  x = pp->pa_x;
461  y = pp->pa_y;
462  pnext = pp->pa_next;
463  xnext = pnext->pa_x;
464  ynext = pnext->pa_y;
465 
466  if (ynext >= bottom && y < bottom) {
467  /* poly edge crosses bounding clip line */
468 #ifdef DO_FLOAT
469  x += (xnext - x)*(((double)(bottom - y))/(ynext - y));
470 #else
471  x += ((bottom - y) * (xnext - x))/(ynext - y);
472 #endif
473  y = bottom;
474 
475  if (x != xnext || y != ynext) {
476  pfirst = Newlink;
477  pfirst->pa_x = x;
478  pfirst->pa_y = y;
479  pfirst->pa_prev = NULL;
480  newlink();
481  pp = pnext;
482  pfirst->pa_next = pp;
483  pp->pa_prev = pfirst;
484  }
485  else {
486  pp = pnext;
487  pfirst = pnext;
488  pfirst->pa_prev = NULL;
489  }
490 
491  /* walk along inside points, find the last one */
492  for (;;) {
493  if (pp->pa_y < bottom) {
494  pnext = pp;
495  pp = pp->pa_prev;
496  break;
497  }
498  pp = pp->pa_next;
499  }
500  x = pp->pa_x;
501  y = pp->pa_y;
502  xnext = pnext->pa_x;
503  ynext = pnext->pa_y;
504 #ifdef DO_FLOAT
505  x += (xnext - x)*(((double)(bottom - y))/(ynext - y));
506 #else
507  x += ((bottom - y) * (xnext - x))/(ynext - y);
508 #endif
509  y = bottom;
510 
511  if (x != xnext || y != ynext) {
512  plast = Newlink;
513  plast->pa_x = x;
514  plast->pa_y = y;
515  pp->pa_next = plast;
516  plast->pa_prev = pp;
517  plast->pa_next = NULL;
518  newlink();
519  }
520  else {
521  plast = pp;
522  plast->pa_next = NULL;
523  }
524  if (pfirst->pa_next != plast) {
525 
526  /* note that we are saving poly fragments */
527  Newpoly->pl_pair = pfirst;
528  Newpoly->pl_start = pfirst;
529  newpoly();
530  Newpoly->pl_pair = plast;
531  Newpoly->pl_start = pfirst;
532  newpoly();
533  }
534  }
535  pp = pnext;
536  if (pp == pa)
537  break;
538  }
539  if (pointer < Newpoly)
540  linkpolys(pointer,'X');
541 next:
542  ;
543  }
544  for (list = end, end = Polybuf; list < Newpoly; list++) {
545  if (list->pl_pair) {
546  end->pl_pair = list->pl_pair;
547  end->pl_start = NULL;
548  end++;
549  }
550  }
551  Newpoly = end;
552 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static void linkpolys()
static struct plist * Polybuf
Definition: polyclip.c:37
Definition: objects.c:1183
struct pair * pa_prev
Definition: polyclip.c:28
static void newpoly()
Definition: polyclip.c:810
long pa_x
Definition: polyclip.c:26
struct pair * pl_start
Definition: polyclip.c:34
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
static void newlink()
Definition: polyclip.c:772
Definition: dir.c:53
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33
static void clip_left ( )
static
static void clip_left ( long  left)
static

Definition at line 302 of file polyclip.c.

305 {
306  struct pair *pa, *pp, *pfirst, *plast, *pnext;
307  struct plist *list, *end, *pointer;
308  long x, y, xnext, ynext;
309 
310  end = Newpoly;
311  for (list = Polybuf; list < end; list++) {
312  pointer = Newpoly;
313  pa = list->pl_pair;
314  /*
315  * First, find a vertex outside of the clipping
316  * region.
317  */
318 
319  for (pp = pa;;) {
320  if (pp->pa_x < left)
321  break;
322  pp = pp->pa_next;
323  if (pp == pa) {
324  /* no clipping needed */
325  Newpoly->pl_pair = pa;
326  newpoly();
327  goto next;
328  }
329  }
330  /* start with an "outside" point */
331 
332  for (pa = pp;;) {
333  x = pp->pa_x;
334  y = pp->pa_y;
335  pnext = pp->pa_next;
336  xnext = pnext->pa_x;
337  ynext = pnext->pa_y;
338 
339  if (xnext >= left && x < left) {
340  /* poly edge crosses bounding clip line */
341 #ifdef DO_FLOAT
342  y += (ynext - y)*(((double)(left - x))/(xnext - x));
343 #else
344  y += ((left - x) * (ynext - y))/(xnext - x);
345 #endif
346  x = left;
347 
348  if (x != xnext || y != ynext) {
349  pfirst = Newlink;
350  pfirst->pa_x = x;
351  pfirst->pa_y = y;
352  pfirst->pa_prev = NULL;
353  newlink();
354  pp = pnext;
355  pfirst->pa_next = pp;
356  pp->pa_prev = pfirst;
357  }
358  else {
359  pp = pnext;
360  pfirst = pnext;
361  pfirst->pa_prev = NULL;
362  }
363 
364  /* walk along inside points, find the last one */
365  for (;;) {
366  if (pp->pa_x < left) {
367  pnext = pp;
368  pp = pp->pa_prev;
369  break;
370  }
371  pp = pp->pa_next;
372  }
373  x = pp->pa_x;
374  y = pp->pa_y;
375  xnext = pnext->pa_x;
376  ynext = pnext->pa_y;
377 #ifdef DO_FLOAT
378  y += (ynext - y)*(((double)(left - x))/(xnext - x));
379 #else
380  y += ((left - x) * (ynext - y))/(xnext - x);
381 #endif
382  x = left;
383 
384  if (x != xnext || y != ynext) {
385  plast = Newlink;
386  plast->pa_x = x;
387  plast->pa_y = y;
388  pp->pa_next = plast;
389  plast->pa_prev = pp;
390  plast->pa_next = NULL;
391  newlink();
392  }
393  else {
394  plast = pp;
395  plast->pa_next = NULL;
396  }
397  if (pfirst->pa_next != plast) {
398 
399  /* note that we are saving poly fragments */
400  Newpoly->pl_pair = pfirst;
401  Newpoly->pl_start = pfirst;
402  newpoly();
403  Newpoly->pl_pair = plast;
404  Newpoly->pl_start = pfirst;
405  newpoly();
406  }
407  }
408  pp = pnext;
409  if (pp == pa)
410  break;
411  }
412  if (pointer < Newpoly)
413  linkpolys(pointer,'Y');
414 next:
415  ;
416  }
417  for (list = end, end = Polybuf; list < Newpoly; list++) {
418  if (list->pl_pair) {
419  end->pl_pair = list->pl_pair;
420  end->pl_start = NULL;
421  end++;
422  }
423  }
424  Newpoly = end;
425 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static void linkpolys()
static struct plist * Polybuf
Definition: polyclip.c:37
Definition: objects.c:1183
struct pair * pa_prev
Definition: polyclip.c:28
static void newpoly()
Definition: polyclip.c:810
long pa_x
Definition: polyclip.c:26
struct pair * pl_start
Definition: polyclip.c:34
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
static void newlink()
Definition: polyclip.c:772
Definition: dir.c:53
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33
static void clip_right ( )
static
static void clip_right ( long  right)
static

Definition at line 175 of file polyclip.c.

178 {
179  struct pair *pa, *pp, *pfirst, *plast, *pnext;
180  struct plist *list, *end, *pointer;
181  long x, y, xnext, ynext;
182 
183  end = Newpoly;
184  for (list = Polybuf; list < end; list++) {
185  pointer = Newpoly;
186  pa = list->pl_pair;
187  /*
188  * First, find a vertex outside of the clipping
189  * region.
190  */
191 
192  for (pp = pa;;) {
193  if (pp->pa_x > right)
194  break;
195  pp = pp->pa_next;
196  if (pp == pa) {
197  /* no clipping needed */
198  Newpoly->pl_pair = pa;
199  newpoly();
200  goto next;
201  }
202  }
203  /* start with an "outside" point */
204 
205  for (pa = pp;;) {
206  x = pp->pa_x;
207  y = pp->pa_y;
208  pnext = pp->pa_next;
209  xnext = pnext->pa_x;
210  ynext = pnext->pa_y;
211 
212  if (xnext <= right && x > right) {
213  /* poly edge crosses bounding clip line */
214 #ifdef DO_FLOAT
215  y += (ynext - y)*(((double)(right - x))/(xnext - x));
216 #else
217  y += ((right-x)*(ynext-y))/(xnext-x);
218 #endif
219  x = right;
220 
221  if (x != xnext || y != ynext) {
222  pfirst = Newlink;
223  pfirst->pa_x = x;
224  pfirst->pa_y = y;
225  pfirst->pa_prev = NULL;
226  newlink();
227  pp = pnext;
228  pfirst->pa_next = pp;
229  pp->pa_prev = pfirst;
230  }
231  else {
232  pp = pnext;
233  pfirst = pnext;
234  pfirst->pa_prev = NULL;
235  }
236 
237  /* walk along inside points, find the last one */
238  for (;;) {
239  if (pp->pa_x > right) {
240  pnext = pp;
241  pp = pp->pa_prev;
242  break;
243  }
244  pp = pp->pa_next;
245  }
246  x = pp->pa_x;
247  y = pp->pa_y;
248  xnext = pnext->pa_x;
249  ynext = pnext->pa_y;
250 #ifdef DO_FLOAT
251  y += (ynext - y)*(((double)(right - x))/(xnext - x));
252 #else
253  y += ((right-x)*(ynext-y))/(xnext-x);
254 #endif
255  x = right;
256 
257  if (x != xnext || y != ynext) {
258  plast = Newlink;
259  plast->pa_x = x;
260  plast->pa_y = y;
261  pp->pa_next = plast;
262  plast->pa_prev = pp;
263  plast->pa_next = NULL;
264  newlink();
265  }
266  else {
267  plast = pp;
268  plast->pa_next = NULL;
269  }
270  if (pfirst->pa_next != plast) {
271 
272  /* note that we are saving poly fragments */
273  Newpoly->pl_pair = pfirst;
274  Newpoly->pl_start = pfirst;
275  newpoly();
276  Newpoly->pl_pair = plast;
277  Newpoly->pl_start = pfirst;
278  newpoly();
279  }
280  }
281  pp = pnext;
282  if (pp == pa)
283  break;
284  }
285  if (pointer < Newpoly)
286  linkpolys(pointer,'Y');
287 next:
288  ;
289  }
290  for (list = end, end = Polybuf; list < Newpoly; list++) {
291  if (list->pl_pair) {
292  end->pl_pair = list->pl_pair;
293  end->pl_start = NULL;
294  end++;
295  }
296  }
297  Newpoly = end;
298 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static void linkpolys()
static struct plist * Polybuf
Definition: polyclip.c:37
Definition: objects.c:1183
struct pair * pa_prev
Definition: polyclip.c:28
static void newpoly()
Definition: polyclip.c:810
long pa_x
Definition: polyclip.c:26
struct pair * pl_start
Definition: polyclip.c:34
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
static void newlink()
Definition: polyclip.c:772
Definition: dir.c:53
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33
static void clip_top ( )
static
static void clip_top ( long  top)
static

Definition at line 556 of file polyclip.c.

559 {
560  struct pair *pa, *pp, *pfirst, *plast, *pnext;
561  struct plist *list, *end, *pointer;
562  long x, y, xnext, ynext;
563 
564  end = Newpoly;
565  for (list = Polybuf; list < end; list++) {
566  pointer = Newpoly;
567  pa = list->pl_pair;
568  /*
569  * First, find a vertex outside of the clipping
570  * region.
571  */
572 
573  for (pp = pa;;) {
574  if (pp->pa_y > top)
575  break;
576  pp = pp->pa_next;
577  if (pp == pa) {
578  /* no clipping needed */
579  Newpoly->pl_pair = pa;
580  newpoly();
581  goto next;
582  }
583  }
584  /* start with an "outside" point */
585 
586  for (pa = pp;;) {
587  x = pp->pa_x;
588  y = pp->pa_y;
589  pnext = pp->pa_next;
590  xnext = pnext->pa_x;
591  ynext = pnext->pa_y;
592 
593  if (ynext <= top && y > top) {
594  /* poly edge crosses bounding clip line */
595 #ifdef DO_FLOAT
596  x += (xnext - x)*(((double)(top - y))/(ynext - y));
597 #else
598  x += ((top - y) * (xnext - x))/(ynext - y);
599 #endif
600  y = top;
601 
602  if (x != xnext || y != ynext) {
603  pfirst = Newlink;
604  pfirst->pa_x = x;
605  pfirst->pa_y = y;
606  pfirst->pa_prev = NULL;
607  newlink();
608  pp = pnext;
609  pfirst->pa_next = pp;
610  pp->pa_prev = pfirst;
611  }
612  else {
613  pp = pnext;
614  pfirst = pnext;
615  pfirst->pa_prev = NULL;
616  }
617 
618  /* walk along inside points, find the last one */
619  for (;;) {
620  if (pp->pa_y > top) {
621  pnext = pp;
622  pp = pp->pa_prev;
623  break;
624  }
625  pp = pp->pa_next;
626  }
627  x = pp->pa_x;
628  y = pp->pa_y;
629  xnext = pnext->pa_x;
630  ynext = pnext->pa_y;
631 #ifdef DO_FLOAT
632  x += (xnext - x)*(((double)(top - y))/(ynext - y));
633 #else
634  x += ((top - y) * (xnext - x))/(ynext - y);
635 #endif
636  y = top;
637 
638  if (x != xnext || y != ynext) {
639  plast = Newlink;
640  plast->pa_x = x;
641  plast->pa_y = y;
642  pp->pa_next = plast;
643  plast->pa_prev = pp;
644  plast->pa_next = NULL;
645  newlink();
646  }
647  else {
648  plast = pp;
649  plast->pa_next = NULL;
650  }
651  if (pfirst->pa_next != plast) {
652 
653  /* note that we are saving poly fragments */
654  Newpoly->pl_pair = pfirst;
655  Newpoly->pl_start = pfirst;
656  newpoly();
657  Newpoly->pl_pair = plast;
658  Newpoly->pl_start = pfirst;
659  newpoly();
660  }
661  }
662  pp = pnext;
663  if (pp == pa)
664  break;
665  }
666  if (pointer < Newpoly)
667  linkpolys(pointer,'X');
668 next:
669  ;
670  }
671  for (list = end, end = Polybuf; list < Newpoly; list++) {
672  if (list->pl_pair) {
673  end->pl_pair = list->pl_pair;
674  end->pl_start = NULL;
675  end++;
676  }
677  }
678  Newpoly = end;
679 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static void linkpolys()
static struct plist * Polybuf
Definition: polyclip.c:37
Definition: objects.c:1183
struct pair * pa_prev
Definition: polyclip.c:28
static void newpoly()
Definition: polyclip.c:810
long pa_x
Definition: polyclip.c:26
struct pair * pl_start
Definition: polyclip.c:34
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
static void newlink()
Definition: polyclip.c:772
Definition: dir.c:53
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33
static void linkpolys ( )
static
static void linkpolys ( struct plist base,
int  XorY 
)
static

Definition at line 683 of file polyclip.c.

687 {
688  struct plist tmp, *b, *bb;
689 
690  if (XorY == 'X')
691  qsort(base,Newpoly-base,sizeof(struct plist),polycmpX);
692  else
693  qsort(base,Newpoly-base,sizeof(struct plist),polycmpY);
694 
695  for (b = base; b < Newpoly; b += 2) {
696  /* link adjacent vertices */
697  if (b->pl_pair == b->pl_start) {
698  if ((b+1)->pl_pair == (b+1)->pl_start) {
699  tmp = *(b+1);
700  *(b+1) = *(b+2);
701  *(b+2) = tmp;
702  }
703  b->pl_pair->pa_prev = (b+1)->pl_pair;
704  (b+1)->pl_pair->pa_next = b->pl_pair;
705  (b+1)->pl_pair = NULL;
706  if (b->pl_start != (b+1)->pl_start) {
707  for (bb = b+2; bb < Newpoly; bb++) {
708  if (bb->pl_start == b->pl_start) {
709  bb->pl_start = (b+1)->pl_start;
710  break;
711  }
712  }
713  b->pl_pair = NULL;
714  }
715  }
716  else {
717  if ((b+1)->pl_pair != (b+1)->pl_start) {
718  tmp = *(b+1);
719  *(b+1) = *(b+2);
720  *(b+2) = tmp;
721  }
722  b->pl_pair->pa_next = (b+1)->pl_pair;
723  (b+1)->pl_pair->pa_prev = b->pl_pair;
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) {
728  bb->pl_start = b->pl_start;
729  break;
730  }
731  }
732  b->pl_pair = NULL;
733  }
734  }
735  }
736 }
static struct plist * Newpoly
Definition: polyclip.c:38
static int polycmpY()
struct pair * pa_prev
Definition: polyclip.c:28
struct pair * pl_start
Definition: polyclip.c:34
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
qsort()
Definition: string.c:375
static int polycmpX()
struct pair * pl_pair
Definition: polyclip.c:33
static void newlink ( )
static

Definition at line 772 of file polyclip.c.

774 {
775  struct pair *oldbuf;
776  int i, num;
777 
778  if (Linkbuf == NULL) {
779  Linkbuf = (struct pair *)malloc(400*sizeof(struct pair));
780  if (Linkbuf == NULL)
781  MallocFailed();
782  Newlink = Linkbuf;
783  Numlinks = 400;
784  return;
785  }
786 
787  Newlink++;
788  num = Newlink - Linkbuf;
789  if (num > Numlinks) {
790  Numlinks = num + 200;
791  oldbuf = Linkbuf;
792  Linkbuf = (struct pair *)
793  realloc((char*)Linkbuf,Numlinks*sizeof(struct pair));
794  if (Linkbuf == NULL)
795  MallocFailed();
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;
800  }
801  num = Newpoly - Polybuf;
802  for (i = 0; i < num; i++) {
803  (Polybuf+i)->pl_pair = ((Polybuf+i)->pl_pair - oldbuf) + Linkbuf;
804  }
805  }
806 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static struct plist * Polybuf
Definition: polyclip.c:37
char * malloc()
struct pair * pa_prev
Definition: polyclip.c:28
void MallocFailed()
Definition: scedintr.c:857
struct pair * pa_next
Definition: polyclip.c:27
#define NULL
Definition: spdefs.h:121
static struct pair * Linkbuf
Definition: polyclip.c:42
static int Numlinks
Definition: polyclip.c:44
char * realloc()
Definition: polyclip.c:25
static void newpoly ( )
static

Definition at line 810 of file polyclip.c.

812 {
813  struct plist *pp;
814  int num;
815 
816  if (Polybuf == NULL) {
817  Polybuf = (struct plist *)malloc(100*sizeof(struct plist));
818  if (Polybuf == NULL)
819  MallocFailed();
820  Newpoly = Polybuf;
821  Numpolys = 100;
822  return;
823  }
824 
825  Newpoly++;
826  num = Newpoly - Polybuf;
827  if (num > Numpolys) {
828  Numpolys = num + 100;
829  Polybuf = (struct plist *)
830  realloc((char*)Polybuf,Numpolys*sizeof(struct plist));
831  if (Polybuf == NULL)
832  MallocFailed();
833  Newpoly = Polybuf + num;
834  }
835 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct plist * Polybuf
Definition: polyclip.c:37
Definition: objects.c:1183
char * malloc()
void MallocFailed()
Definition: scedintr.c:857
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
char * realloc()
static int Numpolys
Definition: polyclip.c:40
int NextPolygon ( POLYGON p)

Definition at line 135 of file polyclip.c.

138 {
139  long *xy;
140  int i;
141  struct pair *pp, *pa;
142 
143  for (;;) {
144  xy = (long*)p->xy;
145  i = 1;
146  if (Polycurrent == Newpoly) {
147  Newlink = Linkbuf;
148  Newpoly = Polybuf;
150  return (0);
151  }
152  pp = pa = Polycurrent->pl_pair;
153  if (pp) {
154  *xy++ = pp->pa_x;
155  *xy++ = pp->pa_y;
156 
157  for (pp = pp->pa_next; ; pp = pp->pa_next) {
158  i++;
159  *xy++ = pp->pa_x;
160  *xy++ = pp->pa_y;
161  if (pp == pa) break;
162  }
163  }
164 
165  Polycurrent++;
166  if (i >= 4)
167  break;
168  }
169  p->nvertices = i;
170  return (1);
171 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static struct plist * Polybuf
Definition: polyclip.c:37
long * xy
Definition: plotdev.h:16
Definition: objects.c:1183
if(TDesc==NULL)
Definition: cd.c:1326
int nvertices
Definition: plotdev.h:15
long pa_x
Definition: polyclip.c:26
struct pair * pa_next
Definition: polyclip.c:27
static struct pair * Linkbuf
Definition: polyclip.c:42
static struct plist * Polycurrent
Definition: polyclip.c:39
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33
static int polycmpX ( )
static
static int polycmpX ( char *  p1,
char *  p2 
)
static

Definition at line 740 of file polyclip.c.

747 {
748  return (((struct plist *)p1)->pl_pair->pa_x -
749  ((struct plist *)p2)->pl_pair->pa_x);
750 }
Definition: polyclip.c:32
static int polycmpY ( )
static
static int polycmpY ( char *  p1,
char *  p2 
)
static

Definition at line 754 of file polyclip.c.

761 {
762  return (((struct plist *)p1)->pl_pair->pa_y -
763  ((struct plist *)p2)->pl_pair->pa_y);
764 }
Definition: polyclip.c:32
void PolygonClip ( POLYGON poly,
long  left,
long  bottom,
long  right,
long  top 
)

Definition at line 71 of file polyclip.c.

75 {
76  struct plist *pl;
77  struct pair *pa;
78  int i, n;
79  long tmp;
80 
81  if (left > right) {
82  tmp = left;
83  left = right;
84  right = tmp;
85  }
86  if (bottom > top) {
87  tmp = bottom;
88  bottom = top;
89  top = tmp;
90  }
91 
92  if (Linkbuf == NULL)
93  newlink();
94  if (Polybuf == NULL)
95  newpoly();
96 
97  Newlink = Linkbuf;
98  Newpoly = Polybuf;
99 
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];
104  Newlink->pa_prev = Newlink-1;
105  Newlink->pa_next = Newlink+1;
106  newlink();
107  }
108  pa = Linkbuf;
109 
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];
113  Newlink->pa_prev = Newlink-1;
114  Newlink->pa_next = Newlink+1;
115  newlink();
116  }
117  Newlink--;
118  Newlink->pa_next = pa;
119  pa->pa_prev = Newlink;
120  Newlink++;
121 
122  Newpoly->pl_pair = pa;
123  newpoly();
124 
125  clip_left(left);
126  clip_bottom(bottom);
127  clip_right(right);
128  clip_top(top);
129 
131 }
static struct plist * Newpoly
Definition: polyclip.c:38
static struct pair * Newlink
Definition: polyclip.c:43
static void clip_top()
static void clip_bottom()
static struct plist * Polybuf
Definition: polyclip.c:37
long * xy
Definition: plotdev.h:16
static void clip_left()
struct pair * pa_prev
Definition: polyclip.c:28
static void newpoly()
Definition: polyclip.c:810
int nvertices
Definition: plotdev.h:15
long pa_x
Definition: polyclip.c:26
struct pair * pa_next
Definition: polyclip.c:27
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
static void newlink()
Definition: polyclip.c:772
static struct pair * Linkbuf
Definition: polyclip.c:42
static struct plist * Polycurrent
Definition: polyclip.c:39
static void clip_right()
Definition: polyclip.c:25
long pa_y
Definition: polyclip.c:26
struct pair * pl_pair
Definition: polyclip.c:33

Variable Documentation

struct pair* Linkbuf
static

Definition at line 42 of file polyclip.c.

struct pair* Newlink
static

Definition at line 43 of file polyclip.c.

struct plist* Newpoly
static

Definition at line 38 of file polyclip.c.

int Numlinks
static

Definition at line 44 of file polyclip.c.

int Numpolys
static

Definition at line 40 of file polyclip.c.

struct plist* Polybuf
static

Definition at line 37 of file polyclip.c.

struct plist* Polycurrent
static

Definition at line 39 of file polyclip.c.