| 1 | package Geometry::Primitive::Line; | ||||||||||||||||||||||||||||
| 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 | 2 | ▶ | use overload ('""' => 'to_string'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Geometry::Primitive::Point; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | has 'start' => ( | |||||||||||||||||||||||||||
| 12 | is => 'rw', | ||||||||||||||||||||||||||||
| 13 | isa => 'Geometry::Primitive::Point', | ||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||
| 15 | coerce => 1 | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | has 'end' => ( | |||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | isa => 'Geometry::Primitive::Point', | ||||||||||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||||||||||
| 22 | coerce => 1 | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub contains_point { | ||||||||||||||||||||||||||
|
Subroutine
contains_point: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 2 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | my $point; | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | if(!ref($x) && defined($y)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $x and defined $y
MC/DC0%0/2
not ref $x and defined $y
not ref $x
defined $y
Truth table33%1/3
not(A) and B
A= not ref $xB= defined $y
| |||||||||||||||||||||||||||||
| 30 | # This allows the user to pass in $x and $y as scalars, which | ||||||||||||||||||||||||||||
| 31 | # easier sometimes. | ||||||||||||||||||||||||||||
| 32 | 2 | $point = Geometry::Primitive::Point->new(x => $x, y => $y); | |||||||||||||||||||||||||||
| 33 | } else { | ||||||||||||||||||||||||||||
| 34 | 0 | $point = $x; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | my $expy = ($self->slope * $point->x) + $self->y_intercept; | |||||||||||||||||||||||||||
| 38 | 2 | return $expy == $point->y; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Don't know how to do this atm. | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub scale { } | ||||||||||||||||||||||||||
|
Subroutine
scale: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub is_parallel { | ||||||||||||||||||||||||||
|
Subroutine
is_parallel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | return $line->slope == $self->slope; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | sub is_perpendicular { | ||||||||||||||||||||||||||
|
Subroutine
is_perpendicular: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 3 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | my $slope = $self->slope; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Deal with horizontal and vertical lines | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if(!defined($slope)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | return $line->slope == 0; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if($slope == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | return !defined($line->slope); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | return $line->slope == (-1 / $self->slope); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub length { | ||||||||||||||||||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | return sqrt(($self->end->x - $self->start->x) ** 2 | |||||||||||||||||||||||||||
| 70 | + ($self->end->y - $self->start->y) ** 2); | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub point_end { | ||||||||||||||||||||||||||
|
Subroutine
point_end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 1 | my ($self) = @_; return $self->end; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | sub point_start { | ||||||||||||||||||||||||||
|
Subroutine
point_start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 1 | my ($self) = @_; return $self->start; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 16 | ▶ | sub slope { | ||||||||||||||||||||||||||
|
Subroutine
slope: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 16 | my $end = $self->end; | |||||||||||||||||||||||||||
| 85 | 16 | my $start = $self->start; | |||||||||||||||||||||||||||
| 86 | 16 | my $x = $end->x - $start->x; | |||||||||||||||||||||||||||
| 87 | 16 | my $y = $end->y - $start->y; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 16 | ▶ | if($x == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 3 | return undef; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 13 | return $y / $x; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 2 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | return $self->start->to_string." - ".$self->end->to_string; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | ▶ | sub y_intercept { | ||||||||||||||||||||||||||
|
Subroutine
y_intercept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | return $self->start->y - ($self->slope * $self->start->x); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 2 | 1; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||