lib/SVG/Estimate/Path.pm

filter: Statementstmt 98.8% 82 / 83 Branchbran 72.2% 26 / 36 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 14 / 14 Podpod 50.0% 1 / 2 totaltotal 87.5% 127 / 145 CC 22 SCAR 27.6
CC
22
Cov
89%
BUILDARGS
24.5
BEGIN
1.0
BEGIN
1.0
CRAP 15.8
« blib/lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Path/Moveto.pm »
1 package SVG::Estimate::Path;
2 3 $SVG::Estimate::Path::VERSION = '1.0116';
3 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Image::SVG::Path qw/extract_path_info/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use SVG::Estimate::Path::Moveto;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use SVG::Estimate::Path::Lineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use SVG::Estimate::Path::CubicBezier;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use SVG::Estimate::Path::QuadraticBezier;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use SVG::Estimate::Path::HorizontalLineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use SVG::Estimate::Path::VerticalLineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use SVG::Estimate::Path::Arc;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Clone qw/clone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 extends 'SVG::Estimate::Shape';
16  
17 =head1 NAME
18  
19 SVG::Estimate::Path - Handles estimating arbitrary vectors.
20  
21 =head1 VERSION
22  
23 version 1.0116
24  
25 =head1 SYNOPSIS
26  
27 my $path = SVG::Estimate::Path->new(
28 transformer => $transform,
29 start_point => [45,13],
30 d => 'M150 0 L75 200 L225 200 Z',
31 );
32  
33 my $length = $path->length;
34  
35 =head1 INHERITANCE
36  
37 This class extends L<SVG::Estimate::Shape>.
38  
39 =head1 METHODS
40  
41 =head2 new()
42  
43 Constructor.
44  
45 =over
46  
47 =item d
48  
49 An SVG path string as described L<http://www.w3.org/TR/SVG/paths.html>.
50  
51 =back
52  
53 =cut
54  
55 3 has d => ( is => 'ro', required => 1, );
56 3 has commands => ( is => 'ro', );
57 3 has internal_travel_length => ( is => 'ro', required => 1, );
58 7 ▶has summarize => ( is => 'ro', default => sub { 0 }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
59  
60 sub BUILDARGS {
61 7 ▶ my ($class, @args) = @_;
Subroutine BUILDARGS: called CC=22 SCAR=32.0
Pod undocumented
62 ##Upgrade to hashref
63 7 ▶ my $args = @args % 2 ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 0 7 7
64  
65 7 ▶ if (! exists $args->{d} || $args->{d} =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/) 2 5 7
Condition66%2/3
not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/
l!l&&r!l&&!r
025
MC/DC50%1/2
not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/
not exists $args->{"d"} $args->{"d"} =~ /^\s*$/
Truth table66%2/3
not(A) or B
A= not exists $args->{"d"}B= $args->{"d"} =~ /^\s*$/
ABresult
1X1
011
000
66 2 $args->{d} = "m 0 0";
67 }
68 7 my @path_info = extract_path_info($args->{d}, { absolute => 1, no_shortcuts=> 1, });
69 7 my @commands = ();
70  
71 7 my $first_flag = 1;
72 7 my $first;
73 7 my $cursor = clone $args->{start_point};
74 7 $args->{length} = 0;
75 7 foreach my $subpath (@path_info) {
76 30 $subpath->{transformer} = $args->{transformer};
77 ##On the first command, set the start point to the moveto destination, otherwise the travel length gets counted twice.
78 30 $subpath->{start_point} = clone $cursor;
79 my $command = $subpath->{type} eq 'moveto' ? SVG::Estimate::Path::Moveto->new($subpath)
80 : $subpath->{type} eq 'line-to' ? SVG::Estimate::Path::Lineto->new($subpath)
81 : $subpath->{type} eq 'cubic-bezier' ? SVG::Estimate::Path::CubicBezier->new($subpath)
82 : $subpath->{type} eq 'quadratic-bezier' ? SVG::Estimate::Path::QuadraticBezier->new($subpath)
83 : $subpath->{type} eq 'horizontal-line-to' ? SVG::Estimate::Path::HorizontalLineto->new($subpath)
84 : $subpath->{type} eq 'vertical-line-to' ? SVG::Estimate::Path::VerticalLineto->new($subpath)
85 : $subpath->{type} eq 'arc' ? SVG::Estimate::Path::Arc->new($subpath)
86 : $subpath->{type} eq 'closepath' ? '' #Placeholder so we don't fall through
87 30 ▶ : ouch('unknown_path', "Unknown subpath type ".$subpath->{type}) ; ##Something bad happened
Branch: 8 branches
BranchTrueFalseTotal
$subpath->{'type'} eq 'moveto' ? : 9 21 30
$subpath->{'type'} eq 'line-to' ? : 17 4 21
$subpath->{'type'} eq 'cubic-bezier' ? : 0 4 4
$subpath->{'type'} eq 'quadratic-bezier' ? : 0 4 4
$subpath->{'type'} eq 'horizontal-line-to' ? : 0 4 4
$subpath->{'type'} eq 'vertical-line-to' ? : 0 4 4
$subpath->{'type'} eq 'arc' ? : 0 4 4
$subpath->{'type'} eq 'closepath' ? : 4 0 4
88 30 ▶ if ($subpath->{type} eq 'closepath') {
Branch: 1 branch
BranchTrueFalseTotal
if ($subpath->{"type"} eq "closepath") 4 26 30
89 4 $subpath->{point} = clone $first->point;
90 4 $command = SVG::Estimate::Path::Lineto->new($subpath);
91 }
92 30 $cursor = clone $command->end_point;
93 30 ▶ if ($first_flag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($first_flag) { } 7 23 30
elsif ($subpath->{'type'} eq 'moveto') { } 2 21 23
94 ##Save the first point in order to handle a closepath, if it exists
95 7 $first_flag = 0;
96 7 $first = $command; ##According to SVG, this will be a Moveto.
97 7 $args->{min_x} = $command->min_x;
98 7 $args->{max_x} = $command->max_x;
99 7 $args->{min_y} = $command->min_y;
100 7 $args->{max_y} = $command->max_y;
101 7 $args->{draw_start} = $command->end_point;
102 }
103 elsif ($subpath->{type} eq 'moveto') {
104 2 $first = $command; ##Save for the next close, if it comes
105 }
106 30 $args->{shape_length} += $command->shape_length;
107 30 $args->{internal_travel_length} += $command->travel_length;
108 30 ▶ $args->{min_x} = $command->min_x if $command->min_x < $args->{min_x};
Branch: 1 branch
BranchTrueFalseTotal
if $command->min_x < $args->{"min_x"} 0 30 30
109 30 ▶ $args->{max_x} = $command->max_x if $command->max_x > $args->{max_x};
Branch: 1 branch
BranchTrueFalseTotal
if $command->max_x > $args->{"max_x"} 8 22 30
110 30 ▶ $args->{min_y} = $command->min_y if $command->min_y < $args->{min_y};
Branch: 1 branch
BranchTrueFalseTotal
if $command->min_y < $args->{"min_y"} 0 30 30
111 30 ▶ $args->{max_y} = $command->max_y if $command->max_y > $args->{max_y};
Branch: 1 branch
BranchTrueFalseTotal
if $command->max_y > $args->{"max_y"} 6 24 30
112 30 ▶ if (exists $args->{summarize} && $args->{summarize}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"summarize"} and $args->{"summarize"}) 0 30 30
Condition33%1/3
exists $args->{"summarize"} and $args->{"summarize"}
!ll&&!rl&&r
3000
MC/DC0%0/2
exists $args->{"summarize"} and $args->{"summarize"}
exists $args->{"summarize"} $args->{"summarize"}
Truth table33%1/3
A and B
A= exists $args->{"summarize"}B= $args->{"summarize"}
ABresult
0X0
100
111
113 0 $command->summarize_myself;
114 }
115 30 push @commands, $command;
116 }
117 7 $args->{draw_end} = $cursor;
118  
119 7 $args->{commands} = \@commands;
120 7 return $args;
121 }
122  
123 ##Return the internally calculated travel length, not the standard one use by SVG::Estimate::Shape
124 sub travel_length {
125 9 ▶ my $self = shift;
Subroutine travel_length: called CC=1 SCAR=0.0
Pod documented
126 9 my $length = $self->internal_travel_length;
127 9 return $length;
128 }
129  
130 3 1;
« blib/lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Path/Moveto.pm »