lib/PDL/Image2D/misc.c

filter: Statementstmt 67.3% 35 / 52 Branchbran 62.5% 35 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 64.8% 70 / 108 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/PDL/Primitive-pp-approx_artol.c ↑ Summary lib/PDL/Math-pp-csqrt.c »
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 ▶ if (i==j)
Branch: 1 branch
BranchTrueFalseTotal
if (i==j) 2 0 2
7 2 return;
8 0 k = j;
9 do {
10 0 k = equiv[k];
11 0 ▶ } while ( k != j && k != i );
Branch: 2 branches
BranchTrueFalseTotal
} while ( k != j && k != i ); 0 0 0
} while ( k != j && k != i ); 0 0 0
12 0 ▶ if ( k == j ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( k == j ) { 0 0 0
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 ▶ for (i=1; i<n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=1; i<n; i++) { 4 2 6
38 4 ▶ ymin = PDLMIN(ymin, PY(i));
Branch: 1 branch
BranchTrueFalseTotal
ymin = PDLMIN(ymin, PY(i)); 4 0 4
39 4 ▶ ymax = PDLMAX(ymax, PY(i));
Branch: 1 branch
BranchTrueFalseTotal
ymax = PDLMAX(ymax, PY(i)); 0 4 4
40 4 ▶ xmin = PDLMIN(xmin, PX(i));
Branch: 1 branch
BranchTrueFalseTotal
xmin = PDLMIN(xmin, PX(i)); 4 0 4
41 4 ▶ xmax = PDLMAX(xmax, PX(i));
Branch: 1 branch
BranchTrueFalseTotal
xmax = PDLMAX(xmax, PX(i)); 2 2 4
42 }
43 2 ▶ if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) {
Branch: 4 branches
BranchTrueFalseTotal
if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) { 2 0 2
if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) { 2 0 2
if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) { 2 0 2
if (xmin < 0 || xmax >= wx || ymin < 0 || ymax >= wy) { 0 2 2
44 0 *ierr = 1; /* clipping */
45 0 return;
46 }
47 2 s1 = PX(n-1);
48 2 t1 = PY(n-1);
49 12 ▶ for (l=ymin; l<= ymax; l++) {
Branch: 1 branch
BranchTrueFalseTotal
for (l=ymin; l<= ymax; l++) { 10 2 12
50 10 nsect = 0;
51 10 fwrd = 1;
52 40 ▶ for (i=0; i<n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<n; i++) { 30 10 40
53 30 s2 = PX(i);
54 30 t2 = PY(i);
55 30 ▶ if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) {
Branch: 4 branches
BranchTrueFalseTotal
if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) { 14 16 30
if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) { 6 8 14
if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) { 16 6 22
if ((t1 < l && l <= t2) || (t1 >= l && l > t2)) { 8 8 16
56 16 ▶ if (nsect > MAXSEC) {
Branch: 1 branch
BranchTrueFalseTotal
if (nsect > MAXSEC) { 0 16 16
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 ▶ for (i=1; i<nsect; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=1; i<nsect; i++) 8 10 18
68 16 ▶ for (j=0; j<i; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<i; j++) 8 8 16
69 8 ▶ if (x[j] > x[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (x[j] > x[i]) { 0 8 8
70 0 temp = x[j];
71 0 x[j] = x[i];
72 0 x[i] = temp;
73 }
74 10 ▶ if (fwrd) {
Branch: 1 branch
BranchTrueFalseTotal
if (fwrd) { 10 0 10
75 18 ▶ for (i=0; i<nsect-1; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<nsect-1; i += 2) 8 10 18
76 28 ▶ line(x[i],x[i+1],l);
Branch: 1 branch
BranchTrueFalseTotal
line(x[i],x[i+1],l); 20 8 28
77 10 fwrd = 0;
78 } else {
79 0 ▶ for (i=nsect-1; i>0; i -= 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i=nsect-1; i>0; i -= 2) 0 0 0
80 0 ▶ line(x[i-1],x[i],l);
Branch: 1 branch
BranchTrueFalseTotal
line(x[i-1],x[i],l); 0 0 0
81 0 fwrd = 1;
82 }
83 }
84 }
« lib/PDL/Primitive-pp-approx_artol.c ↑ Summary lib/PDL/Math-pp-csqrt.c »