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