line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Estimate::Rect; |
2
|
|
|
|
|
|
|
$SVG::Estimate::Rect::VERSION = '1.0113'; |
3
|
9
|
|
|
9
|
|
2029
|
use Moo; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
57
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'SVG::Estimate::Shape'; |
6
|
|
|
|
|
|
|
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.0113 |
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. |
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
|
|
|
|
|
|
|
default => sub { 0 }, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has y => ( |
67
|
|
|
|
|
|
|
is => 'ro', |
68
|
|
|
|
|
|
|
default => sub { 0 }, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has width => ( |
72
|
|
|
|
|
|
|
is => 'ro', |
73
|
|
|
|
|
|
|
required => 1, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has height => ( |
77
|
|
|
|
|
|
|
is => 'ro', |
78
|
|
|
|
|
|
|
required => 1, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub BUILDARGS { |
82
|
|
|
|
|
|
|
my ($class, @args) = @_; |
83
|
|
|
|
|
|
|
##Upgrade to hashref |
84
|
|
|
|
|
|
|
my $args = @args % 2 ? $args[0] : { @args }; |
85
|
|
|
|
|
|
|
$args->{x} //= 0; |
86
|
|
|
|
|
|
|
$args->{y} //= 0; |
87
|
|
|
|
|
|
|
my $origin = [ $args->{x}, $args->{y} ]; |
88
|
|
|
|
|
|
|
my $opposite = [ $args->{x} + $args->{width}, $args->{y} + $args->{height} ]; |
89
|
|
|
|
|
|
|
if ($args->{transformer}->has_transforms) { |
90
|
|
|
|
|
|
|
$origin = $args->{transformer}->transform($origin); |
91
|
|
|
|
|
|
|
$opposite = $args->{transformer}->transform($opposite); |
92
|
|
|
|
|
|
|
$args->{x} = $origin->[0] < $opposite->[0] ? $origin->[0] : $opposite->[0]; |
93
|
|
|
|
|
|
|
$args->{y} = $origin->[1] < $opposite->[1] ? $origin->[1] : $opposite->[1]; |
94
|
|
|
|
|
|
|
$args->{width} = abs($opposite->[0] - $origin->[0]); |
95
|
|
|
|
|
|
|
$args->{height} = abs($opposite->[1] - $origin->[1]); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
$args->{draw_start} = $origin; |
98
|
|
|
|
|
|
|
$args->{draw_end} = $origin; |
99
|
|
|
|
|
|
|
my $disabled = $args->{width} == 0 || $args->{height} == 0; |
100
|
|
|
|
|
|
|
$args->{shape_length} = $disabled ? 0 : ($args->{width} + $args->{height}) * 2; |
101
|
|
|
|
|
|
|
$args->{min_x} = $origin->[0]; |
102
|
|
|
|
|
|
|
$args->{min_y} = $origin->[1]; |
103
|
|
|
|
|
|
|
$args->{max_x} = $opposite->[0]; |
104
|
|
|
|
|
|
|
$args->{max_y} = $opposite->[1]; |
105
|
|
|
|
|
|
|
return $args; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub args_with_units { |
109
|
394
|
|
|
394
|
0
|
718
|
return qw/width height/; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |