line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
48832
|
use strict; |
|
9
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
235
|
|
2
|
9
|
|
|
9
|
|
43
|
use warnings; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
410
|
|
3
|
|
|
|
|
|
|
package Math::Shape::Utils; |
4
|
|
|
|
|
|
|
$Math::Shape::Utils::VERSION = '0.15'; |
5
|
9
|
|
|
9
|
|
1704176
|
use Math::Trig ':pi'; |
|
9
|
|
|
|
|
3944507
|
|
|
9
|
|
|
|
|
1340
|
|
6
|
9
|
|
|
9
|
|
100
|
use Carp 'croak'; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
544
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Utility methods used by the Math::Shape::Vector module |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
9
|
|
|
9
|
|
50
|
require Exporter; |
12
|
9
|
|
|
9
|
|
45
|
use base qw(Exporter); |
|
9
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
1156
|
|
13
|
9
|
|
|
|
|
31
|
our @EXPORT = qw(degrees_to_radians radians_to_degrees overlap equal_floats minimum maximum clamp_on_range); |
14
|
9
|
|
|
|
|
2569
|
our @EXPORT_OK = (); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub degrees_to_radians |
18
|
|
|
|
|
|
|
{ |
19
|
4
|
|
|
4
|
0
|
25
|
$_[0] * pi / 180.0; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub radians_to_degrees |
23
|
|
|
|
|
|
|
{ |
24
|
5
|
|
|
5
|
0
|
28
|
$_[0] / pi * 180.0; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub overlap |
28
|
|
|
|
|
|
|
{ |
29
|
70
|
|
|
70
|
0
|
108
|
my ($minA, $maxA, $minB, $maxB) = @_; |
30
|
70
|
100
|
100
|
|
|
681
|
$minB <= $maxA && $minA <= $maxB ? 1 : 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub equal_floats |
34
|
|
|
|
|
|
|
{ |
35
|
39
|
|
|
39
|
0
|
50
|
my $threshold = 1.0 / 8192.0; |
36
|
39
|
100
|
|
|
|
283
|
abs($_[0] - $_[1]) < $threshold ? 1 : 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub minimum |
40
|
|
|
|
|
|
|
{ |
41
|
53
|
100
|
|
53
|
0
|
170
|
$_[0] < $_[1] ? $_[0] : $_[1]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub maximum |
45
|
|
|
|
|
|
|
{ |
46
|
53
|
100
|
|
53
|
0
|
190
|
$_[0] > $_[1] ? $_[0] : $_[1]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub clamp_on_range |
50
|
|
|
|
|
|
|
{ |
51
|
27
|
50
|
|
27
|
0
|
64
|
croak 'clamp_on_range() called without enough args. It requires 3 arguments: x, min & max' unless @_ == 3; |
52
|
27
|
|
|
|
|
34
|
my ($x, $min, $max) = @_; |
53
|
|
|
|
|
|
|
|
54
|
27
|
100
|
|
|
|
68
|
if ($x < $min) |
|
|
100
|
|
|
|
|
|
55
|
|
|
|
|
|
|
{ |
56
|
5
|
|
|
|
|
15
|
$min; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ($x > $max) |
59
|
|
|
|
|
|
|
{ |
60
|
4
|
|
|
|
|
13
|
$max; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else |
63
|
|
|
|
|
|
|
{ |
64
|
18
|
|
|
|
|
43
|
$x; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |