| 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
| |||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 7 | ▶ | if (! exists $args->{d} || $args->{d} =~ /^\s*$/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $args->{"d"} or $args->{"d"} =~ /^\s*$/
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*$/
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 88 | 30 | ▶ | if ($subpath->{type} eq 'closepath') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 109 | 30 | ▶ | $args->{max_x} = $command->max_x if $command->max_x > $args->{max_x}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 110 | 30 | ▶ | $args->{min_y} = $command->min_y if $command->min_y < $args->{min_y}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 111 | 30 | ▶ | $args->{max_y} = $command->max_y if $command->max_y > $args->{max_y}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 112 | 30 | ▶ | if (exists $args->{summarize} && $args->{summarize}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args->{"summarize"} and $args->{"summarize"}
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"}
| |||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||