Line.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 84.6% 22 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 75.0% 3 / 4 totaltotal 92.5% 74 / 80 CC 14 SCAR 16.0
CC
14
Cov
93%
collides
9.0
is_equivalent
3.0
on_one_side
3.0
CRAP 4.9
« OrientedRectangle.pm ↑ Summary Vector.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Math::Shape::Line;
4 7 $Math::Shape::Line::VERSION = '0.15';
5 7 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Math::Shape::Vector;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: a 2d vector-based infinite line
10  
11  
12 39 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 39 ▶ croak 'incorrect number of args' unless @_ == 5;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 5 0 39 39
14 39 my ($class, $x1, $y1, $x2, $y2) = @_;
15 39 bless { base => Math::Shape::Vector->new($x1, $y1),
16 direction => Math::Shape::Vector->new($x2, $y2),
17 }, $class;
18 }
19  
20  
21 sub is_equivalent
22 8 ▶{
Subroutine is_equivalent: called CC=3 SCAR=11.0
Pod documented
23 8 ▶ croak 'must pass a line object' unless $_[1]->isa('Math::Shape::Line');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->isa("Math::Shape::Line") 0 8 8
24 8 ▶ unless( $_[0]->{direction}->is_parallel($_[1]->{direction}) )
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'direction'}->is_parallel($_[1]{'direction'})) { } 5 3 8
25 {
26 3 0;
27 }
28 else
29 {
30 5 my $base = $_[0]->{base}->subtract_vector($_[1]->{base});
31 5 $base->is_parallel($_[0]->{direction});
32 }
33 }
34  
35  
36 sub on_one_side
37 20 ▶{
Subroutine on_one_side: called CC=3 SCAR=11.0
Pod undocumented
38 20 ▶ croak 'project not called with argument of type Math::Shape::Line' unless $_[1]->isa('Math::Shape::LineSegment');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->isa("Math::Shape::LineSegment") 0 20 20
39 20 my ($self, $segment) = @_;
40  
41 20 my $vector_d1 = $segment->{start}->subtract_vector($self->{base});
42 20 my $vector_d2 = $segment->{end}->subtract_vector($self->{base});
43 20 my $vector_n = $self->{direction}->rotate_90;
44  
45 20 ▶ $vector_n->dot_product($vector_d1) * $vector_n->dot_product($vector_d2)
Branch: 1 branch
BranchTrueFalseTotal
$vector_n->dot_product($vector_d1) * $vector_n->dot_product($vector_d2) > 0 ? : 8 12 20
46 > 0 ? 1 : 0;
47 }
48  
49  
50  
51 sub collides
52 21 ▶{
Subroutine collides: called CC=9 SCAR=22.0
Pod documented
53 21 my ($self, $other_obj) = @_;
54  
55 21 ▶ if ($other_obj->isa('Math::Shape::Line'))
Branch: 6 branches
BranchTrueFalseTotal
if ($other_obj->isa('Math::Shape::Line')) { } 7 14 21
elsif ($other_obj->isa('Math::Shape::LineSegment')) { } 6 8 14
elsif ($other_obj->isa('Math::Shape::OrientedRectangle')) { } 2 6 8
elsif ($other_obj->isa('Math::Shape::Circle')) { } 2 4 6
elsif ($other_obj->isa('Math::Shape::Rectangle')) { } 2 2 4
elsif ($other_obj->isa('Math::Shape::Vector')) { } 2 0 2
56 {
57 7 ▶ if($self->{direction}->is_parallel($other_obj->{direction}))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'direction'}->is_parallel($other_obj->{'direction'})) { } 4 3 7
58 {
59 4 $self->is_equivalent($other_obj);
60 }
61 else
62 {
63 3 1;
64 }
65 }
66 elsif ($other_obj->isa('Math::Shape::LineSegment'))
67 {
68 6 ▶ $self->on_one_side($other_obj) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->on_one_side($other_obj) ? : 3 3 6
69 }
70 elsif ($other_obj->isa('Math::Shape::OrientedRectangle'))
71 {
72 2 $other_obj->collides($self);
73 }
74 elsif ($other_obj->isa('Math::Shape::Circle'))
75 {
76 2 $other_obj->collides($self);
77 }
78 elsif ($other_obj->isa('Math::Shape::Rectangle'))
79 {
80 2 $other_obj->collides($self);
81 }
82 elsif ($other_obj->isa('Math::Shape::Vector'))
83 {
84 2 $other_obj->collides($self);
85 }
86 else
87 {
88 0 croak 'collides must be called with a Math::Shape::Vector library object';
89 }
90 }
91  
92  
93  
94 7 1;
95  
96 __END__
« OrientedRectangle.pm ↑ Summary Vector.pm »