line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Estimate::Role::SegmentLength; |
2
|
|
|
|
|
|
|
$SVG::Estimate::Role::SegmentLength::VERSION = '1.0113'; |
3
|
12
|
|
|
12
|
|
4627
|
use strict; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
315
|
|
4
|
12
|
|
|
12
|
|
52
|
use Moo::Role; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
SVG::Estimate::Role::SegmentLength - Estimate the distance along a curve |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
version 1.0113 |
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
|
59705
|
|
|
59705
|
1
|
60528
|
my $class = shift; |
24
|
59705
|
|
|
|
|
74807
|
my ($args, $t0, $t1, $start, $end, $error, $min_depth, $depth) = @_; |
25
|
59705
|
|
|
|
|
61805
|
my $th = ($t1 + $t0) / 2; ##half-way |
26
|
59705
|
|
|
|
|
83338
|
my $mid = $class->this_point($args, $th); |
27
|
59705
|
100
|
|
|
|
99224
|
$args->{min_x} = $mid->[0] if $mid->[0] < $args->{min_x}; |
28
|
59705
|
100
|
|
|
|
76141
|
$args->{max_x} = $mid->[0] if $mid->[0] > $args->{max_x}; |
29
|
59705
|
100
|
|
|
|
76335
|
$args->{min_y} = $mid->[1] if $mid->[1] < $args->{min_y}; |
30
|
59705
|
100
|
|
|
|
71700
|
$args->{max_y} = $mid->[1] if $mid->[1] > $args->{max_y}; |
31
|
59705
|
|
|
|
|
84159
|
my $length = $class->pythagorean($start, $end); ##Segment from start to end |
32
|
59705
|
|
|
|
|
88849
|
my $left = $class->pythagorean($start, $mid); |
33
|
59705
|
|
|
|
|
83943
|
my $right = $class->pythagorean($mid, $end); |
34
|
59705
|
|
|
|
|
61863
|
my $length2 = $left + $right; ##Sum of segments through midpoint |
35
|
59705
|
100
|
100
|
|
|
131479
|
if ($length2 - $length > $error || $depth < $min_depth) { |
36
|
29388
|
|
|
|
|
25594
|
++$depth; |
37
|
29388
|
|
|
|
|
40808
|
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
|
30317
|
|
|
|
|
80305
|
return $length2; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |