lib/SVG/Estimate/Path/CubicBezier.pm

filter: Statementstmt 100% 41 / 41 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 88.5% 54 / 61 CC 7 SCAR 15.4
CC
7
Cov
91%
BUILDARGS
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
« lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Role/Round.pm »
1 package SVG::Estimate::Path::CubicBezier;
2 4 $SVG::Estimate::Path::CubicBezier::VERSION = '1.0111';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use List::Util qw/min max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Clone qw/clone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 extends 'SVG::Estimate::Path::Command';
8 4 with 'SVG::Estimate::Role::Pythagorean';
9 4 with 'SVG::Estimate::Role::SegmentLength';
10 4 with 'SVG::Estimate::Role::EndToPoint';
11  
12 =head1 NAME
13  
14 SVG::Estimate::Path::CubicBezier - Handles estimating cubic bezier curves.
15  
16 =head1 VERSION
17  
18 version 1.0111
19  
20 =head1 SYNOPSIS
21  
22 my $curve = SVG::Estimate::Path::CubicBezier->new(
23 transformer => $transform,
24 start_point => [13, 19],
25 point => [45,13],
26 control1 => [10,3],
27 control2 => [157,40],
28 );
29  
30 my $length = $curve->length;
31  
32 =head1 INHERITANCE
33  
34 This class extends L<SVG::Estimate::Path::Command> and consumes L<SVG::Estimate::Role::Pythagorean>, L<SVG::Estimate::Role::SegmentLength>, and L<SVG::Estimate::Role::EndToPoint>.
35  
36 =head1 METHODS
37  
38 =head2 new()
39  
40 Constructor.
41  
42 =over
43  
44 =item point
45  
46 An array ref containing two floats that represent a point.
47  
48 =item control1
49  
50 An array ref containing two floats that represent a point.
51  
52 =item control2
53  
54 An array ref containing two floats that represent a point.
55  
56 =back
57  
58 =cut
59  
60 4 has point => (
61 is => 'ro',
62 required => 1,
63 );
64  
65 4 has control1 => (
66 is => 'ro',
67 required => 1,
68 );
69  
70 4 has control2 => (
71 is => 'ro',
72 required => 1,
73 );
74  
75 sub BUILDARGS {
76 2 ▶ my ($class, @args) = @_;
Subroutine BUILDARGS: called CC=7 SCAR=19.8
Pod undocumented
77 ##Upgrade to hashref
78 2 ▶ my $args = @args % 2 ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 2 0 2
79 2 ▶ if ($args->{transformer}->has_transforms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"transformer"}->has_transforms) 1 1 2
80 1 $args->{point} = $args->{transformer}->transform($args->{point});
81 1 $args->{control1} = $args->{transformer}->transform($args->{control1});
82 1 $args->{control2} = $args->{transformer}->transform($args->{control2});
83 }
84 2 $args->{end_point} = clone $args->{point};
85  
86 2 my $start = $class->this_point($args, 0);
87 2 my $end = $class->this_point($args, 1);
88 2 ▶ $args->{min_x} = $start->[0] < $end->[0] ? $start->[0] : $end->[0];
Branch: 1 branch
BranchTrueFalseTotal
$start->[0] < $end->[0] ? : 2 0 2
89 2 ▶ $args->{max_x} = $start->[0] > $end->[0] ? $start->[0] : $end->[0];
Branch: 1 branch
BranchTrueFalseTotal
$start->[0] > $end->[0] ? : 0 2 2
90 2 ▶ $args->{min_y} = $start->[1] < $end->[1] ? $start->[1] : $end->[1];
Branch: 1 branch
BranchTrueFalseTotal
$start->[1] < $end->[1] ? : 0 2 2
91 2 ▶ $args->{max_y} = $start->[1] > $end->[1] ? $start->[1] : $end->[1];
Branch: 1 branch
BranchTrueFalseTotal
$start->[1] > $end->[1] ? : 2 0 2
92  
93 2 $args->{shape_length} = $class->segment_length($args, 0, 1, $start, $end, 1e-4, 5, 0);
94 2 $args->{travel_length} = 0;
95  
96 2 return $args;
97 }
98  
99 sub _this_point {
100 1188 ▶ shift;
Subroutine _this_point: called CC=1 SCAR=0.0
101 1188 my ($t, $s, $c1, $c2, $p) = @_;
102 1188 return ((1 - $t)**3 * $s)
103 + (3 * (1 - $t)**2 * $t * $c1)
104 + (3 * (1 - $t) * $t**2 * $c2)
105 + ($t**3 * $p)
106 ;
107 }
108  
109 sub this_point {
110 594 ▶ my $class = shift;
Subroutine this_point: called CC=1 SCAR=0.0
Pod undocumented
111 594 my $args = shift;
112 594 my $t = shift;
113 return [
114 $class->_this_point($t, $args->{start_point}->[0], $args->{control1}->[0], $args->{control2}->[0], $args->{point}->[0]),
115 594 $class->_this_point($t, $args->{start_point}->[1], $args->{control1}->[1], $args->{control2}->[1], $args->{point}->[1])
116 ];
117 }
118  
119  
120 4 1;
« lib/SVG/Estimate/Role/SegmentLength.pm ↑ Summary blib/lib/SVG/Estimate/Role/Round.pm »