Primitive/Polygon.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 100% 45 / 45 CC 3 SCAR 3.4
CC
3
Cov
100%
area
2.0
scale
2.0
BEGIN
1.0
CRAP 1.4
« Primitive/Circle.pm ↑ Summary Primitive/Dimension.pm »
1 package Geometry::Primitive::Polygon;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use MooseX::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 with qw(Geometry::Primitive::Shape MooseX::Clone MooseX::Storage::Deferred);
6  
7 has 'points' => (
8 traits => [ qw(Array Clone) ],
9 is => 'rw',
10 isa => 'ArrayRef[Geometry::Primitive::Point]',
11 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 2 handles => {
13 add_point => 'push',
14 clear_points=> 'clear',
15 get_point => 'get',
16 point_count => 'count'
17 }
18 );
19  
20 2 ▶sub area {
Subroutine area: called CC=2 SCAR=6.9
Pod documented
21 2 my ($self) = @_;
22  
23 # http://mathworld.wolfram.com/PolygonArea.html
24 2 my $area = 0;
25 2 my $last = $self->get_point(0);
26 2 ▶ for (my $i = 1; $i < $self->point_count; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->point_count) 8 2 10
27 8 my $curr = $self->get_point($i);
28  
29 8 $area += ($last->x * $curr->y) - ($curr->x * $last->y);
30 8 $last = $curr;
31 }
32  
33 2 return abs($area / 2);
34 }
35  
36 1 ▶sub point_end {
Subroutine point_end: called CC=1 SCAR=0.0
Pod documented
37 1 my ($self) = @_;
38  
39 1 return $self->get_point($self->point_count - 1);
40 }
41  
42 1 ▶sub point_start {
Subroutine point_start: called CC=1 SCAR=0.0
Pod documented
43 1 my ($self) = @_;
44  
45 1 return $self->get_point(0);
46 }
47  
48 1 ▶sub scale {
Subroutine scale: called CC=2 SCAR=6.9
Pod documented
49 1 my ($self, $amount) = @_;
50  
51 1 foreach my $p (@{ $self->points }) {
52 5 $p->x($p->x * $amount);
53 5 $p->y($p->y * $amount);
54 }
55  
56 }
57  
58 2 __PACKAGE__->meta->make_immutable;
59  
60 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 1;
62  
63 __END__
« Primitive/Circle.pm ↑ Summary Primitive/Dimension.pm »