Construction/Role/PositionSelection.pm

filter: Statementstmt 86.4% 64 / 74 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 76.8% 83 / 108 CC 9 SCAR 11.6
CC
9
Cov
79%
indexed_position
7.3
extreme_position
3.1
close_position
2.0
CRAP 3.2
« Construction/Derivate/PointOnCircle.pm ↑ Summary Construction/Derivate/IntersectionCircleLine.pm »
1 package Math::Geometry::Construction::Role::PositionSelection;
2 14 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 14 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Math::Geometry::Construction::Vector;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use Math::Geometry::Construction::Types qw(Vector);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use MooseX::Params::Validate 0.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 C<Math::Geometry::Construction::Role::PositionSelection> - select position from list
15  
16 =head1 VERSION
17  
18 Version 0.024
19  
20 =cut
21  
22 14 our $VERSION = '0.024';
23  
24  
25 ###########################################################################
26 # #
27 # Accessors #
28 # #
29 ###########################################################################
30  
31 14 requires 'id';
32 14 requires 'positions';
33  
34 ###########################################################################
35 # #
36 # Retrieve Data #
37 # #
38 ###########################################################################
39  
40 109 ▶sub indexed_position {
Subroutine indexed_position: called CC=5 SCAR=19.8
Pod undocumented
41 109 my ($self, $index) = @_;
42 109 my @positions = grep { defined($_) } $self->positions;
43  
44 109 ▶ croak "Undefined index in 'indexed_position' selector"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 109 109
45 if(!defined($index));
46
47 109 ▶ if(!@positions) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@positions) 0 109 109
48 0 warn sprintf("No positions to select from in %s.\n", $self->id);
49 0 return undef;
50 }
51 109 ▶ if($index < 0 or $index >= @positions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0 or $index >= @positions) 0 109 109
Condition33%1/3
$index < 0 or $index >= @positions
l!l&&r!l&&!r
00109
MC/DC0%0/2
$index < 0 or $index >= @positions
$index < 0 $index >= @positions
Truth table33%1/3
A or B
A= $index < 0B= $index >= @positions
ABresult
1X1
011
000
52 0 warn sprintf("Position index out of range in %s.\n", $self->id);
53 0 return undef;
54 }
55  
56 109 return($positions[$index]);
57 }
58  
59 13 ▶sub extreme_position {
Subroutine extreme_position: called CC=3 SCAR=11.3
Pod undocumented
60 13 my $self = shift;
61 13 my ($direction) = map { $_->value } pos_validated_list
62 (\@_, {isa => Vector, coerce => 1});
63
64 13 my $d = abs($direction);
65 13 ▶ return undef if($d == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $d == 0 0 13 13
66  
67 13 my $norm = $direction / $d;
68 13 my @positions = grep { defined($_) } $self->positions;
69  
70 13 ▶ if(!@positions) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@positions) 0 13 13
71 0 warn sprintf("No positions to select from in %s.\n", $self->id);
72 0 return undef;
73 }
74  
75 26 return((map { $_->[0] }
76 13 sort { $b->[1] <=> $a->[1] }
77 13 map { [$_, $_ * $norm] }
78 @positions)[0]);
79 }
80  
81 4 ▶sub close_position {
Subroutine close_position: called CC=2 SCAR=7.1
Pod undocumented
82 4 my $self = shift;
83 4 my ($reference) = map { $_->value } pos_validated_list
84 (\@_, {isa => Vector, coerce => 1});
85
86 4 my @positions = grep { defined($_) } $self->positions;
87  
88 4 ▶ if(!@positions) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@positions) 0 4 4
89 0 warn sprintf("No positions to select from in %s.\n", $self->id);
90 0 return undef;
91 }
92  
93 8 return((map { $_->[0] }
94 4 sort { $a->[1] <=> $b->[1] }
95 4 map { [$_, abs($_ - $reference)] }
96 @positions)[0]);
97 }
98  
99 2 ▶sub distant_position {
Subroutine distant_position: called CC=2 SCAR=7.1
Pod undocumented
100 2 my $self = shift;
101 2 my ($reference) = map { $_->value } pos_validated_list
102 (\@_, {isa => Vector, coerce => 1});
103
104 2 my @positions = grep { defined($_) } $self->positions;
105  
106 2 ▶ if(!@positions) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@positions) 0 2 2
107 0 warn sprintf("No positions to select from in %s.\n", $self->id);
108 0 return undef;
109 }
110  
111 4 return((map { $_->[0] }
112 2 sort { $b->[1] <=> $a->[1] }
113 2 map { [$_, abs($_ - $reference)] }
114 @positions)[0]);
115 }
116  
117 ###########################################################################
118 # #
119 # Change Data #
120 # #
121 ###########################################################################
122  
123 14 1;
124  
125  
126 __END__
« Construction/Derivate/PointOnCircle.pm ↑ Summary Construction/Derivate/IntersectionCircleLine.pm »