voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
vector2int.hpp
1 #ifndef BLUB_MATH_VECTOR2TEMPLATE_HPP
2 #define BLUB_MATH_VECTOR2TEMPLATE_HPP
3 
4 #include "blub/core/globals.hpp"
5 #include "blub/serialization/access.hpp"
6 #include "blub/serialization/nameValuePair.hpp"
7 
8 #include <boost/functional/hash.hpp>
9 
10 
11 namespace blub
12 {
13 
14 template <typename valueType, valueType valueDefault>
15 class vector2Template
16 {
17 public:
18  typedef vector2Template<valueType, valueDefault> t_thisClass;
19 
20  vector2Template()
21  : x(valueDefault)
22  , y(valueDefault)
23  {
24  ;
25  }
26 
27  vector2Template(const valueType& x_, const valueType& y_)
28  : x(x_)
29  , y(y_)
30  {
31  ;
32  }
33 
34  vector2Template(const valueType& val)
35  : x(val)
36  , y(val)
37  {
38  ;
39  }
40 
41  vector2Template(const t_thisClass& copy)
42  : x(copy.x)
43  , y(copy.y)
44  {
45  ;
46  }
47 
48  bool operator == (const t_thisClass& other) const
49  {
50  return other.x == x && other.y == y;
51  }
52 
53  bool operator <= (const t_thisClass& other) const
54  {
55  return x <= other.x && y <= other.y;
56  }
57 
58  bool operator < (const t_thisClass& other) const
59  {
60  return x < other.x && y < other.y;
61  }
62 
63  bool operator >= (const t_thisClass& other) const
64  {
65  return x >= other.x && y >= other.y;
66  }
67 
68  bool operator > (const t_thisClass& other) const
69  {
70  return x > other.x && y > other.y;
71  }
72 
73  t_thisClass operator * (const t_thisClass& other) const
74  {
75  return t_thisClass(other.x*x, other.y*y);
76  }
77 
78  t_thisClass operator * (const int32& other) const
79  {
80  return t_thisClass(other*x, other*y);
81  }
82 
83  t_thisClass operator + (const t_thisClass& other) const
84  {
85  return t_thisClass(other.x+x, other.y+y);
86  }
87 
88  t_thisClass operator - (const t_thisClass& other) const
89  {
90  return t_thisClass(x-other.x, y-other.y);
91  }
92 
93  t_thisClass operator - (void) const
94  {
95  return t_thisClass(-x, -y);
96  }
97 
98  t_thisClass operator / (const t_thisClass& other) const
99  {
100  return t_thisClass(x/other.x, y/other.y);
101  }
102 
103  t_thisClass operator / (const valueType& other) const
104  {
105  return t_thisClass(x/other, y/other);
106  }
107 
108  valueType calculateArea() const
109  {
110  return x*y;
111  }
112 
113 protected:
114  BLUB_SERIALIZATION_ACCESS
115  template<typename Archive>
116  void serialize(Archive & readWrite, const unsigned int version)
117  {
118  (void)version;
119 
120  readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(x);
121  readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(y);
122  }
123 
124 public:
125  valueType x;
126  valueType y;
127 
128 };
129 
130 template <typename valueType, valueType valueDefault>
131 std::ostream& operator<< (std::ostream& ostr, const vector2Template<valueType, valueDefault>& toCast)
132 {
133  return ostr << "(" << toCast.x << "," << toCast.y << ")";
134 }
135 
136 template <typename valueType, valueType valueDefault>
137 std::size_t hash_value(const vector2Template<valueType, valueDefault>& value)
138 {
139  std::size_t result(value.x);
140  boost::hash_combine(result, value.y);
141 
142  return result;
143 }
144 
145 
146 }
147 
148 
149 #endif // BLUB_MATH_VECTOR2TEMPLATE_HPP
Definition: deadlineTimer.hpp:10