FigAnim/Ellipse.pm

filter: Statementstmt 7.1% 10 / 140 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 17.6% 3 / 17 Podpod n/a totaltotal 5.8% 13 / 224 CC 27 SCAR 41.1
CC
27
Cov
5%
outputSVG
182.0
rotate
20.0
output
12.0
CRAP 61.0
« FigAnim/Text.pm ↑ Summary FigAnim/ConvertSMIL.pm »
1 package Ellipse;
2  
3 =head1 NAME
4  
5 Ellipse - A XFig file animator class - Ellipse object
6  
7 =head1 DESCRIPTION
8  
9 Ellipse object - object code in FIG format: 1.
10 Here are all the attributes of this class:
11  
12 B<sub_type, line_style, thickness, pen_color, fill_color, depth, pen_style,
13 area_fill, style_val, direction, angle, center_x, center_y, radius_x, radius_y,
14 start_x, start_y, end_x, end_y>
15  
16 =head1 FIG ATTRIBUTES
17  
18 =over
19  
20 =item sub_type
21  
22 1: ellipse defined by radii;
23 2: ellipse defined by diameters;
24 3: circle defined by radius;
25 4: circle defined by diameter.
26  
27 =item line_style
28  
29 -1: Default;
30 0: Solid;
31 1: Dashed;
32 2: Dotted;
33 3: Dash-dotted;
34 4: Dash-double-dotted;
35 5: Dash-triple-dotted.
36  
37 =item thickness
38  
39 80-ths of an inch ("display units")
40  
41 =item pen_color
42  
43 -1..31: FIG colors;
44 32..543 (512 total): user colors.
45  
46 =item fill_color
47  
48 -1..31: FIG colors;
49 32..543 (512 total): user colors.
50  
51 =item depth
52  
53 0 ... 999: larger value means object is deeper than (under)
54 objects with smaller depth
55  
56 =item pen_style
57  
58 unused
59  
60 =item area_fill
61  
62 fill type
63  
64 =item style_val
65  
66 length, in 1/80 inches, of the on/off
67 dashes for dashed lines, and the distance between the dots, in 1/80 inches,
68 for dotted lines
69  
70 =item direction
71  
72 always 1
73  
74 =item angle
75  
76 radians, the angle of the x-axis
77  
78 =item center_x, center_y
79  
80 Fig units
81  
82 =item radius_x, radius_y
83  
84 Fig units
85  
86 =item start_x, start_y
87  
88 Fig units; the 1st point entered
89  
90 =item end_x, end_y
91  
92 Fig units; the last point entered
93  
94 =back
95  
96 =head1 ADDITONNAL ATTRIBUTES
97  
98 =over
99  
100 =item visibility
101  
102 0: hidden;
103 1: shown
104  
105 =back
106  
107 =cut
108  
109 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 # useful classes
113 1 ▶use FigAnim::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 # constructor
116 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
117 0 my $proto = shift;
118 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
119 0 my $self = {};
120
121 0 $self->{name} = shift; # object's name in comment
122
123 #$self->{object_code} = 1;
124 0 $self->{sub_type} = shift;
125 0 $self->{line_style} = shift;
126 0 $self->{thickness} = shift;
127 0 $self->{pen_color} = shift;
128 0 $self->{fill_color} = shift;
129 0 $self->{depth} = shift;
130 0 $self->{pen_style} = shift;
131 0 $self->{area_fill} = shift;
132 0 $self->{style_val} = shift;
133 0 $self->{direction} = shift;
134 0 $self->{angle} = shift;
135 0 $self->{center_x} = shift;
136 0 $self->{center_y} = shift;
137 0 $self->{radius_x} = shift;
138 0 $self->{radius_y} = shift;
139 0 $self->{start_x} = shift;
140 0 $self->{start_y} = shift;
141 0 $self->{end_x} = shift;
142 0 $self->{end_y} = shift;
143
144 # reference to the FigFile
145 0 $self->{fig_file} = shift;
146
147 # object's visibility : 0=hidden 1=shown
148 0 $self->{visibility} = 1;
149  
150 # animations
151 0 $self->{animations} = [];
152  
153 0 bless ($self, $class);
154 0 return $self;
155 }
156  
157  
158 # methods
159 0 ▶sub clone {
Subroutine clone: not called CC=2 SCAR=17.9
160 0 my $self = shift;
161 0 my $obj = new Ellipse;
162 0 $obj->{$_} = $self->{$_} foreach (keys %{$self});
163 0 return $obj;
164 }
165  
166 0 ▶sub output {
Subroutine output: not called CC=3 SCAR=24.8
167 0 my $self = shift;
168 0 ▶ return if ($self->{visibility} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"visibility"} == 0 0 0 0
169
170 0 my $fh = shift;
171
172 0 foreach (split(/\n/, $self->{name})) {
173 0 printf $fh "# $_\n";
174 }
175
176 printf $fh
177 "1 %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
178 0 @$self{'sub_type','line_style','thickness','pen_color','fill_color',
179 'depth','pen_style','area_fill','style_val','direction','angle',
180 'center_x','center_y','radius_x','radius_y','start_x','start_y',
181 'end_x','end_y'};
182 }
183  
184  
185 # animation methods
186 0 ▶sub setAttributeValue {
Subroutine setAttributeValue: not called CC=1 SCAR=6.9
187 0 my $self = shift;
188 0 my @anim = (0, $self->{name}, shift, 0, shift, shift);
189 0 push @{$self->{fig_file}->{animations}}, \@anim;
190 }
191  
192 0 ▶sub setPenColor {
Subroutine setPenColor: not called CC=2 SCAR=17.9
193 0 my $self = shift;
194 0 my $time = shift;
195 0 my $color = $FigAnim::Utils::colors_codes{shift};
196 0 ▶ if (defined $color) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $color) 0 0 0
197 0 my @anim = (0, $self->{name}, $time, 0, 'pen_color', $color);
198 0 push @{$self->{fig_file}->{animations}}, \@anim;
199 }
200 }
201  
202 0 ▶sub setFillColor {
Subroutine setFillColor: not called CC=2 SCAR=17.9
203 0 my $self = shift;
204 0 my $time = shift;
205 0 my $color = $FigAnim::Utils::colors_codes{shift};
206 0 ▶ if (defined $color) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $color) 0 0 0
207 0 my @anim = (0, $self->{name}, $time, 0, 'fill_color', $color);
208 0 push @{$self->{fig_file}->{animations}}, \@anim;
209 }
210 }
211  
212 0 ▶sub hide {
Subroutine hide: not called CC=1 SCAR=6.9
213 0 my $self = shift;
214 0 my @anim = (0, $self->{name}, shift, 0, 'visibility', 0);
215 0 push @{$self->{fig_file}->{animations}}, \@anim;
216 }
217  
218 0 ▶sub show {
Subroutine show: not called CC=1 SCAR=6.9
219 0 my $self = shift;
220 0 my @anim = (0, $self->{name}, shift, 0, 'visibility', 1);
221 0 push @{$self->{fig_file}->{animations}}, \@anim;
222 }
223  
224 0 ▶sub changeThickness {
Subroutine changeThickness: not called CC=1 SCAR=6.9
225 0 my $self = shift;
226 0 my @anim = (1, $self->{name}, shift, shift, int shift);
227 0 push @{$self->{fig_file}->{animations}}, \@anim;
228 }
229  
230 0 ▶sub changeFillIntensity {
Subroutine changeFillIntensity: not called CC=3 SCAR=24.8
231 0 my $self = shift;
232 0 my @anim = (2, $self->{name}, shift, shift, int shift);
233 0 ▶ $anim[4] = 0 if ($anim[4] < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $anim[4] < 0 0 0 0
234 0 ▶ $anim[4] = 20 if ($anim[4] > 20);
Branch: 1 branch
BranchTrueFalseTotal
if $anim[4] > 20 0 0 0
235 0 push @{$self->{fig_file}->{animations}}, \@anim;
236 }
237  
238 0 ▶sub translate {
Subroutine translate: not called CC=2 SCAR=17.9
239 0 my $self = shift;
240 0 my @anim = (11, $self->{name}, shift, shift, shift, shift, shift);
241 0 ▶ $anim[6] = '' if (!(defined $anim[6]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $anim[6] 0 0 0
242 0 push @{$self->{fig_file}->{animations}}, \@anim;
243 }
244  
245 0 ▶sub rotate {
Subroutine rotate: not called CC=4 SCAR=30.0
246 0 my $self = shift;
247 0 my @anim = (21, $self->{name}, shift, shift, shift, shift, shift, shift);
248 0 ▶ if (!((defined $anim[5]) && (defined $anim[6]))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $anim[5] and defined $anim[6]) 0 0 0
Condition0%0/3
defined $anim[5] and defined $anim[6]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $anim[5] and defined $anim[6]
defined $anim[5] defined $anim[6]
Truth table0%0/3
A and B
A= defined $anim[5]B= defined $anim[6]
ABresult
0X0
100
111
249 0 $anim[5] = $self->{center_x};
250 0 $anim[6] = $self->{center_y};
251 }
252 0 ▶ $anim[7] = '' if (!(defined $anim[7]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $anim[7] 0 0 0
253 0 push @{$self->{fig_file}->{animations}}, \@anim;
254 }
255  
256 0 ▶sub scale {
Subroutine scale: not called CC=3 SCAR=24.8
257 0 my $self = shift;
258 0 my @anim = (31, $self->{name}, shift, shift, shift, shift, shift);
259 0 ▶ if (!((defined $anim[5]) && (defined $anim[6]))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $anim[5] and defined $anim[6]) 0 0 0
Condition0%0/3
defined $anim[5] and defined $anim[6]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $anim[5] and defined $anim[6]
defined $anim[5] defined $anim[6]
Truth table0%0/3
A and B
A= defined $anim[5]B= defined $anim[6]
ABresult
0X0
100
111
260 0 $anim[5] = $self->{center_x};
261 0 $anim[6] = $self->{center_y};
262 }
263 0 push @{$self->{fig_file}->{animations}}, \@anim;
264 }
265  
266  
267 # outputs a SVG element
268 0 ▶sub outputSVG {
Subroutine outputSVG: not called CC=13 SCAR=52.0
269 0 my $self = shift;
270 0 my $fh = shift;
271  
272 0 my ($colors) = @_;
273
274 0 foreach (split(/\n/, $self->{name})) {
275 0 print $fh "<!-- $_ -->\n";
276 }
277  
278 # converts values in SVG-CSS
279  
280 0 my $style = "style=\"";
281  
282 # line_style, style_val, pen_color
283 $style .= ConvertSVG::line_style_to_stroke($self->{line_style},
284 $self->{style_val},
285 $self->{pen_color},
286 0 $colors) . "; ";
287  
288 # thickness
289 0 $style .= ConvertSVG::thickness_to_stroke($self->{thickness}) . "; ";
290  
291 # fill_color, area_fill
292 $style .= ConvertSVG::area_fill_to_fill($self->{area_fill},
293 $self->{fill_color},
294 0 $colors);
295  
296 # end of style
297 0 $style .= "\"";
298  
299 # direction
300  
301 # angle
302  
303 # center_x
304 0 my $cx = "cx=\"" . $self->{center_x} . "\"";
305  
306 # center_y
307 0 my $cy = "cy=\"" . $self->{center_y} . "\"";
308  
309 0 ▶ if (($self->{'sub_type'} == 1) ||
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'sub_type'} == 1 or $self->{'sub_type'} == 2) { } 0 0 0
elsif ($self->{'sub_type'} == 3 or $self->{'sub_type'} == 4) { } 0 0 0
Condition0%0/3
$self->{"sub_type"} == 1 or $self->{"sub_type"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sub_type"} == 1 or $self->{"sub_type"} == 2
$self->{"sub_type"} == 1 $self->{"sub_type"} == 2
Truth table0%0/3
A or B
A= $self->{"sub_type"} == 1B= $self->{"sub_type"} == 2
ABresult
1X1
011
000
310 ($self->{'sub_type'} == 2)) { # ellipse
311  
312 # radius_x
313 0 my $rx = "rx=\"" . $self->{radius_x} . "\"";
314  
315 # radius_y
316 0 my $ry = "ry=\"" . $self->{radius_y} . "\"";
317  
318 # angle
319 0 my $angle = ConvertSVG::rad_to_deg($self->{angle});
320 0 my $transform = "";
321 0 ▶ if ($angle != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($angle != 0) 0 0 0
322 $transform =
323 "transform=\"rotate($angle, " .
324 $self->{center_x} . ", " .
325 $self->{center_y} .
326 0 ")\"";
327 }
328  
329 0 print $fh "<ellipse $cx $cy $rx $ry $style $transform";
330  
331 ▶ } elsif (($self->{'sub_type'} == 3) ||
Condition0%0/3
$self->{"sub_type"} == 3 or $self->{"sub_type"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sub_type"} == 3 or $self->{"sub_type"} == 4
$self->{"sub_type"} == 3 $self->{"sub_type"} == 4
Truth table0%0/3
A or B
A= $self->{"sub_type"} == 3B= $self->{"sub_type"} == 4
ABresult
1X1
011
000
332 ($self->{'sub_type'} == 4)) { # circle
333  
334 # radius
335 0 my $r = "r=\"" . $self->{radius_x} . "\"";;
336  
337 0 print $fh "<circle $cx $cy $r $style";
338 }
339  
340 0 ▶ if ($#{$self->{animations}} >= 0) { # SVG + SMIL
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{'animations'};} >= 0) { } 0 0 0
341 0 print $fh ">\n";
342 0 ▶ for (my $i = 0; $i <= $#{$self->{animations}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"animations"};}) 0 0 0
343 0 print $fh "\t";
344 0 my $smil = ConvertSMIL::smil($self->{animations}[$i]);
345 0 print $fh $smil;
346 0 print $fh "\n";
347 }
348  
349 0 ▶ if (($self->{'sub_type'} == 1) ||
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'sub_type'} == 1 or $self->{'sub_type'} == 2) { } 0 0 0
elsif ($self->{'sub_type'} == 3 or $self->{'sub_type'} == 4) { } 0 0 0
Condition0%0/3
$self->{"sub_type"} == 1 or $self->{"sub_type"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sub_type"} == 1 or $self->{"sub_type"} == 2
$self->{"sub_type"} == 1 $self->{"sub_type"} == 2
Truth table0%0/3
A or B
A= $self->{"sub_type"} == 1B= $self->{"sub_type"} == 2
ABresult
1X1
011
000
350 ($self->{'sub_type'} == 2)) { # ellipse
351 0 print $fh "</ellipse>\n\n";
352 ▶ } elsif (($self->{'sub_type'} == 3) ||
Condition0%0/3
$self->{"sub_type"} == 3 or $self->{"sub_type"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sub_type"} == 3 or $self->{"sub_type"} == 4
$self->{"sub_type"} == 3 $self->{"sub_type"} == 4
Truth table0%0/3
A or B
A= $self->{"sub_type"} == 3B= $self->{"sub_type"} == 4
ABresult
1X1
011
000
353 ($self->{'sub_type'} == 4)) { # circle
354 0 print $fh "</circle>\n\n";
355 }
356  
357 } else { # SVG only
358 0 print $fh " />\n\n";
359 }
360  
361 }
362  
363  
364  
365 1 1;
« FigAnim/Text.pm ↑ Summary FigAnim/ConvertSMIL.pm »