blib/lib/Term/Fabulous/Chart/Easing.pm

filter: Statementstmt 57.4% 31 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 34.6% 9 / 26 Podpod 100% 3 / 3 totaltotal 35.8% 43 / 120 CC 14 SCAR 21.2
CC
14
Cov
37%
_bounce_out
20.0
is_easing_name
20.0
easing
20.0
CRAP 8.3
« tools/lib/Term/Fabulous/Screenshot/Render/SVG.pm ↑ Summary blib/lib/Term/Fabulous/Unicode.pm »
1 package Term::Fabulous::Chart::Easing;
2  
3 1 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT_OK = qw(easing easing_names is_easing_name);
12  
13 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use constant PI => 4 * atan2( 1, 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # The "in" form of each family; "out" and "in-out" are derived from it,
18 # except where the classic formulas differ (back, elastic, bounce).
19 my %IN = (
20 0 ▶ sine => sub ($t) { 1 - cos( $t * PI / 2 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶ quad => sub ($t) { $t**2 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ cubic => sub ($t) { $t**3 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 ▶ quart => sub ($t) { $t**4 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ quint => sub ($t) { $t**5 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 ▶ expo => sub ($t) { $t <= 0 ? 0 : 2**( 10 * $t - 10 ) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$t <= 0 ? : 0 0 0
26 0 ▶ circ => sub ($t) { 1 - sqrt( 1 - $t**2 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 ▶ back => sub ($t) { 2.70158 * $t**3 - 1.70158 * $t**2 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 ▶ elastic => sub ($t) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
29 0 ▶ return $t if $t <= 0 || $t >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $t <= 0 or $t >= 1 0 0 0
Condition0%0/3
$t <= 0 or $t >= 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$t <= 0 or $t >= 1
$t <= 0 $t >= 1
Truth table0%0/3
A or B
A= $t <= 0B= $t >= 1
ABresult
1X1
011
000
30 0 return -( 2**( 10 * $t - 10 ) ) * sin( ( $t * 10 - 10.75 ) * ( 2 * PI ) / 3 );
31 },
32 0 ▶ bounce => sub ($t) { 1 - _bounce_out( 1 - $t ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 1 );
34  
35 0 ▶sub _bounce_out ($t) {
Subroutine _bounce_out: not called CC=4 SCAR=30.0
36 0 my ( $n, $d ) = ( 7.5625, 2.75 );
37 0 ▶ return $n * $t**2 if $t < 1 / $d;
Branch: 1 branch
BranchTrueFalseTotal
if $t < 1 / $d 0 0 0
38 0 ▶ return $n * ( $t - 1.5 / $d )**2 + 0.75 if $t < 2 / $d;
Branch: 1 branch
BranchTrueFalseTotal
if $t < 2 / $d 0 0 0
39 0 ▶ return $n * ( $t - 2.25 / $d )**2 + 0.9375 if $t < 2.5 / $d;
Branch: 1 branch
BranchTrueFalseTotal
if $t < "2.5" / $d 0 0 0
40 0 return $n * ( $t - 2.625 / $d )**2 + 0.984375;
41 }
42  
43 10 ▶sub _out ($in) {
Subroutine _out: called CC=1 SCAR=1.2
44 0 ▶ return sub ($t) { 1 - $in->( 1 - $t ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
45 }
46  
47 10 ▶sub _in_out ($in) {
Subroutine _in_out: called CC=1 SCAR=3.5
48 0 ▶ return sub ($t) { $t < 0.5 ? $in->( 2 * $t ) / 2 : 1 - $in->( 2 - 2 * $t ) / 2 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$t < 0.5 ? : 0 0 0
49 }
50  
51 0 ▶my %EASING = ( linear => sub ($t) { $t } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
52 1 foreach my $family ( keys %IN ) {
53 10 $EASING{"ease-in-$family"} = $IN{$family};
54 10 $EASING{"ease-out-$family"} = _out( $IN{$family} );
55 10 $EASING{"ease-in-out-$family"} = _in_out( $IN{$family} );
56 }
57  
58 0 ▶sub easing_names () {
Subroutine easing_names: not called CC=1 SCAR=6.9
Pod documented
59 0 my @names = sort keys %EASING;
60 0 return @names;
61 }
62  
63 0 ▶sub is_easing_name ($name) {
Subroutine is_easing_name: not called CC=4 SCAR=30.0
Pod documented
64 0 ▶ return defined $name && !ref $name && exists $EASING{$name} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $name && !ref($name) && exists $EASING{$name} ? : 0 0 0
Condition0%0/6
defined $name and not ref $name and exists $EASING{$name}
!ll&&!rl&&r
000
defined $name and not ref $name
!ll&&!rl&&r
000
MC/DC0%0/3
defined $name and not ref $name and exists $EASING{$name}
defined $name not ref $name exists $EASING{$name}
Truth table0%0/4
A and not(B) and C
A= defined $nameB= not ref $nameC= exists $EASING{$name}
ABCresult
0XX0
10X0
1100
1111
65 }
66  
67 0 ▶sub easing ($name) {
Subroutine easing: not called CC=4 SCAR=30.0
Pod documented
68 0 ▶ return $EASING{ $name // '' } // croak "Term::Fabulous::Chart::Easing: unknown easing '" . ( $name // 'undef' ) . "' (known: " . join( ', ', easing_names() ) . ")";
Condition0%0/6
$EASING{$name // ""} // croak(q[Term::Fabulous::Chart::Easing: unknown easing '] . ($name // "undef") . q[' (known: ] . join(", ", easing_names()) . ')')
l!l
00
$name // ""
l!l
00
$name // "undef"
l!l
00
MC/DC0%0/1
$EASING{$name // ""} // croak(q[Term::Fabulous::Chart::Easing: unknown easing '] . ($name // "undef") . q[' (known: ] . join(", ", easing_names()) . ')')
$EASING{$name // ""}
MC/DC0%0/1
$name // ""
$name
MC/DC0%0/1
$name // "undef"
$name
Truth table0%0/2
A
A= $EASING{$name // ""}
Aresult
11
00
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $name
Aresult
11
00
69 }
70  
71 1 1;
72  
73 __END__
« tools/lib/Term/Fabulous/Screenshot/Render/SVG.pm ↑ Summary blib/lib/Term/Fabulous/Unicode.pm »