| 1 | package SVG::Estimate::Line; | ||||||||||||
| 2 | 2 | $SVG::Estimate::Line::VERSION = '1.0111'; | |||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | extends 'SVG::Estimate::Shape'; | |||||||||||
| 6 | 2 | with 'SVG::Estimate::Role::Pythagorean'; | |||||||||||
| 7 | |||||||||||||
| 8 | =head1 NAME | ||||||||||||
| 9 | |||||||||||||
| 10 | SVG::Estimate::Line - Handles estimating straight lines. | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 VERSION | ||||||||||||
| 13 | |||||||||||||
| 14 | version 1.0111 | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||
| 17 | |||||||||||||
| 18 | my $line = SVG::Estimate::Line->new( | ||||||||||||
| 19 | transformer => $transform, | ||||||||||||
| 20 | start_point => [45,13], | ||||||||||||
| 21 | x1 => 1, | ||||||||||||
| 22 | y1 => 3, | ||||||||||||
| 23 | x2 => 4.6, | ||||||||||||
| 24 | y2 => 3, | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | my $length = $line->length; | ||||||||||||
| 28 | |||||||||||||
| 29 | =head1 INHERITANCE | ||||||||||||
| 30 | |||||||||||||
| 31 | This class extends L<SVG::Estimate::Shape> and consumes L<SVG::Estimate::Role::Pythagorean>. | ||||||||||||
| 32 | |||||||||||||
| 33 | =head1 METHODS | ||||||||||||
| 34 | |||||||||||||
| 35 | =head2 new() | ||||||||||||
| 36 | |||||||||||||
| 37 | Constructor. | ||||||||||||
| 38 | |||||||||||||
| 39 | =over | ||||||||||||
| 40 | |||||||||||||
| 41 | =item x1 | ||||||||||||
| 42 | |||||||||||||
| 43 | Float representing the x start point. | ||||||||||||
| 44 | |||||||||||||
| 45 | =item y1 | ||||||||||||
| 46 | |||||||||||||
| 47 | Float representing the y start point. | ||||||||||||
| 48 | |||||||||||||
| 49 | =item x2 | ||||||||||||
| 50 | |||||||||||||
| 51 | Float representing the x end point. | ||||||||||||
| 52 | |||||||||||||
| 53 | =item y2 | ||||||||||||
| 54 | |||||||||||||
| 55 | Float representing the y end point. | ||||||||||||
| 56 | |||||||||||||
| 57 | =back | ||||||||||||
| 58 | |||||||||||||
| 59 | =cut | ||||||||||||
| 60 | |||||||||||||
| 61 | has x1 => ( | ||||||||||||
| 62 | is => 'ro', | ||||||||||||
| 63 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 64 | 2 | ); | |||||||||||
| 65 | |||||||||||||
| 66 | has y1 => ( | ||||||||||||
| 67 | is => 'ro', | ||||||||||||
| 68 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 69 | 2 | ); | |||||||||||
| 70 | |||||||||||||
| 71 | has x2 => ( | ||||||||||||
| 72 | is => 'ro', | ||||||||||||
| 73 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 74 | 2 | ); | |||||||||||
| 75 | |||||||||||||
| 76 | has y2 => ( | ||||||||||||
| 77 | is => 'ro', | ||||||||||||
| 78 | 0 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 79 | 2 | ); | |||||||||||
| 80 | |||||||||||||
| 81 | sub BUILDARGS { | ||||||||||||
| 82 | 4 | ▶ | my ($class, @args) = @_; | ||||||||||
|
Subroutine
BUILDARGS: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||
| 83 | ##Upgrade to hashref | ||||||||||||
| 84 | 4 | ▶ | my $args = @args % 2 ? $args[0] : { @args }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 4 | foreach my $arg (qw(x1 x2 y1 y2)) { | |||||||||||
| 86 | 16 | ▶ | $args->{$arg} //= 0; | ||||||||||
|
Condition50%1/2
$args->{$arg} //= 0
MC/DC0%0/1
$args->{$arg} //= 0
$args->{$arg}
Truth table50%1/2
A
A= $args->{$arg}
| |||||||||||||
| 87 | } | ||||||||||||
| 88 | 4 | ▶ | return $args unless exists $args->{transformer}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | 4 | my $point1 = $args->{transformer}->transform([$args->{x1}, $args->{y1}]); | |||||||||||
| 90 | 4 | my $point2 = $args->{transformer}->transform([$args->{x2}, $args->{y2}]); | |||||||||||
| 91 | 4 | $args->{x1} = $point1->[0]; | |||||||||||
| 92 | 4 | $args->{y1} = $point1->[1]; | |||||||||||
| 93 | 4 | $args->{x2} = $point2->[0]; | |||||||||||
| 94 | 4 | $args->{y2} = $point2->[1]; | |||||||||||
| 95 | 4 | $args->{draw_start} = $point1; | |||||||||||
| 96 | 4 | $args->{draw_end} = $point2; | |||||||||||
| 97 | 4 | ▶ | $args->{min_y} = $args->{y1} < $args->{y2} ? $args->{y1} : $args->{y2}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 4 | ▶ | $args->{max_y} = $args->{y1} > $args->{y2} ? $args->{y1} : $args->{y2}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 4 | ▶ | $args->{min_x} = $args->{x1} < $args->{x2} ? $args->{x1} : $args->{x2}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 4 | ▶ | $args->{max_x} = $args->{x1} > $args->{x2} ? $args->{x1} : $args->{x2}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 4 | $args->{shape_length} = $class->pythagorean($point1, $point2); | |||||||||||
| 102 | 4 | return $args; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 2 | 1; | |||||||||||