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