lib/SVG/Estimate/Role/SegmentLength.pm

filter: Statementstmt 100% 24 / 24 Branchbran 80.0% 8 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 95.3% 41 / 43 CC 7 SCAR 17.4
CC
7
Cov
95%
segment_length
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« lib/SVG/Estimate/Path/Lineto.pm ↑ Summary blib/lib/SVG/Estimate/Path/QuadraticBezier.pm »
1 package SVG::Estimate::Role::SegmentLength;
2 9 $SVG::Estimate::Role::SegmentLength::VERSION = '1.0116';
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 SVG::Estimate::Role::SegmentLength - Estimate the distance along a curve
9  
10 =head1 VERSION
11  
12 version 1.0116
13  
14 =head1 METHODS
15  
16 =head2 segment_length ( args, t0, t1, start_point, end_point, tolerance, minimum_iterations, current_iteration)
17  
18 Calculate the distance along a curve using straight line approximations along segments of the curve
19  
20 =cut
21  
22 sub segment_length {
23 1610 ▶ my $class = shift;
Subroutine segment_length: called CC=7 SCAR=19.5
Pod documented
24 1610 my ($args, $t0, $t1, $start, $end, $error, $min_depth, $depth) = @_;
25 1610 my $th = ($t1 + $t0) / 2; ##half-way
26 1610 my $mid = $class->this_point($args, $th);
27 1610 ▶ $args->{min_x} = $mid->[0] if $mid->[0] < $args->{min_x};
Branch: 1 branch
BranchTrueFalseTotal
if $mid->[0] < $args->{"min_x"} 4 1606 1610
28 1610 ▶ $args->{max_x} = $mid->[0] if $mid->[0] > $args->{max_x};
Branch: 1 branch
BranchTrueFalseTotal
if $mid->[0] > $args->{"max_x"} 0 1610 1610
29 1610 ▶ $args->{min_y} = $mid->[1] if $mid->[1] < $args->{min_y};
Branch: 1 branch
BranchTrueFalseTotal
if $mid->[1] < $args->{"min_y"} 0 1610 1610
30 1610 ▶ $args->{max_y} = $mid->[1] if $mid->[1] > $args->{max_y};
Branch: 1 branch
BranchTrueFalseTotal
if $mid->[1] > $args->{"max_y"} 6 1604 1610
31 1610 my $length = $class->pythagorean($start, $end); ##Segment from start to end
32 1610 my $left = $class->pythagorean($start, $mid);
33 1610 my $right = $class->pythagorean($mid, $end);
34 1610 my $length2 = $left + $right; ##Sum of segments through midpoint
35 1610 ▶ if ($length2 - $length > $error || $depth < $min_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length2 - $length > $error or $depth < $min_depth) 802 808 1610
Condition100%3/3
$length2 - $length > $error or $depth < $min_depth
l!l&&r!l&&!r
411391808
MC/DC100%2/2
$length2 - $length > $error or $depth < $min_depth
$length2 - $length > $error $depth < $min_depth
Truth table100%3/3
A or B
A= $length2 - $length > $errorB= $depth < $min_depth
ABresult
1X1
011
000
36 802 ++$depth;
37 802 return $class->segment_length($args, $t0, $th, $start, $mid, $error, $min_depth, $depth)
38 + $class->segment_length($args, $th, $t1, $mid, $end, $error, $min_depth, $depth)
39 }
40 808 return $length2;
41 }
42  
43 9 1;
« lib/SVG/Estimate/Path/Lineto.pm ↑ Summary blib/lib/SVG/Estimate/Path/QuadraticBezier.pm »