Tweeny 4.1.0
A Tweening library for modern C++
Loading...
Searching...
No Matches
circular.h
1/*
2This file is part of the Tweeny library.
3
4Copyright (c) 2016-2026 Leonardo Guilherme Lucena de Freitas
5Copyright (c) 2016 Guilherme R. Costa
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software and associated documentation files (the "Software"), to deal in
9the Software without restriction, including without limitation the rights to
10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11the Software, and to permit persons to whom the Software is furnished to do so,
12subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#ifndef TWEENY_DETAIL_EASING_CIRCULAR_H
26#define TWEENY_DETAIL_EASING_CIRCULAR_H
27
28#include <cmath>
29
30namespace tweeny::detail {
31 struct circularInEasing {
32 template <typename T>
33 static T run(const float position, T start, T end) {
34 return static_cast<T>(-(end - start) * (sqrtf(1 - position * position) - 1) + start);
35 }
36
37 template <typename T>
38 T operator()(const float position, T start, T end) const {
39 return run<T>(position, start, end);
40 }
41 };
42
43 struct circularOutEasing {
44 template <typename T>
45 static T run(float position, T start, T end) {
46 --position;
47 return static_cast<T>((end - start) * sqrtf(1 - position * position) + start);
48 }
49
50 template <typename T>
51 T operator()(const float position, T start, T end) const {
52 return run<T>(position, start, end);
53 }
54 };
55
56 struct circularInOutEasing {
57 template <typename T>
58 static T run(float position, T start, T end) {
59 position *= 2;
60 if (position < 1) {
61 return static_cast<T>(-(end - start) / 2 * (sqrtf(1 - position * position) - 1) + start);
62 }
63
64 position -= 2;
65 return static_cast<T>((end - start) / 2 * (sqrtf(1 - position * position) + 1) + start);
66 }
67
68 template <typename T>
69 T operator()(float position, T start, T end) const {
70 return run<T>(position, start, end);
71 }
72 };
73}
74
75
76
77#endif // TWEENY_DETAIL_EASING_CIRCULAR_H