X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmath%2Fsizef.hpp;h=02866d40f50b541c12cbada9d5d9976350e22343;hb=77b5a67fccb8ce3a5ba43280105031a46560a5c8;hp=e03aeb03c00842fbd9d25b13b822450d37e2c1d6;hpb=2a7eed0651e57e04f995967af57444a569cf6d9e;p=supertux.git diff --git a/src/math/sizef.hpp b/src/math/sizef.hpp index e03aeb03c..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) : @@ -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: @@ -75,43 +87,43 @@ public: }; inline Sizef operator*(const Sizef& lhs, float factor) -{ - return Sizef(lhs.width * factor, - lhs.height * factor); +{ + return Sizef(lhs.width * factor, + lhs.height * factor); } inline Sizef operator*(float factor, const Sizef& rhs) -{ - return Sizef(rhs.width * factor, - rhs.height * factor); +{ + return Sizef(rhs.width * factor, + rhs.height * factor); } inline Sizef operator/(const Sizef& lhs, float divisor) -{ - return Sizef(lhs.width / divisor, - lhs.height / 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);