25#ifndef TWEENY_DETAIL_EASING_ELASTIC_H
26#define TWEENY_DETAIL_EASING_ELASTIC_H
31#define M_PI 3.14159265358979323846
34namespace tweeny::detail {
35 struct elasticInEasing {
37 static T run(
float position, T start, T end) {
38 if (position <= 0.00001f)
return start;
39 if (position >= 0.999f)
return end;
42 const float s = p / 4;
43 const float postFix = a * powf(2, 10 * (position -= 1));
44 return static_cast<T
>(-(postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p)) + start);
48 T operator()(
const float position, T start, T end)
const {
49 return run<T>(position, start, end);
53 struct elasticOutEasing {
55 static T run(
const float position, T start, T end) {
56 if (position <= 0.00001f)
return start;
57 if (position >= 0.999f)
return end;
61 return static_cast<T
>(a * powf(2, -10 * position) * sinf(
62 (position - s) * (2 *
static_cast<float>(M_PI)) / p
67 T operator()(
const float position, T start, T end)
const {
68 return run<T>(position, start, end);
72 struct elasticInOutEasing {
74 static T run(
float position, T start, T end) {
75 if (position <= 0.00001f)
return start;
76 if (position >= 0.999f)
return end;
78 const float p = .3f * 1.5f;
80 const float s = p / 4;
84 postFix = a * powf(2, 10 * (position -= 1));
85 return static_cast<T
>(-0.5f * (postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p)) + start);
87 postFix = a * powf(2, -10 * (position -= 1));
88 return static_cast<T
>(postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p) * .5f + end);
92 T operator()(
const float position, T start, T end)
const {
93 return run<T>(position, start, end);