X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmath%2Fsizef.hpp;h=02866d40f50b541c12cbada9d5d9976350e22343;hb=1240eda3ac57e6607b206e3c9cf7feb65c3be620;hp=9339eeced579873537d836e278d39ca7d57ae2c2;hpb=4dd0a3a24921ac753ba11c73e7d98b6fa3702346;p=supertux.git diff --git a/src/math/sizef.hpp b/src/math/sizef.hpp index 9339eeced..02866d40f 100644 --- a/src/math/sizef.hpp +++ b/src/math/sizef.hpp @@ -1,5 +1,5 @@ // SuperTux -// Copyright (C) 2009 Ingo Ruhnke +// Copyright (C) 2009 Ingo Ruhnke // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ #include +#include "math/vector.hpp" + class Size; class Sizef @@ -29,9 +31,14 @@ public: height(0.0f) {} + explicit Sizef(const Vector& v) : + width(v.x), + height(v.y) + {} + Sizef(float width_, float height_) : - width(width_), - height(height_) + width(width_), + height(height_) {} Sizef(const Sizef& rhs) : @@ -41,14 +48,14 @@ public: Sizef(const Size& rhs); - Sizef& operator*=(int factor) + Sizef& operator*=(float factor) { width *= factor; height *= factor; return *this; } - Sizef& operator/=(int divisor) + Sizef& operator/=(float divisor) { width /= divisor; height /= divisor; @@ -56,17 +63,22 @@ public: } Sizef& operator+=(const Sizef& rhs) - { - width += rhs.width; - height += rhs.height; - return *this; + { + width += rhs.width; + height += rhs.height; + return *this; } Sizef& operator-=(const Sizef& rhs) - { - width -= rhs.width; - height -= rhs.height; - return *this; + { + width -= rhs.width; + height -= rhs.height; + return *this; + } + + Vector as_vector() const + { + return Vector(width, height); } public: @@ -74,44 +86,44 @@ public: float height; }; -inline Sizef operator*(const Sizef& lhs, int factor) -{ - return Sizef(lhs.width * factor, - lhs.height * factor); +inline Sizef operator*(const Sizef& lhs, float factor) +{ + return Sizef(lhs.width * factor, + lhs.height * factor); } -inline Sizef operator*(int factor, const Sizef& rhs) -{ - return Sizef(rhs.width * factor, - rhs.height * factor); +inline Sizef operator*(float factor, const Sizef& rhs) +{ + return Sizef(rhs.width * factor, + rhs.height * factor); } -inline Sizef operator/(const Sizef& lhs, int divisor) -{ - return Sizef(lhs.width / divisor, - lhs.height / divisor); +inline Sizef operator/(const Sizef& lhs, float divisor) +{ + return Sizef(lhs.width / divisor, + lhs.height / divisor); } inline Sizef operator+(const Sizef& lhs, const Sizef& rhs) -{ - return Sizef(lhs.width + rhs.width, - lhs.height + rhs.height); +{ + return Sizef(lhs.width + rhs.width, + lhs.height + rhs.height); } inline Sizef operator-(const Sizef& lhs, const Sizef& rhs) { - return Sizef(lhs.width - rhs.width, - lhs.height - rhs.height); + return Sizef(lhs.width - rhs.width, + lhs.height - rhs.height); } inline bool operator==(const Sizef& lhs, const Sizef& rhs) { - return (lhs.width == rhs.width) && (rhs.height == rhs.height); + return (lhs.width == rhs.width) && (rhs.height == rhs.height); } inline bool operator!=(const Sizef& lhs, const Sizef& rhs) -{ - return (lhs.width != rhs.width) || (lhs.height != rhs.height); +{ + return (lhs.width != rhs.width) || (lhs.height != rhs.height); } std::ostream& operator<<(std::ostream& s, const Sizef& size);