| 1 | package Schedule::Easing::Numeric; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use parent qw/Schedule::Easing::Ease/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw/carp confess/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util qw/looks_like_number/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | our $VERSION='0.1.4'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | sub _default_keys { | ||||||||||||||||||||
| 12 | 20 | ▶ | my ($self)=@_; | ||||||||||||||||||
|
Subroutine
_default_keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | return ( | ||||||||||||||||||||
| 14 | 20 | $self->SUPER::_default_keys(), | |||||||||||||||||||
| 15 | qw/ymin ymax/, | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | sub _default { | ||||||||||||||||||||
| 19 | 20 | ▶ | my ($self)=@_; | ||||||||||||||||||
|
Subroutine
_default: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | return ( | ||||||||||||||||||||
| 21 | 20 | $self->SUPER::_default(), | |||||||||||||||||||
| 22 | match=>qr/(?<value>\d+)/, | ||||||||||||||||||||
| 23 | ymin=>0, | ||||||||||||||||||||
| 24 | ymax=>1, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub new { | ||||||||||||||||||||
| 29 | 20 | ▶ | my ($ref,%opt)=@_; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 30 | 20 | ▶ | my $class=ref($ref)||$ref; | ||||||||||||||||||
|
Condition66%2/3
ref $ref || $ref
MC/DC0%0/2
ref $ref || $ref
ref $ref
$ref
Truth table66%2/3
A || B
A= ref $refB= $ref
| |||||||||||||||||||||
| 31 | my %self=( | ||||||||||||||||||||
| 32 | type =>'numeric', | ||||||||||||||||||||
| 33 | $class->_default(), | ||||||||||||||||||||
| 34 | (ref($ref)?%$ref:()), | ||||||||||||||||||||
| 35 | 20 | ▶ | map {$_=>$opt{$_}} grep {defined($opt{$_})} $class->_default_keys() | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | 20 | return bless(\%self,$class)->validate()->init(); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub validate { | ||||||||||||||||||||
| 41 | 20 | ▶ | my ($self)=@_; | ||||||||||||||||||
|
Subroutine
validate: called CC=7 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||
| 42 | 20 | $self->SUPER::validate(); | |||||||||||||||||||
| 43 | 19 | foreach my $k (qw/ymin ymax/) { | |||||||||||||||||||
| 44 | 37 | ▶ | if(!defined($$self{$k})) { confess("Must be defined: $k") } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 37 | ▶ | if(!looks_like_number($$self{$k})) { confess("Must be numeric: $k") } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 17 | ▶ | if($$self{ymin}>$$self{ymax}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 48 | 0 | (@$self{qw/ymin ymax/})=@$self{qw/ymax ymin/}; | |||||||||||||||||||
| 49 | 0 | carp('ymin>ymax'); | |||||||||||||||||||
| 50 | 0 | $$self{_err}=1; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | elsif($$self{ymin}==$$self{ymax}) { | ||||||||||||||||||||
| 53 | 0 | $$self{ymax}=1+$$self{ymin}; | |||||||||||||||||||
| 54 | 0 | carp('ymin==ymax'); | |||||||||||||||||||
| 55 | 0 | $$self{_err}=1; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | 17 | ▶ | if($$self{match}!~/\(\?<value>.*?\)/) { confess("Match pattern does not contain 'value': $$self{match}") } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 15 | return $self; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub init { | ||||||||||||||||||||
| 62 | 15 | ▶ | my ($self)=@_; | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 63 | 15 | $self->SUPER::init(); | |||||||||||||||||||
| 64 | 15 | $$self{yrange}=$$self{ymax}-$$self{ymin}; | |||||||||||||||||||
| 65 | 15 | return $self; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | sub includes { | ||||||||||||||||||||
| 69 | 97353 | ▶ | my ($self,$ts,%D)=@_; | ||||||||||||||||||
|
Subroutine
includes: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||
| 70 | 97353 | ▶ | if(!defined($ts)) { return 1 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 97352 | ▶ | if(!defined($D{value})) { return 1 } # possibly a configuration for the default, but should never be called | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 97351 | ▶ | if(!looks_like_number($D{value})) { return 1 } # possibly a config, but can't cast non-numerics at this time | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 97350 | my $p=$$self{_shaper}->($ts,@$self{qw/tsA tsB begin final/},@{$$self{shapeopt}}); | |||||||||||||||||||
| 74 | 97350 | ▶ | if($p<=0) { return 0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 85330 | ▶ | if($p>=1) { return 1 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 73312 | ▶ | if($D{value}-$$self{ymin}<=$p*$$self{yrange}) { return 1 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 36625 | return 0; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | sub schedule { | ||||||||||||||||||||
| 81 | 4757 | ▶ | my ($self,%D)=@_; | ||||||||||||||||||
|
Subroutine
schedule: called CC=9 SCAR=23.6
Pod
undocumented
| |||||||||||||||||||||
| 82 | 4757 | ▶ | if(!defined($D{value})) { return 0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 4757 | ▶ | if(!looks_like_number($D{value})) { return 0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 4757 | my $p=($D{value}-$$self{ymin})/$$self{yrange}; | |||||||||||||||||||
| 85 | 4757 | ▶ | if($$self{begin}<$$self{final}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 86 | 2757 | ▶ | if($p<$$self{begin}) { return 0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 2639 | ▶ | if($p>$$self{final}) { return } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | elsif($$self{begin}>$$self{final}) { | ||||||||||||||||||||
| 90 | 2000 | ▶ | if($p>$$self{begin}) { return 0 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 2000 | ▶ | if($p<$$self{final}) { return } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | 4580 | return $$self{_unshaper}->($p,@$self{qw/tsA tsB begin final/},@{$$self{shapeopt}}); | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 2 | 1; | |||||||||||||||||||