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