Flutter Engine
The Flutter Engine
Functions
TimeUtils Namespace Reference

Functions

static SkMSec NanosToMSec (double nanos)
 
static double NanosToSeconds (double nanos)
 
static float Scaled (float time, float speed, float period=0)
 
static float PingPong (double time, float period, float phase, float ends, float mid)
 
static float SineWave (double time, float periodInSecs, float phaseInSecs, float min, float max)
 

Function Documentation

◆ NanosToMSec()

static SkMSec TimeUtils::NanosToMSec ( double  nanos)
inlinestatic

Definition at line 16 of file TimeUtils.h.

16 {
17 const double msec = nanos * 1e-6;
18 SkASSERT(SK_MSecMax >= msec);
19 return static_cast<SkMSec>(msec);
20 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr SkMSec SK_MSecMax
Definition: SkTypes.h:188
uint32_t SkMSec
Definition: SkTypes.h:184

◆ NanosToSeconds()

static double TimeUtils::NanosToSeconds ( double  nanos)
inlinestatic

Definition at line 22 of file TimeUtils.h.

22 {
23 return nanos * 1e-9;
24 }

◆ PingPong()

static float TimeUtils::PingPong ( double  time,
float  period,
float  phase,
float  ends,
float  mid 
)
inlinestatic

Definition at line 37 of file TimeUtils.h.

41 {
42 double value = ::fmod(time + phase, period);
43 double half = period / 2.0;
44 double diff = ::fabs(value - half);
45 return (float)(ends + (1.0 - diff / half) * (mid - ends));
46 }
uint8_t value
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394

◆ Scaled()

static float TimeUtils::Scaled ( float  time,
float  speed,
float  period = 0 
)
inlinestatic

Definition at line 27 of file TimeUtils.h.

27 {
28 double value = time * speed;
29 if (period) {
30 value = ::fmod(value, (double)(period));
31 }
32 return (float)value;
33 }

◆ SineWave()

static float TimeUtils::SineWave ( double  time,
float  periodInSecs,
float  phaseInSecs,
float  min,
float  max 
)
inlinestatic

Definition at line 48 of file TimeUtils.h.

52 {
53 if (periodInSecs < 0.f) {
54 return (min + max) / 2.f;
55 }
56 double t = NanosToSeconds(time) + phaseInSecs;
57 t *= 2 * SK_FloatPI / periodInSecs;
58 float halfAmplitude = (max - min) / 2.f;
59 return halfAmplitude * std::sin(t) + halfAmplitude + min;
60 }
constexpr float SK_FloatPI
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
static double NanosToSeconds(double nanos)
Definition: TimeUtils.h:22