1 //      Filling and clipping polygons.
2 //
3 
4 import plplot;
5 import std.string;
6 
7 
8 //--------------------------------------------------------------------------
9 // main
10 //
11 // Test program for filling polygons and proper clipping
12 //--------------------------------------------------------------------------
13 
main(char[][]args)14 int main( char[][] args )
15 {
16     // Parse and process command line arguments
17     plparseopts( args, PL_PARSE_FULL );
18 
19     // Initialize plplot
20     plssub( 3, 3 );
21     plinit();
22 
23     static PLFLT[2][9] xextreme = [ [-120.0, 120.0],
24                                     [-120.0, 120.0],
25                                     [-120.0, 120.0],
26                                     [ -80.0, 80.0],
27                                     [-220.0, -120.0],
28                                     [ -20.0, 20.0],
29                                     [ -20.0, 20.0],
30                                     [ -80.0, 80.0],
31                                     [  20.0, 120.0] ];
32 
33     static PLFLT[2][9] yextreme = [ [-120.0, 120.0],
34                                     [  20.0, 120.0],
35                                     [ -20.0, 120.0],
36                                     [ -20.0, 120.0],
37                                     [-120.0, 120.0],
38                                     [-120.0, 120.0],
39                                     [ -20.0, 20.0],
40                                     [ -80.0, 80.0],
41                                     [-120.0, 120.0] ];
42 
43     PLFLT[] x0, y0;
44     for ( int k = 0; k < 2; k++ )
45     {
46         for ( int j = 0; j < 4; j++ )
47         {
48             switch ( j )
49             {
50             case 0:
51                 x0.length = 4;
52                 y0.length = 4;
53                 // Polygon 1: a diamond
54                 x0[] = [   0.0, -100.0, 0.0, 100.0 ];
55                 y0[] = [-100.0, 0.0, 100.0, 0.0 ];
56                 break;
57             case 1:
58                 // Polygon 1: a diamond - reverse direction
59                 x0[] = [ 100.0, 0.0, -100.0, 0.0 ];
60                 y0[] = [   0.0, 100.0, 0.0, -100.0 ];
61                 break;
62             case 2:
63                 // Polygon 2: a square with punctures
64                 x0.length = 10;
65                 y0.length = 10;
66                 x0[]      = [ -100.0, -100.0, 80.0, -100.0, -100.0, -80.0, 0.0, 80.0, 100.0, 100.0 ];
67                 y0[]      = [ -100.0, -80.0, 0.0, 80.0, 100.0, 100.0, 80.0, 100.0, 100.0, -100.0 ];
68                 break;
69             case 3:
70                 // Polygon 2: a square with punctures - reversed direction
71                 x0[] = [  100.0, 100.0, 80.0, 0.0, -80.0, -100.0, -100.0, 80.0, -100.0, -100.0 ];
72                 y0[] = [ -100.0, 100.0, 100.0, 80.0, 100.0, 100.0, 80.0, 0.0, -80.0, -100.0 ];
73                 break;
74             default:
75                 break;
76             }
77 
78             for ( int i = 0; i < 9; i++ )
79             {
80                 pladv( 0 );
81                 plvsta();
82                 plwind( xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1] );
83 
84                 plcol0( 2 );
85                 plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 );
86                 plcol0( 1 );
87                 plpsty( 0 );
88                 if ( k == 0 )
89                     plfill( x0, y0 );
90                 else
91                     plgradient( x0, y0, 45. );
92                 plcol0( 2 );
93                 pllsty( 1 );
94                 plline( x0, y0 );
95             }
96         }
97     }
98 
99     // Don't forget to call plend() to finish off!
100     plend();
101     return 0;
102 }
103