lib/SVG/Estimate/Path.pm

filter: Statementstmt 98.7% 81 / 82 Branchbran 70.5% 24 / 34 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 14 / 14 Podpod 50.0% 1 / 2 totaltotal 87.3% 124 / 142 CC 21 SCAR 27.0
CC
21
Cov
89%
BUILDARGS
23.5
BEGIN
1.0
BEGIN
1.0
CRAP 14.9
« blib/lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Path/Moveto.pm »
1 package SVG::Estimate::Path;
2 2 $SVG::Estimate::Path::VERSION = '1.0111';
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Image::SVG::Path qw/extract_path_info/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use SVG::Estimate::Path::Moveto;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use SVG::Estimate::Path::Lineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use SVG::Estimate::Path::CubicBezier;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use SVG::Estimate::Path::QuadraticBezier;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use SVG::Estimate::Path::HorizontalLineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use SVG::Estimate::Path::VerticalLineto;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use SVG::Estimate::Path::Arc;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Clone qw/clone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 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.0111
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 2 has d => ( is => 'ro', required => 1, );
56 2 has commands => ( is => 'ro', );
57 2 has internal_travel_length => ( is => 'ro', required => 1, );
58 5 ▶has summarize => ( is => 'ro', default => sub { 0 }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
59  
60 sub BUILDARGS {
61 5 ▶ my ($class, @args) = @_;
Subroutine BUILDARGS: called CC=21 SCAR=31.6
Pod undocumented
62 ##Upgrade to hashref
63 5 ▶ my $args = @args % 2 ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 0 5 5
64  
65 5 ▶ if (! exists $args->{d} || $args->{d} =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/) 2 3 5
Condition66%2/3
not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/
l!l&&r!l&&!r
023
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 5 my @path_info = extract_path_info($args->{d}, { absolute => 1, no_shortcuts=> 1, });
69 5 my @commands = ();
70  
71 5 my $first_flag = 1;
72 5 my $first;
73 5 my $cursor = clone $args->{start_point};
74 5 $args->{length} = 0;
75 5 foreach my $subpath (@path_info) {
76 15 $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 15 $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 15 ▶ : ouch('unknown_path', "Unknown subpath type ".$subpath->{type}) ; ##Something bad happened
Branch: 8 branches
BranchTrueFalseTotal
$subpath->{'type'} eq 'moveto' ? : 6 9 15
$subpath->{'type'} eq 'line-to' ? : 7 2 9
$subpath->{'type'} eq 'cubic-bezier' ? : 0 2 2
$subpath->{'type'} eq 'quadratic-bezier' ? : 0 2 2
$subpath->{'type'} eq 'horizontal-line-to' ? : 0 2 2
$subpath->{'type'} eq 'vertical-line-to' ? : 0 2 2
$subpath->{'type'} eq 'arc' ? : 0 2 2
$subpath->{'type'} eq 'closepath' ? : 2 0 2
88 15 ▶ if ($subpath->{type} eq 'closepath') {
Branch: 1 branch
BranchTrueFalseTotal
if ($subpath->{"type"} eq "closepath") 2 13 15
89 2 $subpath->{point} = clone $first->point;
90 2 $command = SVG::Estimate::Path::Lineto->new($subpath);
91 }
92 15 $cursor = clone $command->end_point;
93 15 ▶ if ($first_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_flag) 5 10 15
94 ##Save the first point in order to handle a closepath, if it exists
95 5 $first_flag = 0;
96 5 $first = $command; ##According to SVG, this will be a Moveto.
97 5 $args->{min_x} = $command->min_x;
98 5 $args->{max_x} = $command->max_x;
99 5 $args->{min_y} = $command->min_y;
100 5 $args->{max_y} = $command->max_y;
101 5 $args->{draw_start} = $command->end_point;
102 }
103 15 $args->{shape_length} += $command->shape_length;
104 15 $args->{internal_travel_length} += $command->travel_length;
105 15 ▶ $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 15 15
106 15 ▶ $args->{max_x} = $command->max_x if $command->max_x > $args->{max_x};
Branch: 1 branch
BranchTrueFalseTotal
if $command->max_x > $args->{"max_x"} 4 11 15
107 15 ▶ $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 15 15
108 15 ▶ $args->{max_y} = $command->max_y if $command->max_y > $args->{max_y};
Branch: 1 branch
BranchTrueFalseTotal
if $command->max_y > $args->{"max_y"} 4 11 15
109 15 ▶ if (exists $args->{summarize} && $args->{summarize}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"summarize"} and $args->{"summarize"}) 0 15 15
Condition33%1/3
exists $args->{"summarize"} and $args->{"summarize"}
!ll&&!rl&&r
1500
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
110 0 $command->summarize_myself;
111 }
112 15 push @commands, $command;
113 }
114 5 $args->{draw_end} = $cursor;
115  
116 5 $args->{commands} = \@commands;
117 5 return $args;
118 }
119  
120 ##Return the internally calculated travel length, not the standard one use by SVG::Estimate::Shape
121 sub travel_length {
122 7 ▶ my $self = shift;
Subroutine travel_length: called CC=1 SCAR=0.0
Pod documented
123 7 my $length = $self->internal_travel_length;
124 7 return $length;
125 }
126  
127 2 1;
« blib/lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Path/Moveto.pm »