diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/point.cpp | 57 | ||||
-rw-r--r-- | src/utils/point.hpp | 66 | ||||
-rw-r--r-- | src/utils/point_3d.cpp | 43 | ||||
-rw-r--r-- | src/utils/point_3d.hpp | 22 | ||||
-rw-r--r-- | src/utils/rectangle.cpp | 78 | ||||
-rw-r--r-- | src/utils/rectangle.hpp | 64 |
6 files changed, 128 insertions, 202 deletions
diff --git a/src/utils/point.cpp b/src/utils/point.cpp deleted file mode 100644 index a72bfda6..00000000 --- a/src/utils/point.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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 2 - * 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; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "point.hpp" - -namespace usdx -{ - Point::Point(float x, float y) : - x(x), y(y) - { - } - - Point::Point(const Point& point) : - x(point.x), y(point.y) - { - } - - Point& Point::operator=(const Point& point) - { - x = point.x; - y = point.y; - return *this; - } - - float Point::get_x(void) const - { - return x; - } - - float Point::get_y(void) const - { - return y; - } -}; diff --git a/src/utils/point.hpp b/src/utils/point.hpp index 7c1ec727..6618e285 100644 --- a/src/utils/point.hpp +++ b/src/utils/point.hpp @@ -29,18 +29,70 @@ namespace usdx { + template <class T> class Point { private: - float x; - float y; + T x; + T y; + public: - Point(float x, float y); - Point(const Point& point); - Point& operator=(const Point& point); + Point(T x, T y): + x(x), y(y) + { + } + + Point(const Point& point): + x(point.x), y(point.y) + { + } + + Point& operator=(const Point& point) + { + x = point.x; + y = point.y; + return *this; + } + + + T get_x(void) const + { + return x; + } + + T get_y(void) const + { + return y; + } + + + Point& operator+=(const Point &other) + { + x += other.x; + y += other.y; + return *this; + } + + Point& operator-=(const Point &other) + { + x -= other.x; + y -= other.y; + return *this; + } + + const Point operator+(const Point &other) const + { + Point<T> result(*this); + result += other; + return result; + } - float get_x(void) const; - float get_y(void) const; + const Point operator-(const Point &other) const + { + Point<T> result(*this); + result -= other; + return result; + } }; }; diff --git a/src/utils/point_3d.cpp b/src/utils/point_3d.cpp deleted file mode 100644 index 5f8f877a..00000000 --- a/src/utils/point_3d.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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 2 - * 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; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "point_3d.hpp" - -namespace usdx -{ - Point3D::Point3D(float x, float y, float z) : Point(x, y), z(z) - { - } - - Point3D::Point3D(const Point3D& point) : Point(point), z(point.z) - { - } - - float Point3D::get_z(void) const - { - return z; - } -}; diff --git a/src/utils/point_3d.hpp b/src/utils/point_3d.hpp index 0087c08a..1ce2a313 100644 --- a/src/utils/point_3d.hpp +++ b/src/utils/point_3d.hpp @@ -32,15 +32,27 @@ namespace usdx { - class Point3D : public Point + template <class T> + class Point3D : public Point<T> { private: - float z; + T z; + public: - Point3D(float x, float y, float z); - Point3D(const Point3D& point); + Point3D(T x, T y, T z) : + Point<T>(x, y), z(z) + { + } + + Point3D(const Point3D<T>& point) : + Point<T>(point), z(point.z) + { + } - float get_z(void) const; + T get_z(void) const + { + return z; + } }; }; diff --git a/src/utils/rectangle.cpp b/src/utils/rectangle.cpp deleted file mode 100644 index b31e514c..00000000 --- a/src/utils/rectangle.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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 2 - * 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; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "rectangle.hpp" - -namespace usdx -{ - Rectangle::Rectangle(float x1, float y1, float x2, float y2) : - point1(x1, y1), point2(x2, y2) - { - } - - Rectangle::Rectangle(const Point& point1, const Point& point2) : - point1(point1), point2(point2) - { - } - - Rectangle::Rectangle(const Point& point1, float width, float height) : - point1(point1), - point2(point1.get_x() + width, point1.get_y() + height) - { - } - - Rectangle::Rectangle(const Point& point1, const Dimension& dimension) : - point1(point1), - point2(point1.get_x() + dimension.get_width(), - point1.get_y() + dimension.get_height()) - { - } - - Rectangle::Rectangle(const Rectangle& rectangle) : - point1(rectangle.point1), point2(rectangle.point2) - { - } - - const Point& Rectangle::get_point1(void) const - { - return point1; - } - - const Point& Rectangle::get_point2(void) const - { - return point2; - } - - const float Rectangle::get_width(void) const - { - return point2.get_x() - point1.get_x(); - } - - const float Rectangle::get_height(void) const - { - return point2.get_y() - point1.get_y(); - } -}; diff --git a/src/utils/rectangle.hpp b/src/utils/rectangle.hpp index c77b8673..abe26ef1 100644 --- a/src/utils/rectangle.hpp +++ b/src/utils/rectangle.hpp @@ -32,22 +32,62 @@ namespace usdx { + template <class T> class Rectangle { private: - Point point1; - Point point2; + Point<T> point1; + Point<T> point2; + public: - Rectangle(float x1, float y1, float x2, float y2); - Rectangle(const Point& point1, const Point& point2); - Rectangle(const Point& point1, float width, float height); - Rectangle(const Point& point1, const Dimension& dimension); - Rectangle(const Rectangle& rectangle); - - const Point& get_point1(void) const; - const Point& get_point2(void) const; - const float get_width(void) const; - const float get_height(void) const; + Rectangle(T x1, T y1, T x2, T y2) : + point1(x1, y1), point2(x2, y2) + { + } + + Rectangle(const Point<T>& point1, const Point<T>& point2) : + point1(point1), point2(point2) + { + } + + Rectangle(const Point<T>& point1, T width, T height) : + point1(point1), + point2(point1.get_x() + width, point1.get_y() + height) + { + } + + Rectangle(const Point<T>& point1, const Dimension& dimension) : + point1(point1), + point2(point1.get_x() + dimension.get_width(), + point1.get_y() + dimension.get_height()) + { + } + + Rectangle(const Rectangle<T>& rectangle) : + point1(rectangle.point1), point2(rectangle.point2) + { + } + + + const Point<T>& get_point1(void) const + { + return point1; + } + + const Point<T>& get_point2(void) const + { + return point2; + } + + const T get_width(void) const + { + return point2.get_x() - point1.get_x(); + } + + const T get_height(void) const + { + return point2.get_y() - point1.get_y(); + } }; }; |