Utils.pm

filter: Statementstmt 100% 34 / 34 Branchbran 92.8% 13 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 7 totaltotal 89.0% 65 / 73 CC 9 SCAR 7.6
CC
9
Cov
98%
clamp_on_range
4.0
overlap
3.0
equal_floats
2.0
CRAP 2.1
« Vector.pm ↑ Summary Range.pm »
1 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Math::Shape::Utils;
4 9 $Math::Shape::Utils::VERSION = '0.15';
5 9 ▶use Math::Trig ':pi';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Utility methods used by the Math::Shape::Vector module
9  
10 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 require Exporter;
12 9 ▶ use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 our @EXPORT = qw(degrees_to_radians radians_to_degrees overlap equal_floats minimum maximum clamp_on_range);
14 9 our @EXPORT_OK = ();
15 }
16  
17 sub degrees_to_radians
18 4 ▶{
Subroutine degrees_to_radians: called CC=1 SCAR=0.0
Pod undocumented
19 4 $_[0] * pi / 180.0;
20 }
21  
22 sub radians_to_degrees
23 5 ▶{
Subroutine radians_to_degrees: called CC=1 SCAR=0.0
Pod undocumented
24 5 $_[0] / pi * 180.0;
25 }
26  
27 sub overlap
28 70 ▶{
Subroutine overlap: called CC=3 SCAR=11.0
Pod undocumented
29 70 my ($minA, $maxA, $minB, $maxB) = @_;
30 70 ▶ $minB <= $maxA && $minA <= $maxB ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$minB <= $maxA && $minA <= $maxB ? : 61 9 70
Condition100%3/3
$minB <= $maxA and $minA <= $maxB
!ll&&!rl&&r
6361
MC/DC100%2/2
$minB <= $maxA and $minA <= $maxB
$minB <= $maxA $minA <= $maxB
Truth table100%3/3
A and B
A= $minB <= $maxAB= $minA <= $maxB
ABresult
0X0
100
111
31 }
32  
33 sub equal_floats
34 39 ▶{
Subroutine equal_floats: called CC=2 SCAR=6.9
Pod undocumented
35 39 my $threshold = 1.0 / 8192.0;
36 39 ▶ abs($_[0] - $_[1]) < $threshold ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
abs $_[0] - $_[1] < $threshold ? : 24 15 39
37 }
38  
39 sub minimum
40 53 ▶{
Subroutine minimum: called CC=2 SCAR=6.9
Pod undocumented
41 53 ▶ $_[0] < $_[1] ? $_[0] : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < $_[1] ? : 30 23 53
42 }
43  
44 sub maximum
45 53 ▶{
Subroutine maximum: called CC=2 SCAR=6.9
Pod undocumented
46 53 ▶ $_[0] > $_[1] ? $_[0] : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > $_[1] ? : 32 21 53
47 }
48  
49 sub clamp_on_range
50 27 ▶{
Subroutine clamp_on_range: called CC=4 SCAR=13.9
Pod undocumented
51 27 ▶ croak 'clamp_on_range() called without enough args. It requires 3 arguments: x, min & max' unless @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 27 27
52 27 my ($x, $min, $max) = @_;
53  
54 27 ▶ if ($x < $min)
Branch: 2 branches
BranchTrueFalseTotal
if ($x < $min) { } 5 22 27
elsif ($x > $max) { } 4 18 22
55 {
56 5 $min;
57 }
58 elsif ($x > $max)
59 {
60 4 $max;
61 }
62 else
63 {
64 18 $x;
65 }
66 }
67  
68 9 1;
69  
70 __END__
« Vector.pm ↑ Summary Range.pm »