Construction.pm

filter: Statementstmt 99.0% 108 / 109 Branchbran 85.0% 17 / 20 Conditioncond 81.2% 13 / 16 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 27 / 27 Podpod 66.6% 12 / 18 totaltotal 91.0% 182 / 200 CC 22 SCAR 11.0
CC
22
Cov
95%
draw
7.0
add_derived_point
5.0
find_circle
4.0
CRAP 3.0
« Construction/Derivate/IntersectionCircleLine.pm ↑ Summary Construction/Derivate/IntersectionCircleCircle.pm »
1 package Math::Geometry::Construction;
2  
3 16 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 ▶use Math::Geometry::Construction::Types qw(HashRefOfGeometricObject Draw);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Math::Vector::Real 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use SVG;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Params::Validate qw(validate validate_pos :types);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 C<Math::Geometry::Construction> - intersecting lines and circles
16  
17 =head1 VERSION
18  
19 Version 0.024
20  
21 =cut
22  
23 16 our $VERSION = '0.024';
24  
25  
26 ###########################################################################
27 # #
28 # Accessors #
29 # #
30 ###########################################################################
31  
32 16 has 'background' => (isa => 'Str|ArrayRef',
33 is => 'rw');
34  
35 has 'objects' => (isa => HashRefOfGeometricObject,
36 is => 'bare',
37 traits => ['Hash'],
38 58 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 16 handles => {count_objects => 'count',
40 object => 'accessor',
41 object_ids => 'keys',
42 objects => 'values'},
43 init_arg => undef);
44  
45 16 has '_counter' => (isa => 'Int',
46 is => 'rw',
47 default => 0,
48 init_arg => undef);
49  
50 16 has 'point_size' => (isa => 'Num',
51 is => 'rw',
52 default => 6);
53  
54 16 has 'partial_circles' => (isa => 'Bool',
55 is => 'ro',
56 default => 0);
57  
58 16 has 'min_circle_gap' => (isa => 'Num',
59 is => 'ro',
60 default => 1.5707963267949);
61  
62 16 has 'buffer_results' => (isa => 'Bool',
63 is => 'rw',
64 default => 1,
65 trigger => \&clear_buffer);
66  
67 16 has '_output' => (isa => Draw,
68 is => 'rw',
69 handles => {draw_line => 'line',
70 draw_circle => 'circle',
71 draw_text => 'text'},
72 init_arg => undef);
73  
74 585 ▶sub counter {
Subroutine counter: called CC=1 SCAR=0.0
Pod undocumented
75 585 my ($self) = @_;
76  
77 585 my $counter = $self->_counter;
78 585 $self->_counter($counter + 1);
79 585 return $counter;
80 }
81  
82 322 ▶sub clear_buffer {
Subroutine clear_buffer: called CC=3 SCAR=11.0
Pod undocumented
83 322 my ($self) = @_;
84  
85 322 foreach($self->objects) {
86 2156 ▶ $_->clear_buffer if($_->can('clear_buffer'));
Branch: 1 branch
BranchTrueFalseTotal
if $_->can("clear_buffer") 1728 428 2156
87 }
88 }
89  
90 4 ▶sub points {
Subroutine points: called CC=1 SCAR=0.0
Pod documented
91 4 my ($self) = @_;
92 4 my $class = 'Math::Geometry::Construction::Point';
93  
94 4 return(grep { $_->isa($class) } $self->objects);
95 }
96  
97 50 ▶sub lines {
Subroutine lines: called CC=1 SCAR=0.0
Pod documented
98 50 my ($self) = @_;
99 50 my $class = 'Math::Geometry::Construction::Line';
100  
101 50 return(grep { $_->isa($class) } $self->objects);
102 }
103  
104 32 ▶sub circles {
Subroutine circles: called CC=1 SCAR=0.0
Pod documented
105 32 my ($self) = @_;
106 32 my $class = 'Math::Geometry::Construction::Circle';
107  
108 32 return(grep { $_->isa($class) } $self->objects);
109 }
110  
111 585 ▶sub add_object {
Subroutine add_object: called CC=3 SCAR=11.6
Pod documented
112 585 my ($self, $class, @args) = @_;
113  
114 585 ▶ if($class =~ /^\s*[A-Za-z0-9\_\:]+\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^\s*[A-Za-z0-9\_\:]+\s*$/) { } 585 0 585
115 585 ▶ eval "require $class" or croak "Unable to load module $class: $!";
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class" or croak("Unable to load module ${class}: $!") 585 0 585
116 }
117 0 else { croak "Class name $class did not pass regex check" }
118
119 585 my $object = $class->new(construction => $self,
120 @args,
121 order_index => $self->counter);
122 572 $self->object($object->id, $object);
123  
124 572 return $object;
125 }
126  
127 242 ▶sub add_point {
Subroutine add_point: called CC=1 SCAR=0.0
Pod documented
128 242 my ($self, @args) = @_;
129  
130 242 return $self->add_object
131 ('Math::Geometry::Construction::FixedPoint', @args);
132 }
133  
134 60 ▶sub add_line {
Subroutine add_line: called CC=1 SCAR=0.0
Pod documented
135 60 my ($self, @args) = @_;
136  
137 60 return $self->add_object
138 ('Math::Geometry::Construction::Line', @args);
139 }
140  
141 46 ▶sub find_line {
Subroutine find_line: called CC=3 SCAR=11.0
Pod undocumented
142 46 my ($self, %args) = @_;
143  
144 # TODO: test %args
145
146 46 foreach($self->lines) {
147 66 ▶ return $_ if($_->has_point(@{$args{support}}));
Branch: 1 branch
BranchTrueFalseTotal
if $_->has_point(@{$args{"support"};}) 26 40 66
148 }
149 20 return undef;
150 }
151  
152 4 ▶sub find_or_add_line {
Subroutine find_or_add_line: called CC=2 SCAR=7.1
Pod undocumented
153 4 my ($self, @args) = @_;
154  
155 4 ▶ return($self->find_line(@args) or $self->add_line(@args));
Condition66%2/3
$self->find_line(@args) || $self->add_line(@args)
l!l&&r!l&&!r
220
MC/DC0%0/2
$self->find_line(@args) || $self->add_line(@args)
$self->find_line(@args) $self->add_line(@args)
Truth table66%2/3
A || B
A= $self->find_line(@args)B= $self->add_line(@args)
ABresult
1X1
011
000
156 }
157  
158 57 ▶sub add_circle {
Subroutine add_circle: called CC=1 SCAR=0.0
Pod documented
159 57 my ($self, @args) = @_;
160  
161 57 return $self->add_object
162 ('Math::Geometry::Construction::Circle', @args);
163 }
164  
165 28 ▶sub find_circle {
Subroutine find_circle: called CC=4 SCAR=13.9
Pod undocumented
166 28 my ($self, %args) = @_;
167  
168 # TODO: test %args
169
170 28 foreach($self->circles) {
171 return $_ if($_->center->id eq $args{center}->id and
172 45 ▶ $_->has_point($args{support}));
Branch: 1 branch
BranchTrueFalseTotal
if $_->center->id eq $args{"center"}->id and $_->has_point($args{"support"}) 13 32 45
Condition100%3/3
$_->center->id eq $args{"center"}->id and $_->has_point($args{"support"})
!ll&&!rl&&r
161613
MC/DC100%2/2
$_->center->id eq $args{"center"}->id and $_->has_point($args{"support"})
$_->center->id eq $args{"center"}->id $_->has_point($args{"support"})
Truth table100%3/3
A and B
A= $_->center->id eq $args{"center"}->idB= $_->has_point($args{"support"})
ABresult
0X0
100
111
173 }
174 15 return undef;
175 }
176  
177 6 ▶sub find_or_add_circle {
Subroutine find_or_add_circle: called CC=2 SCAR=7.1
Pod undocumented
178 6 my ($self, @args) = @_;
179  
180 6 ▶ return($self->find_circle(@args) or $self->add_circle(@args));
Condition66%2/3
$self->find_circle(@args) || $self->add_circle(@args)
l!l&&r!l&&!r
240
MC/DC0%0/2
$self->find_circle(@args) || $self->add_circle(@args)
$self->find_circle(@args) $self->add_circle(@args)
Truth table66%2/3
A || B
A= $self->find_circle(@args)B= $self->add_circle(@args)
ABresult
1X1
011
000
181 }
182  
183 111 ▶sub add_derivate {
Subroutine add_derivate: called CC=1 SCAR=0.0
Pod documented
184 111 my ($self, $class, @args) = @_;
185  
186 111 return $self->add_object
187 ('Math::Geometry::Construction::Derivate::'.$class, @args);
188 }
189  
190 87 ▶sub add_derived_point {
Subroutine add_derived_point: called CC=5 SCAR=16.1
Pod documented
191 87 my ($self, $class, $derivate_args, $point_args) = @_;
192  
193 87 my $derivate = $self->add_derivate($class, %$derivate_args);
194
195 87 ▶ if(!defined($point_args) or ref($point_args) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $point_args or ref $point_args eq 'HASH') { } 71 16 87
Condition100%3/3
not defined $point_args or ref $point_args eq "HASH"
l!l&&r!l&&!r
422916
MC/DC100%2/2
not defined $point_args or ref $point_args eq "HASH"
not defined $point_args ref $point_args eq "HASH"
Truth table100%3/3
not(A) or B
A= not defined $point_argsB= ref $point_args eq "HASH"
ABresult
1X1
011
000
196 71 ▶ return $derivate->create_derived_point(%{$point_args || {}});
Condition100%2/2
$point_args || {}
l!l
2942
MC/DC100%1/1
$point_args || {}
$point_args
Truth table100%2/2
A
A= $point_args
Aresult
11
00
197 }
198 else {
199 16 ▶ return(map { $derivate->create_derived_point(%{$_ || {}}) }
Condition50%1/2
$_ || {}
l!l
330
MC/DC0%0/1
$_ || {}
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
200 @$point_args);
201 }
202 }
203  
204 ###########################################################################
205 # #
206 # Draw #
207 # #
208 ###########################################################################
209  
210 43 ▶sub draw {
Subroutine draw: called CC=7 SCAR=19.5
Pod documented
211 43 my ($self, $type, %args) = @_;
212  
213 43 ($type) = validate_pos(@{[$type]},
214 {type => SCALAR,
215 regex => qr/^\s*[A-Za-z0-9\_\:]+\s*$/});
216
217 31 ▶ my $class = $type =~ /\:\:/
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /\:\:/ ? : 2 29 31
218 ? $type
219 : 'Math::Geometry::Construction::Draw::'.$type;
220  
221 31 ▶ eval "require $class" or croak "Unable to load module $class: $!";
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class" or croak("Unable to load module ${class}: $!") 24 7 31
222  
223 24 my $output = $self->_output
224 ($class->new(background => $self->background, %args));
225 16 my @objects = sort { $a->order_index <=> $b->order_index }
226 $self->objects;
227  
228 16 my $point_class = 'Math::Geometry::Construction::Point';
229 16 foreach(grep { !eval { $_->isa($point_class) } } @objects) {
230 14 ▶ $_->draw(output => $output) if($_->can('draw'));
Branch: 1 branch
BranchTrueFalseTotal
if $_->can("draw") 10 4 14
231 }
232 16 foreach(grep { eval { $_->isa($point_class) } } @objects) {
233 29 ▶ $_->draw(output => $output) if($_->can('draw'));
Branch: 1 branch
BranchTrueFalseTotal
if $_->can("draw") 29 0 29
234 }
235  
236 16 return $output->output;
237 }
238  
239 12 ▶sub as_svg { return(shift(@_)->draw('SVG', @_)) }
Subroutine as_svg: called CC=1 SCAR=0.0
Pod documented
240  
241 6 ▶sub as_tikz { return(shift(@_)->draw('TikZ', @_)) }
Subroutine as_tikz: called CC=1 SCAR=0.0
Pod documented
242  
243 16 1;
244  
245  
246 __END__
« Construction/Derivate/IntersectionCircleLine.pm ↑ Summary Construction/Derivate/IntersectionCircleCircle.pm »