Construction/Line.pm

filter: Statementstmt 83.3% 75 / 90 Branchbran 60.0% 12 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 18 / 21 Podpod 75.0% 6 / 8 totaltotal 79.8% 111 / 139 CC 11 SCAR 7.9
CC
11
Cov
79%
direction
6.0
parallel
3.4
draw
3.0
CRAP 2.2
« Construction/Vector.pm ↑ Summary Construction/Role/PointSet.pm »
1 package Math::Geometry::Construction::Line;
2 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 10 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use Math::Geometry::Construction::Types qw(PointPoint);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use overload 'x' => '_intersect',
Subroutine BEGIN: called CC=1 SCAR=0.0
13 '.' => '_point_on',
14 10 ▶ 'bool' => sub { return 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 C<Math::Geometry::Construction::Line> - line through two points
19  
20 =head1 VERSION
21  
22 Version 0.024
23  
24 =cut
25  
26 10 our $VERSION = '0.024';
27  
28  
29 ###########################################################################
30 # #
31 # Class Variables and Methods #
32 # #
33 ###########################################################################
34  
35 10 our $ID_TEMPLATE = 'L%09d';
36  
37 59 ▶sub id_template { return $ID_TEMPLATE }
Subroutine id_template: called CC=1 SCAR=0.0
Pod documented
38  
39 ###########################################################################
40 # #
41 # Accessors #
42 # #
43 ###########################################################################
44  
45 10 with 'Math::Geometry::Construction::Role::Input';
46 10 with 'Math::Geometry::Construction::Role::Object';
47 10 with 'Math::Geometry::Construction::Role::PositionSelection';
48 10 with 'Math::Geometry::Construction::Role::Output';
49 10 with 'Math::Geometry::Construction::Role::PointSet';
50  
51 10 has 'support' => (isa => PointPoint,
52 is => 'bare',
53 traits => ['Array'],
54 required => 1,
55 handles => {count_support => 'count',
56 support => 'elements',
57 single_support => 'accessor'});
58  
59 60 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=6.9
Pod documented
60 60 my ($class, %args) = @_;
61
62 60 ▶ for(my $i=0;$i<@{$args{support}};$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$args{"support"};}) 120 60 180
63 $args{support}->[$i] = $class->import_point
64 120 ($args{construction}, $args{support}->[$i]);
65 }
66  
67 60 return \%args;
68 }
69  
70 60 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
71 60 my ($self, $args) = @_;
72  
73 60 ▶ $self->style('stroke', 'black') unless($self->style('stroke'));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->style("stroke") 59 1 60
74  
75 60 $self->register_point($self->support);
76 }
77  
78 ###########################################################################
79 # #
80 # Retrieve Data #
81 # #
82 ###########################################################################
83  
84 8 ▶sub positions {
Subroutine positions: called CC=1 SCAR=0.0
Pod undocumented
85 8 my ($self) = @_;
86  
87 8 return map { $_->position } $self->points;
88 }
89  
90 0 ▶sub direction {
Subroutine direction: not called CC=2 SCAR=17.9
Pod documented
91 0 my ($self) = @_;
92 0 my @support_positions = map { $_->position } $self->support;
93  
94 # check for defined positions
95 0 ▶ if(any { !defined($_) } @support_positions) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { not defined $_; } , @support_positions)) 0 0 0
96 0 warn sprintf("Undefined support point in line %s.\n", $self->id);
97 0 return undef;
98 }
99  
100 0 return($support_positions[1] - $support_positions[0]);
101 }
102  
103 64 ▶sub parallel {
Subroutine parallel: called CC=3 SCAR=12.2
Pod documented
104 64 my ($self) = @_;
105 64 my @support_positions = map { $_->position } $self->support;
106  
107 # check for defined positions
108 64 ▶ if(any { !defined($_) } @support_positions) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { not defined $_; } , @support_positions)) 0 64 64
109 0 warn sprintf("Undefined support point in line %s.\n", $self->id);
110 0 return undef;
111 }
112  
113 64 my $direction = $support_positions[1] - $support_positions[0];
114 64 my $length = abs($direction);
115  
116 64 ▶ if($length == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length == 0) 0 64 64
117 0 warn sprintf("Support points of line %s are identical.\n",
118 $self->id);
119 0 return undef;
120 }
121
122 64 return($direction / $length);
123 }
124  
125 38 ▶sub normal {
Subroutine normal: called CC=2 SCAR=7.1
Pod documented
126 38 my ($self) = @_;
127 38 my $parallel = $self->parallel;
128  
129 38 ▶ return $parallel ? V(-$parallel->[1], $parallel->[0]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$parallel ? : 38 0 38
130 }
131  
132 4 ▶sub draw {
Subroutine draw: called CC=3 SCAR=11.1
Pod documented
133 4 my ($self, %args) = @_;
134 4 ▶ return undef if $self->hidden;
Branch: 1 branch
BranchTrueFalseTotal
if $self->hidden 0 4 4
135  
136 4 my $parallel = $self->parallel;
137 4 ▶ return undef if(!$parallel);
Branch: 1 branch
BranchTrueFalseTotal
unless $parallel 0 4 4
138  
139 4 my $extend = $self->extend;
140 4 my @positions = ($self->extreme_position(-$parallel)
141 - $parallel * $extend->[0],
142 $self->extreme_position($parallel)
143 + $parallel * $extend->[1]);
144  
145 4 $self->construction->draw_line(x1 => $positions[0]->[0],
146 y1 => $positions[0]->[1],
147 x2 => $positions[1]->[0],
148 y2 => $positions[1]->[1],
149 style => $self->style_hash,
150 id => $self->id);
151
152 4 $self->draw_label
153 ('x' => ($positions[0]->[0] + $positions[1]->[0]) / 2,
154 'y' => ($positions[0]->[1] + $positions[1]->[1]) / 2);
155 }
156  
157 ###########################################################################
158 # #
159 # Overloading #
160 # #
161 ###########################################################################
162  
163 3 ▶sub _intersect {
Subroutine _intersect: called CC=3 SCAR=11.0
164 3 my ($self, $intersector) = @_;
165 3 my $class;
166
167 3 $class = 'Math::Geometry::Construction::Line';
168 3 ▶ if(eval { $intersector->isa($class) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $intersector->isa($class) } }) 2 1 3
169 2 return $self->construction->add_derived_point
170 ('IntersectionLineLine', {input => [$self, $intersector]});
171 }
172  
173 1 $class = 'Math::Geometry::Construction::Circle';
174 1 ▶ if(eval { $intersector->isa($class) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $intersector->isa($class) } }) 1 0 1
175 1 return $self->construction->add_derived_point
176 ('IntersectionCircleLine', {input => [$self, $intersector]});
177 }
178 }
179  
180 0 ▶sub _point_on {
Subroutine _point_on: not called CC=1 SCAR=6.9
181 0 my ($self, $args) = @_;
182  
183 0 my $derivate = "Math::Geometry::Construction::Derivate::PointOnLine";
184 0 return $self->construction->add_derived_point
185 ($derivate, {input => [$self], $args});
186 }
187  
188 10 1;
189  
190  
191 __END__
« Construction/Vector.pm ↑ Summary Construction/Role/PointSet.pm »