Construction/Derivate/IntersectionCircleCircle.pm

filter: Statementstmt 100% 39 / 39 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 90.7% 49 / 54 CC 6 SCAR 10.5
CC
6
Cov
93%
calculate_positions
5.0
register_derived_point
2.0
BEGIN
1.0
CRAP 2.9
« Construction.pm ↑ Summary Construction/Role/Input.pm »
1 package Math::Geometry::Construction::Derivate::IntersectionCircleCircle;
2 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 extends 'Math::Geometry::Construction::Derivate';
4  
5 3 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Math::Geometry::Construction::Types qw(CircleCircle);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 C<Math::Geometry::Construction::Derivate::IntersectionCircleCircle> - circle circle intersection
14  
15 =head1 VERSION
16  
17 Version 0.024
18  
19 =cut
20  
21 3 our $VERSION = '0.024';
22  
23  
24 ###########################################################################
25 # #
26 # Accessors #
27 # #
28 ###########################################################################
29  
30 3 has 'input' => (isa => CircleCircle,
31 is => 'bare',
32 traits => ['Array'],
33 required => 1,
34 handles => {count_input => 'count',
35 input => 'elements',
36 single_input => 'accessor'});
37  
38 ###########################################################################
39 # #
40 # Retrieve Data #
41 # #
42 ###########################################################################
43  
44 4 ▶sub calculate_positions {
Subroutine calculate_positions: called CC=5 SCAR=16.2
Pod undocumented
45 4 my ($self) = @_;
46 4 my @circles = $self->input;
47  
48 # currently assuming that points have to be defined
49 4 my @center_p = map { $_->center->position } @circles;
50 4 my @radii = map { $_->radius } @circles;
51  
52 4 ▶ foreach(@center_p, @radii) { return if(!defined($_)) }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 16 16
53  
54 4 my $distance = $center_p[1] - $center_p[0];
55 4 my $d = abs($distance);
56 4 ▶ return if($d == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $d == 0 0 4 4
57  
58 4 my $parallel = $distance / $d;
59 4 my $normal = $parallel->normal_base;
60  
61 4 my $x = ($d**2 - $radii[1]**2 + $radii[0]**2) / (2 * $d);
62 4 my $rad = $radii[0]**2 - $x**2;
63 4 ▶ return if($rad < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $rad < 0 0 4 4
64  
65 4 my $y = sqrt($rad);
66 4 return($center_p[0] + $parallel * $x + $normal * $y,
67 $center_p[0] + $parallel * $x - $normal * $y);
68 }
69  
70 ###########################################################################
71 # #
72 # Change Data #
73 # #
74 ###########################################################################
75  
76 8 ▶sub register_derived_point {
Subroutine register_derived_point: called CC=2 SCAR=6.9
Pod undocumented
77 8 my ($self, $point) = @_;
78  
79 8 foreach($self->input) { $_->register_point($point) }
80 }
81  
82 3 1;
83  
84  
85 __END__
« Construction.pm ↑ Summary Construction/Role/Input.pm »