-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.cpp
40 lines (32 loc) · 1.1 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "utils.h"
#include <cmath>
void utils::centerizeTextOrigin(sf::Text &text)
{
const sf::FloatRect labelBounds = text.getLocalBounds();
text.setOrigin(0.5f * labelBounds.width,
0.5f * labelBounds.height);
}
sf::FloatRect utils::uniteRects(const sf::FloatRect &a, const sf::FloatRect &b)
{
const float left = std::min(a.left, b.left);
const float top = std::min(a.top, b.top);
const float right = std::max(a.left + a.width, b.left + b.width);
const float bottom = std::max(a.top + a.height, b.top + b.height);
return sf::FloatRect(left, top, right - left, bottom - top);
}
sf::FloatRect utils::moveRectBy(const sf::FloatRect &a, const sf::Vector2f &movement)
{
sf::FloatRect result = a;
result.left += movement.x;
result.top += movement.y;
return result;
}
float utils::degreesToRadians(float degrees)
{
return (degrees * utils::PI / 180);
}
sf::Vector2f utils::polarToDecartian(float radius, float degrees)
{
const float radians = utils::degreesToRadians(degrees);
return radius * sf::Vector2f(std::cos(radians), std::sin(radians));
}