File Coverage

lib/PDL/Image2D/misc.c
Criterion Covered Total %
statement 35 52 67.3
branch 35 56 62.5
condition n/a
subroutine n/a
pod n/a
total 70 108 64.8


line stmt bran cond sub pod time code
1             #include "pdl.h"
2              
3             /* Add an equivalence to a list - used by pdl_ccNcompt */
4 2           void AddEquiv ( PDL_Long* equiv, PDL_Long i, PDL_Long j) {
5             PDL_Long k, tmp;
6 2 50         if (i==j)
7 2           return;
8 0           k = j;
9             do {
10 0           k = equiv[k];
11 0 0         } while ( k != j && k != i );
    0          
12 0 0         if ( k == j ) {
13 0           tmp = equiv[i];
14 0           equiv[i] = equiv[j];
15 0           equiv[j] = tmp;
16             }
17             }
18              
19             #define MAXSEC 32
20             #define line(x1, x2, y) for (k=x1;k<=x2;k++) \
21             { /* printf("line from %d to %d\n",x1,x2); */ \
22             image[k+wx*y] = col; }
23             #define PX(n) ps[2*n]
24             #define PY(n) ps[2*n+1]
25              
26 2           void polyfill(PDL_Long *image, int wx, int wy, float *ps, int n,
27             PDL_Long col, int *ierr)
28             {
29 2           int ymin, ymax, xmin, xmax, fwrd = 1, i, j, k, nsect;
30             int x[MAXSEC], temp, l;
31             float s1, s2, t1, t2;
32              
33 2           ymin = PY(0); ymax = PY(0);
34 2           xmin = PX(0); xmax = PX(0);
35 2           *ierr = 0;
36              
37 6 100         for (i=1; i
38 4 50         ymin = PDLMIN(ymin, PY(i));
39 4 50         ymax = PDLMAX(ymax, PY(i));
40 4 50         xmin = PDLMIN(xmin, PX(i));
41 4 100         xmax = PDLMAX(xmax, PX(i));
42             }
43 2 50         if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) {
    50          
    50          
    50          
44 0           *ierr = 1; /* clipping */
45 0           return;
46             }
47 2           s1 = PX(n-1);
48 2           t1 = PY(n-1);
49 12 100         for (l=ymin; l<= ymax; l++) {
50 10           nsect = 0;
51 10           fwrd = 1;
52 40 100         for (i=0; i
53 30           s2 = PX(i);
54 30           t2 = PY(i);
55 30 100         if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) {
    100          
    100          
    100          
56 16 50         if (nsect > MAXSEC) {
57 0           *ierr = 2; /* too complex */
58 0           return;
59             }
60 16           x[nsect] = (s1+(s2-s1)*((l-t1)/(t2-t1)));
61 16           nsect += 1;
62             }
63 30           s1 = s2;
64 30           t1 = t2;
65             }
66             /* sort the intersections */
67 18 100         for (i=1; i
68 16 100         for (j=0; j
69 8 50         if (x[j] > x[i]) {
70 0           temp = x[j];
71 0           x[j] = x[i];
72 0           x[i] = temp;
73             }
74 10 50         if (fwrd) {
75 18 100         for (i=0; i
76 28 100         line(x[i],x[i+1],l);
77 10           fwrd = 0;
78             } else {
79 0 0         for (i=nsect-1; i>0; i -= 2)
80 0 0         line(x[i-1],x[i],l);
81 0           fwrd = 1;
82             }
83             }
84             }