CIGIPP/WaveControl.pm

filter: Statementstmt 70.4% 86 / 122 Branchbran 38.1% 16 / 42 Conditioncond 33.3% 6 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 90.9% 20 / 22 Podpod 100% 18 / 18 totaltotal 62.9% 146 / 232 CC 29 SCAR 17.6
CC
29
Cov
59%
new
19.6
breaker_type
6.7
scope
6.7
CRAP 5.8
« CIGIPP/EnvironmentalRegionControl.pm ↑ Summary CIGIPP/RateControl.pm »
1 #
2 # Rinchi Common Image Generator Interface for Perl
3 # Class Identifier: f78ad832-200e-11de-bdae-001c25551abc
4 # Author: Brian M. Ames
5 #
6  
7 package Rinchi::CIGIPP::WaveControl;
8  
9 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 require Exporter;
15  
16 2 our @ISA = qw(Exporter);
17  
18 # Items to export into callers namespace by default. Note: do not export
19 # names by default without a very good reason. Use EXPORT_OK instead.
20 # Do not simply export all your public functions/methods/constants.
21  
22 # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24 # will save memory.
25 2 our %EXPORT_TAGS = ( 'all' => [ qw(
26
27 ) ] );
28  
29 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30  
31 2 our @EXPORT = qw(
32
33 );
34  
35 2 our $VERSION = '0.02';
36  
37 # Preloaded methods go here.
38  
39 =head1 NAME
40  
41 Rinchi::CIGIPP::WaveControl - Perl extension for the Common Image Generator
42 Interface - Wave Control data packet.
43 data packet.
44 =head1 SYNOPSIS
45  
46 use Rinchi::CIGIPP::WaveControl;
47 my $wave_ctl = Rinchi::CIGIPP::WaveControl->new();
48  
49 $packet_type = $wave_ctl->packet_type();
50 $packet_size = $wave_ctl->packet_size();
51 $region_ident = $wave_ctl->region_ident(57556);
52 $entity_ident = $wave_ctl->entity_ident(19952);
53 $wave_ident = $wave_ctl->wave_ident(240);
54 $breaker_type = $wave_ctl->breaker_type(Rinchi::CIGIPP->Plunging);
55 $scope = $wave_ctl->scope(Rinchi::CIGIPP->GlobalScope);
56 $wave_enable = $wave_ctl->wave_enable(Rinchi::CIGIPP->Enable);
57 $wave_height = $wave_ctl->wave_height(83.07);
58 $wave_length = $wave_ctl->wave_length(12.084);
59 $period = $wave_ctl->period(54.785);
60 $direction = $wave_ctl->direction(24.212);
61 $phase_offset = $wave_ctl->phase_offset(69.289);
62 $leading = $wave_ctl->leading(26.815);
63  
64 =head1 DESCRIPTION
65  
66 The Wave Control packet is used to specify the behavior of waves propagating
67 across the surface of a body of water. Examples include simulated swells and
68 wind chop.
69  
70 The basic waveform is defined by a wave height, wavelength, period, and
71 direction of propagation. Wave height refers to the vertical distance between
72 the wave's crest and trough. The wavelength is the distance from one crest to
73 the next or from one trough to the next.
74  
75 The Phase Offset attribute specifies a phase angle to be added to the IG's
76 reference phase. This is useful for modeling the interference patterns produced
77 within a multiple-wave system. The Leading attribute determines the
78 cross-sectional shape of the wave. This value is the phase angle at which the
79 crest of the wave occurs. For a sinusoidal wave, this angle is zero (0)
80 degrees. As the value increases, the trough flattens and the crest moves toward
81 the front of the wave.
82  
83 =head2 EXPORT
84  
85 None by default.
86  
87 #==============================================================================
88  
89 =item new $wave_ctl = Rinchi::CIGIPP::WaveControl->new()
90  
91 Constructor for Rinchi::WaveControl.
92  
93 =cut
94  
95 2 ▶sub new {
Subroutine new: called CC=7 SCAR=29.8
Pod documented
96 2 my $class = shift;
97 2 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
98  
99 2 my $self = {
100 '_Buffer' => '',
101 '_ClassIdent' => 'f78ad832-200e-11de-bdae-001c25551abc',
102 '_Pack' => 'CCSCCSffffff',
103 '_Swap1' => 'CCvCCvVVVVVV',
104 '_Swap2' => 'CCnCCnNNNNNN',
105 'packetType' => 14,
106 'packetSize' => 32,
107 'region_entityIdent' => 0,
108 'waveIdent' => 0,
109 '_bitfields1' => 0, # Includes bitfields unused26, breakerType, scope, and waveEnable.
110 'breakerType' => 0,
111 'scope' => 0,
112 'waveEnable' => 0,
113 '_unused27' => 0,
114 'waveHeight' => 0,
115 'waveLength' => 0,
116 'period' => 0,
117 'direction' => 0,
118 'phaseOffset' => 0,
119 'leading' => 0,
120 };
121  
122 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
123 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
elsif (ref $_[0] eq 'HASH') { } 0 0 0
124 0 $self->{'_Buffer'} = $_[0][0];
125 } elsif (ref($_[0]) eq 'HASH') {
126 0 foreach my $attr (keys %{$_[0]}) {
127 0 ▶ $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^_/ 0 0 0
128 }
129 }
130 }
131  
132 2 bless($self,$class);
133 2 return $self;
134 }
135  
136 #==============================================================================
137  
138 =item sub packet_type()
139  
140 $value = $wave_ctl->packet_type();
141  
142 Data Packet Identifier.
143  
144 This attribute identifies this data packet as the Wave Control packet. The
145 value of this attribute must be 14.
146  
147 =cut
148  
149 2 ▶sub packet_type() {
Subroutine packet_type: called CC=1 SCAR=0.0
Pod documented
150 2 my ($self) = @_;
151 2 return $self->{'packetType'};
152 }
153  
154 #==============================================================================
155  
156 =item sub packet_size()
157  
158 $value = $wave_ctl->packet_size();
159  
160 Data Packet Size. This attribute indicates the number of bytes in this data
161 packet. The value of this attribute must be 32.
162  
163 =cut
164  
165 2 ▶sub packet_size() {
Subroutine packet_size: called CC=1 SCAR=0.0
Pod documented
166 2 my ($self) = @_;
167 2 return $self->{'packetSize'};
168 }
169  
170 #==============================================================================
171  
172 =item sub region_ident([$newValue])
173  
174 $value = $wave_ctl->region_ident($newValue);
175  
176 Entity ID. (Entity-based Surface Conditions)
177  
178 This attribute specifies the entity to which the surface attributes in this
179 packet are applied.
180  
181  
182  
183 =cut
184  
185 2 ▶sub region_ident() {
Subroutine region_ident: called CC=2 SCAR=7.0
Pod documented
186 2 my ($self,$nv) = @_;
187 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
188 2 $self->{'region_entityIdent'} = $nv;
189 }
190 2 return $self->{'region_entityIdent'};
191 }
192  
193 #==============================================================================
194  
195 =item sub entity_ident([$newValue])
196  
197 $value = $wave_ctl->entity_ident($newValue);
198  
199 Region ID. (Regional Surface Conditions)
200  
201 This attribute specifies the region to which the surface attributes are
202 confined.
203 Note: Entity ID/Region ID is ignored if Scope is set to Global (0).
204  
205 =cut
206  
207 2 ▶sub entity_ident() {
Subroutine entity_ident: called CC=2 SCAR=7.0
Pod documented
208 2 my ($self,$nv) = @_;
209 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
210 2 $self->{'region_entityIdent'} = $nv;
211 }
212 2 return $self->{'region_entityIdent'};
213 }
214  
215 #==============================================================================
216  
217 =item sub wave_ident([$newValue])
218  
219 $value = $wave_ctl->wave_ident($newValue);
220  
221 Wave ID.
222  
223 This attribute specifies the wave to which the attributes in this packet are applied.
224  
225 =cut
226  
227 2 ▶sub wave_ident() {
Subroutine wave_ident: called CC=2 SCAR=7.0
Pod documented
228 2 my ($self,$nv) = @_;
229 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
230 2 $self->{'waveIdent'} = $nv;
231 }
232 2 return $self->{'waveIdent'};
233 }
234  
235 #==============================================================================
236  
237 =item sub breaker_type([$newValue])
238  
239 $value = $wave_ctl->breaker_type($newValue);
240  
241 Breaker Type.
242  
243 This attribute specifies the type of breaker within the surf zone. This may be
244 one of the following values:
245  
246 Plunging - Plunging waves peak until the wave forms a vertical wall, at which
247 point the crest moves faster than the base of the breaker. The wave will then
248 break violently into the wave trough.
249  
250 Spilling - Spilling breakers break gradually over a great distance. White water
251 forms over the crest, which spills down the face of the breaker.
252  
253 Surging - Surging breakers advance toward the beach as vertical walls of water.
254 Unlike with plunging and spilling breakers, the crest does not fall over the
255 front of the wave.
256  
257 Plunging 0
258 Spilling 1
259 Surging 2
260  
261 =cut
262  
263 2 ▶sub breaker_type() {
Subroutine breaker_type: called CC=5 SCAR=19.1
Pod documented
264 2 my ($self,$nv) = @_;
265 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
266 2 ▶ if (($nv==0) or ($nv==1) or ($nv==2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv == 0 or $nv == 1 or $nv == 2) { } 2 0 2
Condition33%2/6
$nv == 0 or $nv == 1 or $nv == 2
l!l&&r!l&&!r
200
$nv == 0 or $nv == 1
l!l&&r!l&&!r
200
MC/DC0%0/3
$nv == 0 or $nv == 1 or $nv == 2
$nv == 0 $nv == 1 $nv == 2
Truth table25%1/4
A or B or C
A= $nv == 0B= $nv == 1C= $nv == 2
ABCresult
1XX1
01X1
0011
0000
267 2 $self->{'breakerType'} = $nv;
268 2 $self->{'_bitfields1'} |= ($nv << 3) &0x18;
269 } else {
270 0 carp "breaker_type must be 0 (Plunging), 1 (Spilling), or 2 (Surging).";
271 }
272 }
273 2 return (($self->{'_bitfields1'} & 0x18) >> 3);
274 }
275  
276 #==============================================================================
277  
278 =item sub scope([$newValue])
279  
280 $value = $wave_ctl->scope($newValue);
281  
282 Scope.
283  
284 This attribute specifies whether the wave is defined for global, regional, or
285 entity-controlled maritime surface conditions. If this value is set to Regional
286 (1), the wave properties are applied only within the region specified by Region
287 ID. If this value is set to Entity (2), the properties are applied to the area
288 defined by the moving model specified by Entity ID.
289  
290 GlobalScope 0
291 RegionalScope 1
292 EntityScope 2
293  
294 =cut
295  
296 2 ▶sub scope() {
Subroutine scope: called CC=5 SCAR=19.1
Pod documented
297 2 my ($self,$nv) = @_;
298 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
299 2 ▶ if (($nv==0) or ($nv==1) or ($nv==2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv == 0 or $nv == 1 or $nv == 2) { } 2 0 2
Condition33%2/6
$nv == 0 or $nv == 1 or $nv == 2
l!l&&r!l&&!r
200
$nv == 0 or $nv == 1
l!l&&r!l&&!r
200
MC/DC0%0/3
$nv == 0 or $nv == 1 or $nv == 2
$nv == 0 $nv == 1 $nv == 2
Truth table25%1/4
A or B or C
A= $nv == 0B= $nv == 1C= $nv == 2
ABCresult
1XX1
01X1
0011
0000
300 2 $self->{'scope'} = $nv;
301 2 $self->{'_bitfields1'} |= ($nv << 1) &0x06;
302 } else {
303 0 carp "scope must be 0 (GlobalScope), 1 (RegionalScope), or 2 (EntityScope).";
304 }
305 }
306 2 return (($self->{'_bitfields1'} & 0x06) >> 1);
307 }
308  
309 #==============================================================================
310  
311 =item sub wave_enable([$newValue])
312  
313 $value = $wave_ctl->wave_enable($newValue);
314  
315 Wave Enable.
316  
317 This attribute determines whether the wave is enabled or disabled. A disabled
318 wave does not contribute to the shape of the water's surface.
319  
320 Disable 0
321 Enable 1
322  
323 =cut
324  
325 2 ▶sub wave_enable() {
Subroutine wave_enable: called CC=4 SCAR=15.5
Pod documented
326 2 my ($self,$nv) = @_;
327 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
328 2 ▶ if (($nv==0) or ($nv==1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nv == 0 or $nv == 1) { } 2 0 2
Condition33%1/3
$nv == 0 or $nv == 1
l!l&&r!l&&!r
020
MC/DC0%0/2
$nv == 0 or $nv == 1
$nv == 0 $nv == 1
Truth table33%1/3
A or B
A= $nv == 0B= $nv == 1
ABresult
1X1
011
000
329 2 $self->{'waveEnable'} = $nv;
330 2 $self->{'_bitfields1'} |= $nv &0x01;
331 } else {
332 0 carp "wave_enable must be 0 (Disable), or 1 (Enable).";
333 }
334 }
335 2 return ($self->{'_bitfields1'} & 0x01);
336 }
337  
338 #==============================================================================
339  
340 =item sub wave_height([$newValue])
341  
342 $value = $wave_ctl->wave_height($newValue);
343  
344 Wave Height.
345  
346 This attribute specifies the average vertical distance measured in meters from
347 trough to crest produced by the wave. Wave Height is centered on Sea Surface Height.
348  
349 =cut
350  
351 2 ▶sub wave_height() {
Subroutine wave_height: called CC=2 SCAR=7.0
Pod documented
352 2 my ($self,$nv) = @_;
353 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
354 2 $self->{'waveHeight'} = $nv;
355 }
356 2 return $self->{'waveHeight'};
357 }
358  
359 #==============================================================================
360  
361 =item sub wave_length([$newValue])
362  
363 $value = $wave_ctl->wave_length($newValue);
364  
365 Wavelength.
366  
367 This attribute specifies the distance from a particular phase on a wave to the
368 same phase on an adjacent wave.
369  
370 =cut
371  
372 2 ▶sub wave_length() {
Subroutine wave_length: called CC=2 SCAR=7.0
Pod documented
373 2 my ($self,$nv) = @_;
374 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
375 2 $self->{'waveLength'} = $nv;
376 }
377 2 return $self->{'waveLength'};
378 }
379  
380 #==============================================================================
381  
382 =item sub period([$newValue])
383  
384 $value = $wave_ctl->period($newValue);
385  
386 Period.
387  
388 This attribute specifies the time required for one complete oscillation of the wave.
389  
390 =cut
391  
392 2 ▶sub period() {
Subroutine period: called CC=2 SCAR=7.0
Pod documented
393 2 my ($self,$nv) = @_;
394 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
395 2 $self->{'period'} = $nv;
396 }
397 2 return $self->{'period'};
398 }
399  
400 #==============================================================================
401  
402 =item sub direction([$newValue])
403  
404 $value = $wave_ctl->direction($newValue);
405  
406 Direction.
407  
408 This attribute specifies the direction in which the wave propagates measured in
409 degrees from true north.
410  
411 =cut
412  
413 2 ▶sub direction() {
Subroutine direction: called CC=2 SCAR=7.0
Pod documented
414 2 my ($self,$nv) = @_;
415 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
416 2 $self->{'direction'} = $nv;
417 }
418 2 return $self->{'direction'};
419 }
420  
421 #==============================================================================
422  
423 =item sub phase_offset([$newValue])
424  
425 $value = $wave_ctl->phase_offset($newValue);
426  
427 Phase Offset.
428  
429 This attribute specifies a phase offset for the wave.
430  
431 =cut
432  
433 2 ▶sub phase_offset() {
Subroutine phase_offset: called CC=2 SCAR=7.0
Pod documented
434 2 my ($self,$nv) = @_;
435 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
436 2 $self->{'phaseOffset'} = $nv;
437 }
438 2 return $self->{'phaseOffset'};
439 }
440  
441 #==============================================================================
442  
443 =item sub leading([$newValue])
444  
445 $value = $wave_ctl->leading($newValue);
446  
447 Leading.This attribute specifies the phase angle at which the crest occurs.
448  
449 =cut
450  
451 2 ▶sub leading() {
Subroutine leading: called CC=2 SCAR=7.0
Pod documented
452 2 my ($self,$nv) = @_;
453 2 ▶ if (defined($nv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nv) 2 0 2
454 2 $self->{'leading'} = $nv;
455 }
456 2 return $self->{'leading'};
457 }
458  
459 #==========================================================================
460  
461 =item sub pack()
462  
463 $value = $wave_ctl->pack();
464  
465 Returns the packed data packet.
466  
467 =cut
468  
469 2 ▶sub pack($) {
Subroutine pack: called CC=1 SCAR=0.0
Pod documented
470 2 my $self = shift ;
471
472 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
473 $self->{'packetType'},
474 $self->{'packetSize'},
475 $self->{'region_entityIdent'},
476 $self->{'waveIdent'},
477 $self->{'_bitfields1'}, # Includes bitfields unused26, breakerType, scope, and waveEnable.
478 $self->{'_unused27'},
479 $self->{'waveHeight'},
480 $self->{'waveLength'},
481 $self->{'period'},
482 $self->{'direction'},
483 $self->{'phaseOffset'},
484 2 $self->{'leading'},
485 );
486  
487 2 return $self->{'_Buffer'};
488 }
489  
490 #==========================================================================
491  
492 =item sub unpack()
493  
494 $value = $wave_ctl->unpack();
495  
496 Unpacks the packed data packet.
497  
498 =cut
499  
500 0 ▶sub unpack($) {
Subroutine unpack: not called CC=2 SCAR=17.9
Pod documented
501 0 my $self = shift @_;
502
503 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
504 0 $self->{'_Buffer'} = shift @_;
505 }
506 0 my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
507 0 $self->{'packetType'} = $a;
508 0 $self->{'packetSize'} = $b;
509 0 $self->{'region_entityIdent'} = $c;
510 0 $self->{'waveIdent'} = $d;
511 0 $self->{'_bitfields1'} = $e; # Includes bitfields unused26, breakerType, scope, and waveEnable.
512 0 $self->{'_unused27'} = $f;
513 0 $self->{'waveHeight'} = $g;
514 0 $self->{'waveLength'} = $h;
515 0 $self->{'period'} = $i;
516 0 $self->{'direction'} = $j;
517 0 $self->{'phaseOffset'} = $k;
518 0 $self->{'leading'} = $l;
519  
520 0 $self->{'breakerType'} = $self->breaker_type();
521 0 $self->{'scope'} = $self->scope();
522 0 $self->{'waveEnable'} = $self->wave_enable();
523  
524 0 return $self->{'_Buffer'};
525 }
526  
527 #==========================================================================
528  
529 =item sub byte_swap()
530  
531 $obj_name->byte_swap();
532  
533 Byte swaps the packed data packet.
534  
535 =cut
536  
537 0 ▶sub byte_swap($) {
Subroutine byte_swap: not called CC=2 SCAR=17.9
Pod documented
538 0 my $self = shift @_;
539
540 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
541 0 $self->{'_Buffer'} = shift @_;
542 } else {
543 0 $self->pack();
544 }
545 0 my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
546  
547 0 $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
548 0 $self->unpack();
549  
550 0 return $self->{'_Buffer'};
551 }
552  
553 2 1;
554 __END__
« CIGIPP/EnvironmentalRegionControl.pm ↑ Summary CIGIPP/RateControl.pm »