Debian Codegraph @

t/t11.t

raw symbols SCIP
1 use strictscip-perl cpan PGPLOT 2.36 strict/; use warningsscip-perl cpan PGPLOT 2.36 warnings/;
2 use Test::Morescip-perl cpan PGPLOT 2.36 Test/More/;
3 use Configscip-perl cpan PGPLOT 2.36 Config/;
4 # Stop f77-linking causing spurious undefined symbols (alpha)
5 $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{'PERL_DL_NONLAZY'}=0 if $Configscip-perl cpan PGPLOT 2.36 main/`%Config`.{'osname'} eq "dec_osf";
6 requirescip-perl cpan PGPLOT 2.36 main/require(). PGPLOT;
7
8 my $dev = $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_DEV} || '/NULL';
9
10 $ENVscip-perl cpan PGPLOT 2.36 main/`%ENV`.{PGPLOT_XW_WIDTH}=0.3;
11
12 notescip-perl cpan PGPLOT 2.36 main/note(). "Testing Object-Oriented stuff";
13
14 PGPLOT::pgbeginscip-perl cpan PGPLOT 2.36 PGPLOT/pgbegin().(9,$dev,1,1); PGPLOT::pgwnadscip-perl cpan PGPLOT 2.36 PGPLOT/pgwnad().(-100,100,-100,100);
15 PGPLOT::pgpagescip-perl cpan PGPLOT 2.36 PGPLOT/pgpage().(); PGPLOT::pgboxscip-perl cpan PGPLOT 2.36 PGPLOT/pgbox().('BC',0,0,'BC',0,0);
16
17 # Define some object classes
18
19 ##############################################################
20
21 package Squarescip-perl cpan PGPLOT 2.36 Square/;
22
23 # Create a new Square - colour is first argument
24
25 sub newscip-perl cpan PGPLOT 2.36 Square/new(). {
26 my $type = shiftscip-perl cpan PGPLOT 2.36 Square/shift().; # Ignore as we know we are a Square;
27 my $self = {}; # $self is ref to anonymous hash
28 my $colour = shiftscip-perl cpan PGPLOT 2.36 Square/shift().;
29 $colour = 2 unless definedscip-perl cpan PGPLOT 2.36 Square/defined().($colour); # Default is red
30 $self->{'Colour'}=$colour;
31 $self->{'Xvertices'} = [-10, 10, 10,-10, -10]; # Initialise as square
32 $self->{'Yvertices'} = [-10,-10, 10, 10, -10];
33 blessscip-perl cpan PGPLOT 2.36 Square/bless(). $self;
34 }
35
36 # Method to plot a Square object at $x,$y
37
38 sub plotscip-perl cpan PGPLOT 2.36 Square/plot(). {
39 my $self = shiftscip-perl cpan PGPLOT 2.36 Square/shift().;
40 my($x,$y) = @_scip-perl cpan PGPLOT 2.36 Square/`@_`.;
41 my(@xpts) = @{$self->{'Xvertices'}};
42 my(@ypts) = @{$self->{'Yvertices'}};
43
44 for (@xpts) { $_scip-perl cpan PGPLOT 2.36 Square/$_. = $_scip-perl cpan PGPLOT 2.36 Square/$_. + $x }
45 for (@ypts) { $_scip-perl cpan PGPLOT 2.36 Square/$_. = $_scip-perl cpan PGPLOT 2.36 Square/$_. + $y }
46
47 PGPLOT::pgsciscip-perl cpan PGPLOT 2.36 PGPLOT/pgsci().($self->{'Colour'}); PGPLOT::pgpolyscip-perl cpan PGPLOT 2.36 PGPLOT/pgpoly().(scalarscip-perl cpan PGPLOT 2.36 Square/scalar().(@xpts), \@xpts, \@ypts);
48 PGPLOT::pgsciscip-perl cpan PGPLOT 2.36 PGPLOT/pgsci().(1); PGPLOT::pglinescip-perl cpan PGPLOT 2.36 PGPLOT/pgline().(scalarscip-perl cpan PGPLOT 2.36 Square/scalar().(@xpts), \@xpts, \@ypts);
49 }
50
51 # Method to expand a Square object
52
53 sub expandscip-perl cpan PGPLOT 2.36 Square/expand(). {
54 my $self = shiftscip-perl cpan PGPLOT 2.36 Square/shift().;
55 my $fac = shiftscip-perl cpan PGPLOT 2.36 Square/shift().;
56 my $xpts = $self->{'Xvertices'};
57 my $ypts = $self->{'Yvertices'};
58
59 for (@$xpts) { $_scip-perl cpan PGPLOT 2.36 Square/$_. = $_scip-perl cpan PGPLOT 2.36 Square/$_. * $fac }
60 for (@$ypts) { $_scip-perl cpan PGPLOT 2.36 Square/$_. = $_scip-perl cpan PGPLOT 2.36 Square/$_. * $fac }
61 }
62
63 # Method to rotate a Square object
64
65 sub rotatescip-perl cpan PGPLOT 2.36 Square/rotate(). {
66 my $self = shiftscip-perl cpan PGPLOT 2.36 Square/shift().;
67 my $angle = (shiftscip-perl cpan PGPLOT 2.36 Square/shift().)*(3.141592564/180);
68 my $x = $self->{'Xvertices'};
69 my $y = $self->{'Yvertices'};
70 my ($x2,$y2);
71
72 for(my $i=0; $i<=$#{$x}; $i++) {
73 $x2 = $$x[$i]*cosscip-perl cpan PGPLOT 2.36 Square/cos().($angle) + $$y[$i]*sinscip-perl cpan PGPLOT 2.36 Square/sin().($angle);
74 $y2 = -$$x[$i]*sinscip-perl cpan PGPLOT 2.36 Square/sin().($angle) + $$y[$i]*cosscip-perl cpan PGPLOT 2.36 Square/cos().($angle);
75 $$x[$i] = $x2; $$y[$i] = $y2;
76 }
77 }
78
79
80 ##############################################################
81
82 package Trianglescip-perl cpan PGPLOT 2.36 Triangle/;
83
84 # Only difference is "new" method. Otherwise inherit
85 # all other properties from "Square";
86
87 our @ISAscip-perl cpan PGPLOT 2.36 Triangle/`@ISA`. = qw( Square );
88
89 # Create a new Triangle
90
91 sub newscip-perl cpan PGPLOT 2.36 Triangle/new(). {
92 my $type = shiftscip-perl cpan PGPLOT 2.36 Triangle/shift().; # Ignore as we know we are a Square;
93 my $self = {}; # $self is ref to anonymous hash
94 my $colour = shiftscip-perl cpan PGPLOT 2.36 Triangle/shift().;
95 $colour = 3 unless definedscip-perl cpan PGPLOT 2.36 Triangle/defined().($colour); # Default is green
96 $self->{'Colour'}=$colour;
97 $self->{'Xvertices'} = [-10, 10, 0, -10]; # Initialise as square
98 $self->{'Yvertices'} = [-10,-10, 5, -10];
99 blessscip-perl cpan PGPLOT 2.36 Triangle/bless(). $self;
100 }
101
102 ##############################################################
103
104 # Now let's use these objects
105
106 package mainscip-perl cpan PGPLOT 2.36 main/;
107
108 notescip-perl cpan PGPLOT 2.36 main/note(). "Testing Square Objects...";
109
110 my $shape1 = new Square;
111
112 # Plot first shape at 50,50;
113
114 notescip-perl cpan PGPLOT 2.36 main/note(). "Square plot method...";
115
116 $shape1->plotscip-perl cpan PGPLOT 2.36 main/plot().(50,50);
117
118 notescip-perl cpan PGPLOT 2.36 main/note(). "Square expand and rotate methods...";
119
120 $shape1->expandscip-perl cpan PGPLOT 2.36 main/expand().(2.3); # Make the shape bigger
121 $shape1->rotatescip-perl cpan PGPLOT 2.36 main/rotate().(20); # Rotate the shape bigger
122
123 $shape1->plotscip-perl cpan PGPLOT 2.36 main/plot().(-20,-50);
124
125 notescip-perl cpan PGPLOT 2.36 main/note(). "Inheriting Square methods in Triangles...";
126
127 my $shape2 = new Triangle;
128
129 $shape2->plotscip-perl cpan PGPLOT 2.36 main/plot().(-20,50);
130
131 my $shape3 = new Triangle(4); # Blue triangle
132 $shape3->rotatescip-perl cpan PGPLOT 2.36 main/rotate().(-15); $shape3->expandscip-perl cpan PGPLOT 2.36 main/expand().(1.5);
133
134 $shape3->plotscip-perl cpan PGPLOT 2.36 main/plot().(50,-50);
135
136 PGPLOT::pgendscip-perl cpan PGPLOT 2.36 PGPLOT/pgend().();
137
138 pass;
139 done_testing;