lib/SVG/Estimate/Rect.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 90.0% 9 / 10 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 85.9% 55 / 64 CC 9 SCAR 19.0
CC
9
Cov
92%
BUILDARGS
9.0
__ANON__
2.0
__ANON__
2.0
CRAP 6.7
« lib/SVG/Estimate/Path/Arc.pm ↑ Summary lib/SVG/Estimate/Path/HorizontalLineto.pm »
1 package SVG::Estimate::Rect;
2 3 $SVG::Estimate::Rect::VERSION = '1.0116';
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.0116
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
BranchTrueFalseTotal
@args % 2 ? : 5 0 5
85 5 ▶ $args->{x} //= 0;
Condition100%2/2
$args->{"x"} //= 0
l!l
41
MC/DC100%1/1
$args->{"x"} //= 0
$args->{"x"}
Truth table100%2/2
A
A= $args->{"x"}
Aresult
11
00
86 5 ▶ $args->{y} //= 0;
Condition100%2/2
$args->{"y"} //= 0
l!l
41
MC/DC100%1/1
$args->{"y"} //= 0
$args->{"y"}
Truth table100%2/2
A
A= $args->{"y"}
Aresult
11
00
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
BranchTrueFalseTotal
if ($args->{"transformer"}->has_transforms) 2 3 5
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
BranchTrueFalseTotal
$origin->[0] < $opposite->[0] ? : 1 1 2
93 2 ▶ $args->{y} = $origin->[1] < $opposite->[1] ? $origin->[1] : $opposite->[1];
Branch: 1 branch
BranchTrueFalseTotal
$origin->[1] < $opposite->[1] ? : 1 1 2
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
l!l&&r!l&&!r
014
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
ABresult
1X1
011
000
100 5 ▶ $args->{shape_length} = $disabled ? 0 : ($args->{width} + $args->{height}) * 2;
Branch: 1 branch
BranchTrueFalseTotal
$disabled ? : 1 4 5
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;
« lib/SVG/Estimate/Path/Arc.pm ↑ Summary lib/SVG/Estimate/Path/HorizontalLineto.pm »