Construction/Derivate/PointOnCircle.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 75.0% 9 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 83.0% 54 / 65 CC 7 SCAR 15.0
CC
7
Cov
89%
calculate_positions
7.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« Construction/Role/AlternativeSources.pm ↑ Summary Construction/Role/PositionSelection.pm »
1 package Math::Geometry::Construction::Derivate::PointOnCircle;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 extends 'Math::Geometry::Construction::Derivate';
4  
5 2 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Math::Geometry::Construction::Types qw(Circle);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 C<Math::Geometry::Construction::Derivate::PointOnCircle> - point on a Circle
13  
14 =head1 VERSION
15  
16 Version 0.024
17  
18 =cut
19  
20 2 our $VERSION = '0.024';
21  
22  
23 ###########################################################################
24 # #
25 # Accessors #
26 # #
27 ###########################################################################
28  
29 2 with 'Math::Geometry::Construction::Role::AlternativeSources';
30  
31 2 has 'input' => (isa => Circle,
32 coerce => 1,
33 is => 'ro',
34 required => 1);
35  
36 2 my %alternative_sources =
37 (position_sources => {'distance' => {isa => 'Num'},
38 'quantile' => {isa => 'Num'},
39 'phi' => {isa => 'Num'}});
40  
41 2 ▶while(my ($name, $alternatives) = each %alternative_sources) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %alternative_sources) 2 2 4
42 2 __PACKAGE__->alternatives
43 (name => $name,
44 alternatives => $alternatives,
45 clear_buffer => 1);
46 }
47  
48 12 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
49 12 my ($self, $args) = @_;
50  
51 12 $self->_check_position_sources;
52 }
53  
54 ###########################################################################
55 # #
56 # Retrieve Data #
57 # #
58 ###########################################################################
59  
60 10 ▶sub calculate_positions {
Subroutine calculate_positions: called CC=7 SCAR=20.1
Pod undocumented
61 10 my ($self) = @_;
62 10 my $circle = $self->input;
63  
64 10 my $center_p = $circle->center->position;
65 10 my $support_p = $circle->support->position;
66 10 ▶ return if(!defined($center_p) or !defined($support_p));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $center_p and defined $support_p 0 10 10
Condition33%1/3
defined $center_p and defined $support_p
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $center_p and defined $support_p
defined $center_p defined $support_p
Truth table33%1/3
A and B
A= defined $center_pB= defined $support_p
ABresult
0X0
100
111
67 10 my $radius_v = $support_p - $center_p;
68 10 my $radius = abs($radius_v);
69 10 ▶ return $center_p if($radius == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $radius == 0 0 10 10
70  
71 10 my $phi = atan2($radius_v->[1], $radius_v->[0]);
72 10 ▶ if($self->_has_distance) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_has_distance) { } 2 8 10
elsif ($self->_has_quantile) { } 5 3 8
elsif ($self->_has_phi) { } 3 0 3
73 2 $phi += $self->_distance / $radius;
74 }
75 elsif($self->_has_quantile) {
76 5 $phi += 6.28318530717959 * $self->_quantile;
77 }
78 elsif($self->_has_phi) {
79 3 $phi += $self->_phi;
80 }
81 else {
82 0 croak "No way to determine position of PointOnCircle ".$self->id;
83 }
84  
85 10 return($center_p + [$radius * cos($phi), $radius * sin($phi)]);
86 }
87  
88 ###########################################################################
89 # #
90 # Change Data #
91 # #
92 ###########################################################################
93  
94 10 ▶sub register_derived_point {
Subroutine register_derived_point: called CC=1 SCAR=0.0
Pod undocumented
95 10 my ($self, $point) = @_;
96  
97 10 $self->input->register_point($point);
98 }
99  
100 2 1;
101  
102  
103 __END__
« Construction/Role/AlternativeSources.pm ↑ Summary Construction/Role/PositionSelection.pm »