Gorgon Game Engine
SizeProperty.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "PointProperty.h"
4 #include "Size.h"
5 #include "../Property.h"
6 
7 namespace Gorgon { namespace Geometry {
8 
12  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &)>
13  class basic_SizeProperty : public Property<C_, T_, Getter_, Setter_> {
14  public:
15 
16  basic_SizeProperty(C_ *object) :
17  Property<C_,T_, Getter_, Setter_>(object),
18  Width(this), Height(this)
19  { }
20 
21  basic_SizeProperty(C_ &object) : basic_SizeProperty(&object)
22  { }
23 
25 
27 
28  operator T_() {
29  return (this->Object.*Getter_)();
30  }
31 
32  operator const T_() const {
33  return (this->Object.*Getter_)();
34  }
35 
36  basic_SizeProperty &operator =(const T_ &value) {
37  (this->Object.*Setter_)(value);
38 
39  return *this;
40  }
41 
42  T_ operator - (const T_ &point) const {
43  return this->Get() - point;
44  }
45 
47  T_ operator -() const {
48  return -this->Get();
49  }
50 
52  T_ operator + (const T_ &point) const {
53  return this->Get() + point;
54  }
55 
58  template <class O_>
59  T_ operator * (O_ value) const {
60  return this->Get() * value;
61  }
62 
64  T_ operator *(const T_ &value) const {
65  return this->Get() * value;
66  }
67 
70  template <class O_>
71  T_ operator / (O_ value) const {
72  return this->Get() / value;
73  }
74 
77  basic_SizeProperty &operator -= (const T_ &point) {
78  this->Set(this->Get() - point);
79 
80  return *this;
81  }
82 
85  basic_SizeProperty &operator += (const T_ &point) {
86  this->Set(this->Get() + point);
87 
88  return *this;
89  }
90 
92  template <class O_>
94  this->Set(this->Get() * value);
95 
96  return *this;
97  }
98 
100  template <class O_>
102  this->Set(this->Get() / value);
103 
104  return *this;
105  }
106 
108  T_ CrossProduct(const T_ &value) const {
109  return this->Get().CrossProduct(value);
110  }
111 
113  T_ DotProduct(const T_ &value) const {
114  return this->Get().DotProduct(value);
115  }
116 
117 
119  Float Distance(const T_ &target) const {
120  return this->Get().Distance(target);
121  }
123  Float EuclideanSquare(const T_ &target) const {
124  return this->Get().EuclideanSquare(target);
125  }
127  Float Distance() const {
128  return this->Get().Distance();
129  }
130 
133  return this->Get().EuclideanSquare();
134  }
136  Float ManhattanDistance(const T_ &target) const {
137  return this->Get().ManhattanDistance(target);
138  }
139 
142  return this->Get().ManhattanDistance();
143  }
144 
146  T_ Normalize() const {
147  return this->Get().Normalize();
148  }
149 
151  T_ Perpendicular() const {
152  return this->Get().Perpendicular();
153  }
154 
159  Float Angle(const T_ &origin) const {
160  return this->Get().Angle(origin);
161  }
162 
166  Float Angle() const {
167  return this->Get().Angle();
168  }
169 
173  Float Slope(const T_ &point) const {
174  return this->Get().Slope(point);
175  }
176 
179  Float Slope() const {
180  return this->Get().Slop();
181  }
182 
184  bool Compare(const T_ &point) const {
185  return this->Get().Compare(point);
186  }
187 
189  bool operator == (const T_ &point) const {
190  return Compare(point);
191  }
192 
194  bool operator !=(const T_ &point) const {
195  return !Compare(point);
196  }
197 
199  typename T_::BaseType GetWidth() const {
200  return this->Get().Width;
201  }
202 
204  void SetWidth(const typename T_::BaseType &value) {
205  this->Set({value, this->Get().Height});
206  }
207 
209  typename T_::BaseType GetHeight() const {
210  return this->Get().Height;
211  }
212 
214  void SetHeight(const typename T_::BaseType &value) {
215  this->Set({this->Get().Width, value});
216  }
217 
220  };
221 
223  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
225  auto p = point.Get();
226  Scale(p, size);
227  point.Set(p);
228  }
229 
231  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
233  auto s = l.Get();
234  Scale(s, size);
235  l.Set(s);
236  }
237 
239  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O1_, class O2_>
240  void Scale(basic_SizeProperty<C_, T_, Getter_, Setter_> &l, const O1_ &sizex, const O2_ &sizey) {
241  auto s = l.Get();
242  Scale(s, sizex, sizey);
243  l.Set(s);
244  }
245 
247  template<class C_, class T_, T_(C_::*Getter_)() const, void(C_::*Setter_)(const T_ &), class O_>
249  auto s = l.Get();
250  Scale(s, size);
251  l.Set(s);
252  }
253 
254 
255  template<class C_, Size(C_::*Getter_)() const, void(C_::*Setter_)(const Size &)>
257 
258  template<class C_, Sizef(C_::*Getter_)() const, void(C_::*Setter_)(const Sizef &)>
260 
261 } }
Gorgon::Property::Set
void Set(const T_ &value)
Definition: Property.h:63
Gorgon::Geometry::basic_SizeProperty::GetHeight
T_::BaseType GetHeight() const
Returns Height component.
Definition: SizeProperty.h:209
Gorgon::Geometry::basic_SizeProperty::Angle
Float Angle() const
Calculates the angle of the line formed from the origin to this point.
Definition: SizeProperty.h:166
Gorgon::Geometry::basic_SizeProperty::GetWidth
T_::BaseType GetWidth() const
Returns Width component.
Definition: SizeProperty.h:199
Gorgon::NumericProperty
Supports arithmetic operators including +, * ..., +=, ...
Definition: Property.h:108
Gorgon::Geometry::basic_SizeProperty::operator=
basic_SizeProperty & operator=(basic_SizeProperty &&)=default
Gorgon::Geometry::basic_SizeProperty::EuclideanSquare
Float EuclideanSquare(const T_ &target) const
Calculates EuclideanSquare distance from this point to the given target.
Definition: SizeProperty.h:123
Gorgon::Geometry::basic_SizeProperty::Height
NumericProperty< basic_SizeProperty, typename T_::BaseType, &basic_SizeProperty::GetHeight, &basic_SizeProperty::SetHeight > Height
Definition: SizeProperty.h:219
Gorgon::Geometry::basic_SizeProperty::operator+
T_ operator+(const T_ &point) const
Adds another point to this one and returns the result.
Definition: SizeProperty.h:52
Gorgon::Geometry::basic_SizeProperty::operator-
T_ operator-() const
Negates this point.
Definition: SizeProperty.h:47
Gorgon::Geometry::basic_SizeProperty::operator/=
basic_SizeProperty & operator/=(O_ value)
Scales this point.
Definition: SizeProperty.h:101
Size.h
contains the Size class
Gorgon::Geometry::basic_SizeProperty::Perpendicular
T_ Perpendicular() const
Calculates perpendicular vector to this point.
Definition: SizeProperty.h:151
PointProperty.h
Gorgon::Float
float Float
Represents floating point data type.
Definition: Types.h:16
Gorgon::Geometry::basic_SizeProperty::Slope
Float Slope(const T_ &point) const
Calculates the slope of the line formed from the given point to this point.
Definition: SizeProperty.h:173
Gorgon::Property::operator*
T_ operator*() const
Definition: Property.h:80
Gorgon::Geometry::basic_SizeProperty::Distance
Float Distance(const T_ &target) const
Calculates Euclidean distance from this point to the given target.
Definition: SizeProperty.h:119
Gorgon::Geometry::basic_SizeProperty::operator/
T_ operator/(O_ value) const
Divides this point to a scalar value.
Definition: SizeProperty.h:71
Gorgon::Geometry::basic_SizeProperty::Slope
Float Slope() const
Calculates the slope of the line formed from the origin to this point.
Definition: SizeProperty.h:179
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_SizeProperty
Property support for point class.
Definition: SizeProperty.h:13
Gorgon::Geometry::basic_SizeProperty::operator==
bool operator==(const T_ &point) const
Compares two points.
Definition: SizeProperty.h:189
Gorgon::Geometry::basic_SizeProperty::SetHeight
void SetHeight(const typename T_::BaseType &value)
Sets Height component.
Definition: SizeProperty.h:214
Gorgon::Geometry::basic_SizeProperty::EuclideanSquare
Float EuclideanSquare() const
Calculates EuclideanSquare distance from this point to the given target.
Definition: SizeProperty.h:132
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::Geometry::basic_SizeProperty::Compare
bool Compare(const T_ &point) const
Compares two points.
Definition: SizeProperty.h:184
Gorgon::Geometry::basic_SizeProperty::DotProduct
T_ DotProduct(const T_ &value) const
Calculates dot product of two points.
Definition: SizeProperty.h:113
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_SizeProperty::SetWidth
void SetWidth(const typename T_::BaseType &value)
Sets Width component.
Definition: SizeProperty.h:204
Gorgon::Geometry::basic_SizeProperty::basic_SizeProperty
basic_SizeProperty(C_ *object)
Definition: SizeProperty.h:16
Gorgon::Geometry::basic_SizeProperty::Normalize
T_ Normalize() const
Normalizes the point as a unit vector.
Definition: SizeProperty.h:146
Gorgon::Geometry::basic_SizeProperty::Distance
Float Distance() const
Calculates Euclidean distance from this point to origin.
Definition: SizeProperty.h:127
Gorgon::Geometry::basic_SizeProperty::ManhattanDistance
Float ManhattanDistance() const
Calculates Manhattan distance from this point to origin.
Definition: SizeProperty.h:141
Gorgon::Property::Object
C_ & Object
Definition: Property.h:35
Gorgon::Geometry::basic_SizeProperty::basic_SizeProperty
basic_SizeProperty(C_ &object)
Definition: SizeProperty.h:21
Gorgon::Geometry::basic_SizeProperty::Angle
Float Angle(const T_ &origin) const
Calculates the angle of the line formed from the given point to this point.
Definition: SizeProperty.h:159
Gorgon::Geometry::basic_SizeProperty::Width
NumericProperty< basic_SizeProperty, typename T_::BaseType, &basic_SizeProperty::GetWidth, &basic_SizeProperty::SetWidth > Width
Definition: SizeProperty.h:218
Gorgon::Geometry::basic_SizeProperty::operator-=
basic_SizeProperty & operator-=(const T_ &point)
Subtracts another point from this point.
Definition: SizeProperty.h:77
Gorgon::Geometry::basic_SizeProperty::CrossProduct
T_ CrossProduct(const T_ &value) const
Calculates cross product of two points.
Definition: SizeProperty.h:108
Gorgon::Geometry::basic_SizeProperty::operator+=
basic_SizeProperty & operator+=(const T_ &point)
Adds another point from this point.
Definition: SizeProperty.h:85
Gorgon::Property::Get
T_ Get() const
Definition: Property.h:59
Gorgon::Geometry::basic_SizeProperty::basic_SizeProperty
basic_SizeProperty(basic_SizeProperty &&)=default
Gorgon::Geometry::basic_SizeProperty::operator!=
bool operator!=(const T_ &point) const
Compares two points.
Definition: SizeProperty.h:194
Gorgon::Geometry::basic_SizeProperty::ManhattanDistance
Float ManhattanDistance(const T_ &target) const
Calculates Manhattan distance from this point to the given target.
Definition: SizeProperty.h:136
Gorgon::Geometry::basic_SizeProperty::operator*=
basic_SizeProperty & operator*=(O_ value)
Scales this point.
Definition: SizeProperty.h:93
Gorgon::Geometry::basic_PointProperty
Property support for point class.
Definition: PointProperty.h:12