Construction/Derivate/PointOnLine.pm

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