--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "math/size.hpp"
+
+#include <ostream>
+
+#include "math/sizef.hpp"
+
+Size::Size(const Sizef& rhs) :
+ width(static_cast<int>(rhs.width)),
+ height(static_cast<int>(rhs.height))
+{
+}
+
+std::ostream& operator<<(std::ostream& s, const Size& size)
+{
+ return s << "Size(" << size.width << ", " << size.height << ")";
+}
+
+/* EOF */
-/*
-** ClanLib SDK
-** Copyright (c) 1997-2005 The ClanLib Team
-**
-** This software is provided 'as-is', without any express or implied
-** warranty. In no event will the authors be held liable for any damages
-** arising from the use of this software.
-**
-** Permission is granted to anyone to use this software for any purpose,
-** including commercial applications, and to alter it and redistribute it
-** freely, subject to the following restrictions:
-**
-** 1. The origin of this software must not be misrepresented; you must not
-** claim that you wrote the original software. If you use this software
-** in a product, an acknowledgment in the product documentation would be
-** appreciated but is not required.
-** 2. Altered source versions must be plainly marked as such, and must not be
-** misrepresented as being the original software.
-** 3. This notice may not be removed or altered from any source distribution.
-**
-** Note: Some of the libraries ClanLib may link to may have additional
-** requirements or restrictions.
-**
-** File Author(s):
-**
-** Magnus Norddahl
-** (if your name is missing here, please add it)
-*/
-
-//! clanCore="Math"
-//! header=core.h
-
-#ifndef HEADER_WINDSTILLE_MATH_SIZE_HPP
-#define HEADER_WINDSTILLE_MATH_SIZE_HPP
-
-#if _MSC_VER > 1000
-#pragma once
-#endif
-
-#include <iostream>
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_MATH_SIZE_HPP
+#define HEADER_SUPERTUX_MATH_SIZE_HPP
+
+#include <iosfwd>
class Sizef;
-//: 2D (width,height) size structure.
-//- !group=Core/Math!
-//- !header=core.h!
class Size
{
- //! Construction:
public:
- //: Constructs a size structure.
- //param width: Initial width of size structure.
- //param height: Initial height of size structure.
- //param size: Size structure to construct this one from.
- Size()
- : width(0), height(0)
+ Size() :
+ width(0),
+ height(0)
{}
- Size(int width_, int height_)
- : width(width_), height(height_)
+ Size(int width_, int height_) :
+ width(width_),
+ height(height_)
{}
- Size(const Size &s)
- : width(s.width),
- height(s.height)
+ Size(const Size& rhs) :
+ width(rhs.width),
+ height(rhs.height)
{}
- explicit Size(const Sizef& s);
+ explicit Size(const Sizef& rhs);
+
+ Size& operator*=(int factor)
+ {
+ width *= factor;
+ height *= factor;
+ return *this;
+ }
+
+ Size& operator/=(int divisor)
+ {
+ width /= divisor;
+ height /= divisor;
+ return *this;
+ }
+
+ Size& operator+=(const Size& rhs)
+ {
+ width += rhs.width;
+ height += rhs.height;
+ return *this;
+ }
+
+ Size& operator-=(const Size& rhs)
+ {
+ width -= rhs.width;
+ height -= rhs.height;
+ return *this;
+ }
- //! Attributes:
public:
- //: Size width.
int width;
-
- //: Size height.
int height;
-
- //! Operations:
-public:
- //: Size += Size operator.
- Size &operator+=(const Size &s)
- { width += s.width; height += s.height; return *this; }
-
- //: Size -= Size operator.
- Size &operator-=(const Size &s)
- { width -= s.width; height -= s.height; return *this; }
-
- //: Size + Size operator.
- Size operator+(const Size &s) const
- { return Size(width + s.width, height + s.height); }
-
- //: Size - Size operator.
- Size operator-(const Size &s) const
- { return Size(width - s.width, height - s.height); }
-
- //: Size == Size operator (deep compare).
- bool operator==(const Size &s) const
- { return (width == s.width) && (height == s.height); }
-
- //: Size != Size operator (deep compare).
- bool operator!=(const Size &s) const
- { return (width != s.width) || (height != s.height); }
};
-//: 2D (width,height) floating point size structure.
-class Sizef
-{
- //! Construction:
-public:
- //: Constructs a size structure.
- //param width: Initial width of size structure.
- //param height: Initial height of size structure.
- //param size: Size structure to construct this one from.
- Sizef()
- : width(0.0f),
- height(0.0f)
- {}
-
- Sizef(const Size& s)
- : width(static_cast<float>(s.width)),
- height(static_cast<float>(s.height))
- {}
-
- Sizef(float width_, float height_)
- : width(width_),
- height(height_)
- {}
-
- Sizef(const Sizef &s)
- : width(s.width),
- height(s.height)
- {}
+inline Size operator*(const Size& lhs, int factor)
+{
+ return Size(lhs.width * factor,
+ lhs.height * factor);
+}
- //! Attributes:
-public:
- //: Size width.
- float width;
+inline Size operator*(int factor, const Size& rhs)
+{
+ return Size(rhs.width * factor,
+ rhs.height * factor);
+}
- //: Size height.
- float height;
+inline Size operator/(const Size& lhs, int divisor)
+{
+ return Size(lhs.width / divisor,
+ lhs.height / divisor);
+}
- //! Operations:
-public:
- //: Size += Size operator.
- Sizef &operator+=(const Sizef &s)
- { width += s.width; height += s.height; return *this; }
-
- //: Size -= Size operator.
- Sizef &operator-=(const Sizef &s)
- { width -= s.width; height -= s.height; return *this; }
-
- //: Size + Size operator.
- Sizef operator+(const Sizef &s) const
- { return Sizef(width + s.width, height + s.height); }
-
- //: Size - Size operator.
- Sizef operator-(const Sizef &s) const
- { return Sizef(width - s.width, height - s.height); }
-
- //: Size == Size operator (deep compare).
- bool operator==(const Sizef &s) const
- { return (width == s.width) && (height == s.height); }
-
- //: Size != Size operator (deep compare).
- bool operator!=(const Size &s) const
- { return (width != s.width) || (height != s.height); }
-};
+inline Size operator+(const Size& lhs, const Size& rhs)
+{
+ return Size(lhs.width + rhs.width,
+ lhs.height + rhs.height);
+}
-inline Size::Size(const Sizef& s)
- : width(static_cast<int>(s.width)),
- height(static_cast<int>(s.height))
-{}
+inline Size operator-(const Size& lhs, const Size& rhs)
+{
+ return Size(lhs.width - rhs.width,
+ lhs.height - rhs.height);
+}
-inline std::ostream& operator<<(std::ostream& s, const Size& size)
+inline bool operator==(const Size& lhs, const Size& rhs)
{
- return s << "Size(" << size.width << ", " << size.height << ")";
+ return (lhs.width == rhs.width) && (lhs.height == rhs.height);
}
+inline bool operator!=(const Size& lhs, const Size& rhs)
+{
+ return (lhs.width != rhs.width) || (lhs.height != rhs.height);
+}
+
+std::ostream& operator<<(std::ostream& s, const Size& size);
+
#endif
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "math/sizef.hpp"
+
+#include <ostream>
+
+#include "math/size.hpp"
+
+Sizef::Sizef(const Size& rhs) :
+ width(static_cast<float>(rhs.width)),
+ height(static_cast<float>(rhs.height))
+{
+}
+
+std::ostream& operator<<(std::ostream& s, const Sizef& size)
+{
+ return s << "Size(" << size.width << ", " << size.height << ")";
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_MATH_SIZEF_HPP
+#define HEADER_SUPERTUX_MATH_SIZEF_HPP
+
+#include <iosfwd>
+
+class Size;
+
+class Sizef
+{
+public:
+ Sizef() :
+ width(0.0f),
+ height(0.0f)
+ {}
+
+ Sizef(float width_, float height_) :
+ width(width_),
+ height(height_)
+ {}
+
+ Sizef(const Sizef& rhs) :
+ width(rhs.width),
+ height(rhs.height)
+ {}
+
+ Sizef(const Size& rhs);
+
+ Sizef& operator*=(int factor)
+ {
+ width *= factor;
+ height *= factor;
+ return *this;
+ }
+
+ Sizef& operator/=(int divisor)
+ {
+ width /= divisor;
+ height /= divisor;
+ return *this;
+ }
+
+ Sizef& operator+=(const Sizef& rhs)
+ {
+ width += rhs.width;
+ height += rhs.height;
+ return *this;
+ }
+
+ Sizef& operator-=(const Sizef& rhs)
+ {
+ width -= rhs.width;
+ height -= rhs.height;
+ return *this;
+ }
+
+public:
+ float width;
+ float height;
+};
+
+inline Sizef operator*(const Sizef& lhs, int 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/(const Sizef& lhs, int 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);
+}
+
+inline Sizef operator-(const Sizef& lhs, const Sizef& rhs)
+{
+ 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);
+}
+
+inline bool operator!=(const Sizef& lhs, const Sizef& rhs)
+{
+ return (lhs.width != rhs.width) || (lhs.height != rhs.height);
+}
+
+std::ostream& operator<<(std::ostream& s, const Sizef& size);
+
+#endif
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <iostream>
+
+#include "math/size.hpp"
+
+int main()
+{
+ Size size(800, 600);
+
+ std::cout << size << std::endl;
+ std::cout << size * 2 << std::endl;
+ std::cout << 2 * size << std::endl;
+ std::cout << size / 2 << std::endl;
+ std::cout << size + size << std::endl;
+ size *= 2;
+ std::cout << size << std::endl;
+ size /= 2;
+ std::cout << size << std::endl;
+ size += size;
+ std::cout << size << std::endl;
+
+ return 0;
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <iostream>
+
+#include "math/sizef.hpp"
+
+int main()
+{
+ Sizef size(800, 600);
+
+ std::cout << size << std::endl;
+ std::cout << size * 2 << std::endl;
+ std::cout << 2 * size << std::endl;
+ std::cout << size / 2 << std::endl;
+ std::cout << size + size << std::endl;
+ size *= 2;
+ std::cout << size << std::endl;
+ size /= 2;
+ std::cout << size << std::endl;
+ size += size;
+ std::cout << size << std::endl;
+
+ return 0;
+}
+
+/* EOF */