| 1 | package SVG::Estimate::Rect; | ||||||||||||||||||||
| 2 | 3 | $SVG::Estimate::Rect::VERSION = '1.0111'; | |||||||||||||||||||
| 3 | 3 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | extends 'SVG::Estimate::Shape'; | |||||||||||||||||||
| 6 | 3 | with 'SVG::Estimate::Role::ArgsWithUnits'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | SVG::Estimate::Rect - Handles estimating rectangles. | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | version 1.0111 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | my $rect = SVG::Estimate::Rect->new( | ||||||||||||||||||||
| 19 | transformer => $transform, | ||||||||||||||||||||
| 20 | start_point => [45,13], | ||||||||||||||||||||
| 21 | x => 3, | ||||||||||||||||||||
| 22 | y => 6, | ||||||||||||||||||||
| 23 | width => 11.76, | ||||||||||||||||||||
| 24 | height => 15.519, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | my $length = $rect->length; | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head1 INHERITANCE | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | This class extends L<SVG::Estimate::Shape>. | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =head1 METHODS | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head2 new() | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | Constructor. | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =over | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =item x | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | Float representing the top left corner x. | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =item y | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | Float representing the top left corner y. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =item width | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | Float representing the width of the box. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =item height | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | Float representing the height of the box. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =back | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | has x => ( | ||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||
| 63 | 0 | ▶ | default => sub { 0 }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 64 | 3 | ); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | has y => ( | ||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||
| 68 | 0 | ▶ | default => sub { 0 }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 69 | 3 | ); | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 3 | has width => ( | |||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||
| 73 | required => 1, | ||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 3 | has height => ( | |||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||
| 78 | required => 1, | ||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub BUILDARGS { | ||||||||||||||||||||
| 82 | 5 | ▶ | my ($class, @args) = @_; | ||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||
| 83 | ##Upgrade to hashref | ||||||||||||||||||||
| 84 | 5 | ▶ | my $args = @args % 2 ? $args[0] : { @args }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 5 | ▶ | $args->{x} //= 0; | ||||||||||||||||||
|
Condition100%2/2
$args->{"x"} //= 0
MC/DC100%1/1
$args->{"x"} //= 0
$args->{"x"}
Truth table100%2/2
A
A= $args->{"x"}
| |||||||||||||||||||||
| 86 | 5 | ▶ | $args->{y} //= 0; | ||||||||||||||||||
|
Condition100%2/2
$args->{"y"} //= 0
MC/DC100%1/1
$args->{"y"} //= 0
$args->{"y"}
Truth table100%2/2
A
A= $args->{"y"}
| |||||||||||||||||||||
| 87 | 5 | my $origin = [ $args->{x}, $args->{y} ]; | |||||||||||||||||||
| 88 | 5 | my $opposite = [ $args->{x} + $args->{width}, $args->{y} + $args->{height} ]; | |||||||||||||||||||
| 89 | 5 | ▶ | if ($args->{transformer}->has_transforms) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 2 | $origin = $args->{transformer}->transform($origin); | |||||||||||||||||||
| 91 | 2 | $opposite = $args->{transformer}->transform($opposite); | |||||||||||||||||||
| 92 | 2 | ▶ | $args->{x} = $origin->[0] < $opposite->[0] ? $origin->[0] : $opposite->[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 2 | ▶ | $args->{y} = $origin->[1] < $opposite->[1] ? $origin->[1] : $opposite->[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 2 | $args->{width} = abs($opposite->[0] - $origin->[0]); | |||||||||||||||||||
| 95 | 2 | $args->{height} = abs($opposite->[1] - $origin->[1]); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | 5 | $args->{draw_start} = $origin; | |||||||||||||||||||
| 98 | 5 | $args->{draw_end} = $origin; | |||||||||||||||||||
| 99 | 5 | ▶ | my $disabled = $args->{width} == 0 || $args->{height} == 0; | ||||||||||||||||||
|
Condition66%2/3
$args->{'width'} == 0 || $args->{'height'} == 0
MC/DC50%1/2
$args->{'width'} == 0 || $args->{'height'} == 0
$args->{'width'} == 0
$args->{'height'} == 0
Truth table66%2/3
A || B
A= $args->{'width'} == 0B= $args->{'height'} == 0
| |||||||||||||||||||||
| 100 | 5 | ▶ | $args->{shape_length} = $disabled ? 0 : ($args->{width} + $args->{height}) * 2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 5 | $args->{min_x} = $origin->[0]; | |||||||||||||||||||
| 102 | 5 | $args->{min_y} = $origin->[1]; | |||||||||||||||||||
| 103 | 5 | $args->{max_x} = $opposite->[0]; | |||||||||||||||||||
| 104 | 5 | $args->{max_y} = $opposite->[1]; | |||||||||||||||||||
| 105 | 5 | return $args; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | sub args_with_units { | ||||||||||||||||||||
| 109 | 7 | ▶ | return qw/width height/; | ||||||||||||||||||
|
Subroutine
args_with_units: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 3 | 1; | |||||||||||||||||||