Gorgon Game Engine
PointProperty.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Point.h"
4 #include "../Property.h"
5 
6 namespace Gorgon { namespace Geometry {
7 
11  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
12  class basic_PointProperty : Property<C_, T_, Getter_, Setter_> {
13  public:
14 
15  basic_PointProperty(C_ *object) :
16  Property<C_,T_, Getter_, Setter_>(object),
17  X(this), Y(this)
18  { }
19 
21  { }
22 
24 
26 
27  operator T_() {
28  return (this->Object.*Getter_)();
29  }
30 
31  operator const T_() const {
32  return (this->Object.*Getter_)();
33  }
34 
35  basic_PointProperty &operator =(const T_ &value) {
36  (this->Object.*Setter_)(value);
37 
38  return *this;
39  }
40 
41  T_ operator - (const T_ &point) const {
42  return this->Get() - point;
43  }
44 
46  T_ operator -() const {
47  return -this->Get();
48  }
49 
51  T_ operator + (const T_ &point) const {
52  return this->Get() + point;
53  }
54 
57  template <class O_>
58  T_ operator * (O_ value) const {
59  return this->Get() * value;
60  }
61 
63  T_ operator *(const T_ &value) const {
64  return this->Get() * value;
65  }
66 
69  template <class O_>
70  T_ operator / (O_ value) const {
71  return this->Get() / value;
72  }
73 
76  basic_PointProperty &operator -= (const T_ &point) {
77  this->Set(this->Get() - point);
78 
79  return *this;
80  }
81 
84  basic_PointProperty &operator += (const T_ &point) {
85  this->Set(this->Get() + point);
86 
87  return *this;
88  }
89 
91  template <class O_>
93  this->Set(this->Get() * value);
94 
95  return *this;
96  }
97 
99  template <class O_>
101  this->Set(this->Get() / value);
102 
103  return *this;
104  }
105 
107  T_ CrossProduct(const T_ &value) const {
108  return this->Get().CrossProduct(value);
109  }
110 
112  T_ DotProduct(const T_ &value) const {
113  return this->Get().DotProduct(value);
114  }
115 
116 
118  Float Distance(const T_ &target) const {
119  return this->Get().Distance(target);
120  }
122  Float EuclideanSquare(const T_ &target) const {
123  return this->Get().EuclideanSquare(target);
124  }
126  Float Distance() const {
127  return this->Get().Distance();
128  }
129 
132  return this->Get().EuclideanSquare();
133  }
135  Float ManhattanDistance(const T_ &target) const {
136  return this->Get().ManhattanDistance(target);
137  }
138 
141  return this->Get().ManhattanDistance();
142  }
143 
145  T_ Normalize() const {
146  return this->Get().Normalize();
147  }
148 
150  T_ Perpendicular() const {
151  return this->Get().Perpendicular();
152  }
153 
158  Float Angle(const T_ &origin) const {
159  return this->Get().Angle(origin);
160  }
161 
165  Float Angle() const {
166  return this->Get().Angle();
167  }
168 
172  Float Slope(const T_ &point) const {
173  return this->Get().Slope(point);
174  }
175 
178  Float Slope() const {
179  return this->Get().Slope();
180  }
181 
183  bool Compare(const T_ &point) const {
184  return this->Get().Compare(point);
185  }
186 
188  bool operator == (const T_ &point) const {
189  return Compare(point);
190  }
191 
193  bool operator !=(const T_ &point) const {
194  return !Compare(point);
195  }
196 
198  void Move(const T_ &x, const T_ &y) {
199  this->Set({x, y});
200  }
201 
203  typename T_::BaseType GetX() const {
204  return this->Get().X;
205  }
206 
208  void SetX(const typename T_::BaseType &value) {
209  this->Set({value, this->Get().Y});
210  }
211 
213  typename T_::BaseType GetY() const {
214  return this->Get().Y;
215  }
216 
218  void SetY(const typename T_::BaseType &value) {
219  this->Set({this->Get().X, value});
220  }
221 
224  };
225 
227  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
229  auto p = point.Get();
230  Translate(p, x, y);
231  point.Set(p);
232  }
233 
235  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
237  auto p = point.Get();
238  Translate(p, other);
239  point.Set(p);
240  }
241 
243  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
245  auto p = point.Get();
246  Scale(p, size);
247  point.Set(p);
248  }
249 
251  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O1_, class O2_>
252  void Scale(basic_PointProperty<C_, T_, Getter_, Setter_> &point, const O1_ &sizex, const O2_ &sizey) {
253  auto p = point.Get();
254  Scale(p, sizex, sizey);
255  point.Set(p);
256  }
257 
260  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
261  void Scale(basic_PointProperty<C_, T_, Getter_, Setter_> &point, const O_ &size, const basic_Point<T_> &origin) {
262  auto p = point.Get();
263  Scale(p, size, origin);
264  point.Set(p);
265  }
266 
269  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O1_, class O2_>
270  void Scale(basic_PointProperty<C_, T_, Getter_, Setter_> &point, const O1_ &sizex, const O2_ &sizey, const T_ &origin) {
271  auto p = point.Get();
272  Scale(p, sizex, sizey, origin);
273  point.Set(p);
274  }
275 
276 
280  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
282  auto p = point.Get();
283  Rotate(p, angle);
284  point.Set(p);
285  }
286 
291  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
292  void Rotate(basic_PointProperty<C_, T_, Getter_, Setter_> &point, Float angle, const T_ &origin) {
293  auto p = point.Get();
294  Rotate(p, angle, origin);
295  point.Set(p);
296  }
297 
301  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
303  auto p = point.Get();
304  SkewX(p, rate);
305  point.Set(p);
306  }
307 
311  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
313  auto p = point.Get();
314  SkewY(p, rate);
315  point.Set(p);
316  }
317 
321  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
322  void SkewX(basic_PointProperty<C_, T_, Getter_, Setter_> &point, const O_ &rate, const T_ &origin) {
323  point.X += T_((point.Y-origin.Y)*rate);
324  }
325 
329  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
330  void SkewY(basic_PointProperty<C_, T_, Getter_, Setter_> &point, const O_ &rate, const basic_Point<T_> &origin) {
331  point.Y += T_((point.X-origin.X)*rate);
332  }
333 
335  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
337  point.Y = -point.Y;
338  }
339 
341  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
343  point.X = -point.X;
344  }
345 
347  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
349  ReflectX(point);
350  }
351 
353  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
355  ReflectY(point);
356  }
357 
359  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
361  point.Y = -point.Y+origin.Y*2;
362  }
363 
365  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
367  point.X = -point.X+origin.X*2;
368  }
369 
371  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
373  ReflectX(point, origin);
374  }
375 
377  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
379  ReflectY(point, origin);
380  }
381 
382  template<class C_, Point(C_::*Getter_)() const, void(C_::*Setter_)(const Point &)>
384 
385  template<class C_, Pointf(C_::*Getter_)() const, void(C_::*Setter_)(const Pointf &)>
387 
388 } }
Gorgon::Property::Set
void Set(const T_ &value)
Definition: Property.h:63
Gorgon::Geometry::basic_PointProperty::Perpendicular
T_ Perpendicular() const
Calculates perpendicular vector to this point.
Definition: PointProperty.h:150
Gorgon::Geometry::basic_PointProperty::operator!=
bool operator!=(const T_ &point) const
Compares two points.
Definition: PointProperty.h:193
Gorgon::Geometry::SkewY
void SkewY(basic_Bounds< T_ > &bounds, const O_ &rate)
Skews the given bounds with the given rate along Y axis.
Definition: Bounds.h:675
Gorgon::Geometry::basic_PointProperty::Angle
Float Angle() const
Calculates the angle of the line formed from the origin to this point.
Definition: PointProperty.h:165
Gorgon::Geometry::basic_PointProperty::EuclideanSquare
Float EuclideanSquare(const T_ &target) const
Calculates EuclideanSquare distance from this point to the given target.
Definition: PointProperty.h:122
Gorgon::NumericProperty
Supports arithmetic operators including +, * ..., +=, ...
Definition: Property.h:108
Gorgon::Geometry::basic_PointProperty::Normalize
T_ Normalize() const
Normalizes the point as a unit vector.
Definition: PointProperty.h:145
Gorgon::Geometry::ReflectX
void ReflectX(basic_Point< T_ > &point)
Reflects the given point along the X axis.
Definition: Point.h:551
Gorgon::Geometry::basic_PointProperty::Distance
Float Distance() const
Calculates Euclidean distance from this point to origin.
Definition: PointProperty.h:126
Point.h
contains point class.
Gorgon::Geometry::basic_Point::X
T_ X
X coordinate.
Definition: Point.h:368
Gorgon::Geometry::basic_PointProperty::SetY
void SetY(const typename T_::BaseType &value)
Sets Y component.
Definition: PointProperty.h:218
Gorgon::Geometry::basic_PointProperty::GetY
T_::BaseType GetY() const
Returns Y component.
Definition: PointProperty.h:213
Gorgon::Geometry::basic_PointProperty::operator-
T_ operator-() const
Negates this point.
Definition: PointProperty.h:46
Gorgon::Geometry::VerticalMirror
void VerticalMirror(basic_Point< T_ > &point)
Reflects the given point vertically.
Definition: Point.h:569
Gorgon::Geometry::basic_PointProperty::basic_PointProperty
basic_PointProperty(C_ &object)
Definition: PointProperty.h:20
Gorgon::Float
float Float
Represents floating point data type.
Definition: Types.h:16
Gorgon::Property::operator*
T_ operator*() const
Definition: Property.h:80
Gorgon::Geometry::Scale
void Scale(basic_Bounds< T_ > &bounds, const O_ &size)
Scales the given bounds by the given factor. Center of the bounds is used as origin.
Definition: Bounds.h:544
Gorgon::Geometry::basic_PointProperty::Move
void Move(const T_ &x, const T_ &y)
Moves this point to the given coordinates.
Definition: PointProperty.h:198
Gorgon::Geometry::Translate
void Translate(basic_Bounds< T_ > &bounds, O_ x, O_ y)
Translation moves the given bounds by the given amount.
Definition: Bounds.h:526
Gorgon::Geometry::basic_PointProperty::ManhattanDistance
Float ManhattanDistance(const T_ &target) const
Calculates Manhattan distance from this point to the given target.
Definition: PointProperty.h:135
Gorgon::Geometry::basic_PointProperty::operator=
basic_PointProperty & operator=(basic_PointProperty &&)=default
Gorgon::Geometry::basic_PointProperty::Slope
Float Slope(const T_ &point) const
Calculates the slope of the line formed from the given point to this point.
Definition: PointProperty.h:172
Gorgon::Geometry::SkewX
void SkewX(basic_Bounds< T_ > &bounds, const O_ &rate)
Skews the given bounds with the given rate along X axis.
Definition: Bounds.h:658
Gorgon::Geometry::ReflectY
void ReflectY(basic_Point< T_ > &point)
Reflects the given point along the Y axis.
Definition: Point.h:557
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_PointProperty::operator*=
basic_PointProperty & operator*=(O_ value)
Scales this point.
Definition: PointProperty.h:92
Gorgon::Geometry::basic_PointProperty::Compare
bool Compare(const T_ &point) const
Compares two points.
Definition: PointProperty.h:183
Gorgon::Property
This is generic property that can be set and retrieved good for enums mostly, its ok to use with POD ...
Definition: Property.h:30
Gorgon::Geometry::basic_PointProperty::EuclideanSquare
Float EuclideanSquare() const
Calculates EuclideanSquare distance from this point to the given target.
Definition: PointProperty.h:131
Gorgon::Geometry::basic_PointProperty::GetX
T_::BaseType GetX() const
Returns X component.
Definition: PointProperty.h:203
Gorgon::Geometry::basic_PointProperty::operator+=
basic_PointProperty & operator+=(const T_ &point)
Adds another point from this point.
Definition: PointProperty.h:84
Gorgon::Geometry::basic_PointProperty::SetX
void SetX(const typename T_::BaseType &value)
Sets X component.
Definition: PointProperty.h:208
Gorgon::Geometry::basic_PointProperty::Angle
Float Angle(const T_ &origin) const
Calculates the angle of the line formed from the given point to this point.
Definition: PointProperty.h:158
Gorgon::Geometry::basic_PointProperty::operator+
T_ operator+(const T_ &point) const
Adds another point to this one and returns the result.
Definition: PointProperty.h:51
Gorgon::Geometry::basic_PointProperty::operator==
bool operator==(const T_ &point) const
Compares two points.
Definition: PointProperty.h:188
Gorgon::Property::Object
C_ & Object
Definition: Property.h:35
Gorgon::Geometry::basic_PointProperty::Slope
Float Slope() const
Calculates the slope of the line formed from the origin to this point.
Definition: PointProperty.h:178
Gorgon::Geometry::basic_PointProperty::basic_PointProperty
basic_PointProperty(basic_PointProperty &&)=default
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::Geometry::basic_PointProperty::basic_PointProperty
basic_PointProperty(C_ *object)
Definition: PointProperty.h:15
Gorgon::Geometry::basic_PointProperty::operator-=
basic_PointProperty & operator-=(const T_ &point)
Subtracts another point from this point.
Definition: PointProperty.h:76
Gorgon::Geometry::basic_PointProperty::operator/=
basic_PointProperty & operator/=(O_ value)
Scales this point.
Definition: PointProperty.h:100
Gorgon::Geometry::basic_PointProperty::operator/
T_ operator/(O_ value) const
Divides this point to a scalar value.
Definition: PointProperty.h:70
Gorgon::Geometry::basic_PointProperty::Distance
Float Distance(const T_ &target) const
Calculates Euclidean distance from this point to the given target.
Definition: PointProperty.h:118
Gorgon::Geometry::basic_PointProperty::CrossProduct
T_ CrossProduct(const T_ &value) const
Calculates cross product of two points.
Definition: PointProperty.h:107
Gorgon::Geometry::basic_Point::Y
T_ Y
Y coordinate.
Definition: Point.h:371
Gorgon::Property::Get
T_ Get() const
Definition: Property.h:59
Gorgon::Geometry::basic_PointProperty::Y
NumericProperty< basic_PointProperty, typename T_::BaseType, &basic_PointProperty::GetY, &basic_PointProperty::SetY > Y
Definition: PointProperty.h:223
Gorgon::Geometry::basic_PointProperty::ManhattanDistance
Float ManhattanDistance() const
Calculates Manhattan distance from this point to origin.
Definition: PointProperty.h:140
Gorgon::Geometry::HorizontalMirror
void HorizontalMirror(basic_Point< T_ > &point)
Reflects the given point horizontally.
Definition: Point.h:563
Gorgon::Geometry::basic_PointProperty::DotProduct
T_ DotProduct(const T_ &value) const
Calculates dot product of two points.
Definition: PointProperty.h:112
Gorgon::Geometry::basic_PointProperty::X
NumericProperty< basic_PointProperty, typename T_::BaseType, &basic_PointProperty::GetX, &basic_PointProperty::SetX > X
Definition: PointProperty.h:222
Gorgon::Geometry::basic_PointProperty
Property support for point class.
Definition: PointProperty.h:12
Gorgon::Geometry::Rotate
void Rotate(basic_Bounds< T_ > &bounds, Float angle)
Rotates the given bounds by the given angle.
Definition: Bounds.h:614