aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Scale.hpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/include/Scale.hpp b/include/Scale.hpp
index e458894..eb902cd 100644
--- a/include/Scale.hpp
+++ b/include/Scale.hpp
@@ -2,12 +2,15 @@
#include <SFML/System/Vector2.hpp>
-// TODO: Check if size is 0 before dividing to prevent division by 0?
-
namespace QuickMedia {
template<typename T>
static T wrap_to_size_x(const T &size, const T &clamp_size) {
T new_size;
+ if(size.x == 0) {
+ new_size.x = 0;
+ new_size.y = 0;
+ return new_size;
+ }
float size_ratio = (float)size.y / (float)size.x;
new_size.x = clamp_size.x;
new_size.y = new_size.x * size_ratio;
@@ -17,6 +20,11 @@ namespace QuickMedia {
template<typename T>
static T wrap_to_size_y(const T &size, const T &clamp_size) {
T new_size;
+ if(size.y == 0) {
+ new_size.x = 0;
+ new_size.y = 0;
+ return new_size;
+ }
float size_ratio = (float)size.x / (float)size.y;
new_size.y = clamp_size.y;
new_size.x = new_size.y * size_ratio;
@@ -50,6 +58,9 @@ namespace QuickMedia {
template<typename T>
static sf::Vector2f get_ratio(const T &original_size, const T &new_size) {
- return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y);
+ if(original_size.x == 0 || original_size.y == 0)
+ return sf::Vector2f(0.0f, 0.0f);
+ else
+ return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y);
}
} \ No newline at end of file