Coverage report for gui


src/
File: src/utils/Lerp.hpp
Date: 2024-06-25 10:57:02
Lines:
0/12
0.0%
Functions:
0/2
0.0%
Branches:
0/8
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy
4 ** File description:
5 ** Lerp
6 */
7
8 #ifndef LERP_HPP_
9 #define LERP_HPP_
10
11 #include <SFML/Graphics.hpp>
12 #include <cmath>
13
14 class Lerp {
15 public:
16 Lerp() {}
17 ~Lerp() {}
18
19 static float lerp(float a, float b, float t) {
20 return a + t * (b - a);
21 }
22
23 static sf::Vector2f lerp(sf::Vector2f a, sf::Vector2f b, float t, float distanceThreshold = 0.1f) {
24 float distance = std::sqrt(std::pow(b.x - a.x, 2) + std::pow(b.y - a.y, 2));
25 if (distance < distanceThreshold) {
26 return b;
27 } else {
28 return sf::Vector2f(lerp(a.x, b.x, t), lerp(a.y, b.y, t));
29 }
30 }
31
32 static sf::Vector2f moveTo(sf::Vector2f a, sf::Vector2f b, float speed, float distanceThreshold = 5.f) {
33 float distance = std::sqrt(std::pow(b.x - a.x, 2) + std::pow(b.y - a.y, 2));
34 if (distance < distanceThreshold) {
35 return b;
36 } else {
37 float t = speed / distance;
38 return sf::Vector2f(lerp(a.x, b.x, t), lerp(a.y, b.y, t));
39 }
40 }
41
42 static sf::Color lerp(sf::Color a, sf::Color b, float t) {
43 return sf::Color(
44 lerp(a.r, b.r, t),
45 lerp(a.g, b.g, t),
46 lerp(a.b, b.b, t),
47 lerp(a.a, b.a, t)
48 );
49 }
50 };
51
52 #endif /* !LERP_HPP_ */
53