| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
%{ |
| 23 |
#include "util/structures/point.h" |
| 24 |
#include "util/structures/rect.h" |
| 25 |
%} |
| 26 |
|
| 27 |
namespace FIFE { |
| 28 |
|
| 29 |
template <typename T> class PointType2D { |
| 30 |
public: |
| 31 |
T x; |
| 32 |
T y; |
| 33 |
explicit PointType2D(T _x = 0, T _y = 0); |
| 34 |
PointType2D(const PointType2D<T>& rhs); |
| 35 |
PointType2D<T> operator+(const PointType2D<T>& p) const; |
| 36 |
PointType2D<T> operator-(const PointType2D<T>& p) const; |
| 37 |
PointType2D<T>& operator+=(const PointType2D<T>& p); |
| 38 |
PointType2D<T>& operator-=(const PointType2D<T>& p); |
| 39 |
PointType2D<T> operator*(const T& i) const; |
| 40 |
PointType2D<T> operator/(const T& i) const; |
| 41 |
bool operator==(const PointType2D<T>& p) const; |
| 42 |
bool operator!=(const PointType2D<T>& p) const; |
| 43 |
T length() const; |
| 44 |
void normalize(); |
| 45 |
void rotate(T angle); |
| 46 |
void rotate(const PointType2D<T>& origin, T angle); |
| 47 |
void set(T _x, T _y); |
| 48 |
}; |
| 49 |
|
| 50 |
template<typename T> |
| 51 |
std::ostream& operator<<(std::ostream& os, const PointType2D<T>& p); |
| 52 |
|
| 53 |
typedef PointType2D<int32_t> Point; |
| 54 |
typedef PointType2D<int32_t> IntPoint; |
| 55 |
typedef PointType2D<double> DoublePoint; |
| 56 |
typedef PointType2D<int32_t> IntPoint2D; |
| 57 |
typedef PointType2D<double> DoublePoint2D; |
| 58 |
|
| 59 |
%template(Point) PointType2D<int32_t>; |
| 60 |
%template(DoublePoint) PointType2D<double>; |
| 61 |
|
| 62 |
template <typename T> class PointType3D { |
| 63 |
public: |
| 64 |
T x; |
| 65 |
T y; |
| 66 |
T z; |
| 67 |
explicit PointType3D(T _x = 0, T _y = 0, T _z = 0); |
| 68 |
PointType3D(const PointType3D<T>& rhs); |
| 69 |
PointType3D<T> operator+(const PointType3D<T>& p) const; |
| 70 |
PointType3D<T> operator-(const PointType3D<T>& p) const; |
| 71 |
PointType3D<T>& operator+=(const PointType3D<T>& p); |
| 72 |
PointType3D<T>& operator-=(const PointType3D<T>& p); |
| 73 |
PointType3D<T> operator*(const T& i) const; |
| 74 |
PointType3D<T> operator/(const T& i) const; |
| 75 |
bool operator==(const PointType3D<T>& p) const; |
| 76 |
bool operator!=(const PointType3D<T>& p) const; |
| 77 |
T length() const; |
| 78 |
void normalize(); |
| 79 |
void set(T _x, T _y, T _z); |
| 80 |
}; |
| 81 |
|
| 82 |
template<typename T> |
| 83 |
std::ostream& operator<<(std::ostream& os, const PointType3D<T>& p); |
| 84 |
|
| 85 |
typedef PointType3D<int32_t> Point3D; |
| 86 |
typedef PointType3D<int32_t> IntPoint3D; |
| 87 |
typedef PointType3D<double> DoublePoint3D; |
| 88 |
|
| 89 |
%template(Point3D) PointType3D<int32_t>; |
| 90 |
%template(DoublePoint3D) PointType3D<double>; |
| 91 |
|
| 92 |
template <typename T> class RectType { |
| 93 |
public: |
| 94 |
T x; |
| 95 |
T y; |
| 96 |
T w; |
| 97 |
T h; |
| 98 |
explicit RectType(T x = 0, T y = 0, T width = 0, T height = 0); |
| 99 |
T right() const; |
| 100 |
T bottom() const; |
| 101 |
bool operator==(const RectType<T>& rect ) const; |
| 102 |
bool contains( const PointType2D<T>& point ) const; |
| 103 |
bool intersects( const RectType<T>& rect ) const; |
| 104 |
bool intersectInplace( const RectType<T>& rect ); |
| 105 |
}; |
| 106 |
|
| 107 |
template<typename T> |
| 108 |
std::ostream& operator<<(std::ostream&, const RectType<T>&); |
| 109 |
|
| 110 |
typedef RectType<int32_t> Rect; |
| 111 |
typedef RectType<float> FloatRect; |
| 112 |
typedef RectType<double> DoubleRect; |
| 113 |
|
| 114 |
%template(Rect) RectType<int32_t>; |
| 115 |
%template(FloatRect) RectType<float>; |
| 116 |
%template(DoubleRect) RectType<double>; |
| 117 |
} |
| 118 |
|
| 119 |
namespace std { |
| 120 |
%template(FifePointVector) vector<FIFE::Point>; |
| 121 |
} |