libwallaby  v24
The wallaby standard library
geom.hpp
Go to the documentation of this file.
1 /*
2  * geom.hpp
3  *
4  * Created on: Nov 13, 2015
5  * Author: Joshua Southerland
6  */
7 
8 #ifndef INCLUDE_WALLABY_GEOM_HPP_
9 #define INCLUDE_WALLABY_GEOM_HPP_
10 
11 
12 
13 #include "geom.h"
14 #include "export.h"
15 
16 template<typename T>
18 {
19 public:
20  Point2(const T& x, const T &y)
21  : m_x(x),
22  m_y(y)
23  {
24  }
25 
26  const T &x() const
27  {
28  return m_x;
29  }
30 
31  const T &row() const
32  {
33  return m_y;
34  }
35 
36  const T &y() const
37  {
38  return m_y;
39  }
40 
41  const T &column() const
42  {
43  return m_x;
44  }
45 
46  void setX(const T &x)
47  {
48  m_x = x;
49  }
50 
51  void setColumn(const T &column)
52  {
53  m_x = column;
54  }
55 
56  void setY(const T &y)
57  {
58  m_y = y;
59  }
60 
61  void setRow(const T &row)
62  {
63  m_y = row;
64  }
65 
66  point2 toCPoint2() const
67  {
68  return create_point2(m_x, m_y);
69  }
70 
71 private:
72  T m_x;
73  T m_y;
74 };
75 
76 template<typename T>
78 {
79 public:
80  Point3(const T& x, const T &y, const T &z)
81  : m_x(x),
82  m_y(y),
83  m_z(z)
84  {
85  }
86 
87  const T &x() const
88  {
89  return m_x;
90  }
91 
92  const T &y() const
93  {
94  return m_y;
95  }
96 
97  const T &z() const
98  {
99  return m_z;
100  }
101 
102  void setX(const T &x)
103  {
104  m_x = x;
105  }
106 
107  void setY(const T &y)
108  {
109  m_y = y;
110  }
111 
112  void setZ(const T &z)
113  {
114  m_z = z;
115  }
116 
118  {
119  return create_point3(m_x, m_y, m_z);
120  }
121 
122 private:
123  T m_x;
124  T m_y;
125  T m_z;
126 };
127 
128 template<typename T>
130 {
131 public:
132  Rect(const T &x, const T &y, const T &width, const T &height)
133  : m_x(x),
134  m_y(y),
135  m_width(width),
136  m_height(height)
137  {
138  }
139 
140  const T &x() const
141  {
142  return m_x;
143  }
144 
145  const T &y() const
146  {
147  return m_y;
148  }
149 
150  const T &width() const
151  {
152  return m_width;
153  }
154 
155  const T &height() const
156  {
157  return m_height;
158  }
159 
161  {
162  return Point2<T>(m_x + m_width / 2, m_y + m_height / 2);
163  }
164 
165  void setX(const T &x)
166  {
167  m_x = x;
168  }
169 
170  void setY(const T &y)
171  {
172  m_y = y;
173  }
174 
175  void setWidth(const T &width)
176  {
177  m_width = width;
178  }
179 
180  void setHeight(const T &height)
181  {
182  m_x = height;
183  }
184 
185  T area() const
186  {
187  return m_width * m_height;
188  }
189 
191  {
192  return create_rectangle(m_x, m_y, m_width, m_height);
193  }
194 
195 private:
196  T m_x;
197  T m_y;
198  T m_width;
199  T m_height;
200 };
201 
202 
203 
204 #endif /* INCLUDE_WALLABY_GEOM_HPP_ */
const T & width() const
Definition: geom.hpp:150
Rect(const T &x, const T &y, const T &width, const T &height)
Definition: geom.hpp:132
void setX(const T &x)
Definition: geom.hpp:165
VF EXPORT_SYM point3 create_point3(int x, int y, int z)
T area() const
Definition: geom.hpp:185
const T & y() const
Definition: geom.hpp:145
Definition: geom.hpp:129
Point2< T > center() const
Definition: geom.hpp:160
const T & height() const
Definition: geom.hpp:155
Definition: geom.h:25
Point2(const T &x, const T &y)
Definition: geom.hpp:20
rectangle toCRectangle() const
Definition: geom.hpp:190
const T & y() const
Definition: geom.hpp:92
point2 toCPoint2() const
Definition: geom.hpp:66
const T & x() const
Definition: geom.hpp:140
Definition: geom.hpp:77
const T & column() const
Definition: geom.hpp:41
const T & y() const
Definition: geom.hpp:36
VF EXPORT_SYM point2 create_point2(int x, int y)
void setWidth(const T &width)
Definition: geom.hpp:175
Definition: geom.h:32
VF EXPORT_SYM rectangle create_rectangle(int ulx, int uly, int width, int height)
void setX(const T &x)
Definition: geom.hpp:46
Definition: geom.hpp:17
Definition: geom.h:19
point3 toCPoint3() const
Definition: geom.hpp:117
void setZ(const T &z)
Definition: geom.hpp:112
void setY(const T &y)
Definition: geom.hpp:107
void setHeight(const T &height)
Definition: geom.hpp:180
#define EXPORT_SYM
Definition: export.h:14
void setX(const T &x)
Definition: geom.hpp:102
const T & z() const
Definition: geom.hpp:97
Point3(const T &x, const T &y, const T &z)
Definition: geom.hpp:80
void setColumn(const T &column)
Definition: geom.hpp:51
void setY(const T &y)
Definition: geom.hpp:170
void setRow(const T &row)
Definition: geom.hpp:61
const T & x() const
Definition: geom.hpp:26
const T & x() const
Definition: geom.hpp:87
void setY(const T &y)
Definition: geom.hpp:56
const T & row() const
Definition: geom.hpp:31