OpenMining  0.01
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Rectangle.h
Go to the documentation of this file.
1 #ifndef Rectangle_h
2 #define Rectangle_h
3 
4 namespace utils
5 {
6  template <class Tx>
7  class Width
8  {
9  public:
10  Width(Tx x) : m_width(x) {}
11  Tx m_width;
12  };
14 
15  template <class Ty>
16  class Height
17  {
18  public:
19  Height(Ty y) : m_height(y) {}
21  };
23 
24  template <class Tx, class Ty>
26  {
27  public:
28  CentrePoint(Tx x, Ty y) : m_x(x), m_y(y) {}
29  Tx m_x;
30  Ty m_y;
31  };
34 
35  template <class Tx, class Ty>
36  class Rectangle
37  {
38  public:
39  Rectangle(Tx x, Ty y) : m_width(x), m_xmin(0), m_xmax(x), m_height(y), m_ymin(0), m_ymax(y) {}
41  {
42  setCentre(centrePoint);
43  }
44 
45  void setCentre(Tx x, Ty y)
46  {
47  m_xmin = x - (m_width / 2);
48  m_xmax = x + (m_width / 2);
49  m_ymin = y - (m_height / 2);
50  m_ymax = y + (m_height / 2);
51  }
52 
53  void setCentre(const CentrePoint_t& centrePoint) { setCentre(centrePoint.m_x, centrePoint.m_y); }
55  Tx xCentre(void) const { return ((m_xmin + m_xmax) / 2); }
56  Ty yCentre(void) const { return ((m_ymin + m_ymax) / 2); }
57  Tx xMin(void) const { return m_xmin;}
58  Tx xMax(void) const { return m_xmax;}
59  Tx width(void) const { return m_width;}
60  Ty yMin(void) const { return m_ymin;}
61  Ty yMax(void) const { return m_ymax;}
62  Ty height(void) const { return m_height;}
63 
64  private:
67 
68  };
69 
71 
72  template <class Tx, class Ty>
73  std::ostream& operator<<(std::ostream& os, const Rectangle<Tx, Ty>& rectangle)
74  {
75  os << " m_xmin: " << rectangle.xMin() << ", m_xmax: " << rectangle.xMax() << ", m_width: " << rectangle.width() << ", m_ymin: " << rectangle.yMin() << ", m_ymax: " << rectangle.yMax() << ", m_height: " << rectangle.height() ;
76  return os;
77  }
78 
79 }
80 #endif
Ty m_ymax
Definition: Rectangle.h:66
Ty yCentre(void) const
Definition: Rectangle.h:56
Tx m_xmin
Definition: Rectangle.h:65
Ty m_height
Definition: Rectangle.h:66
Ty yMin(void) const
Definition: Rectangle.h:60
Ty m_ymin
Definition: Rectangle.h:66
void setCentre(const CentrePoint_t &centrePoint)
Definition: Rectangle.h:53
Height(Ty y)
Definition: Rectangle.h:19
Width< uint32_t > Width_t
Definition: Rectangle.h:13
CentrePoint< uint32_t, uint32_t > CenterPoint_t
Definition: Rectangle.h:33
Definition: Rectangle.h:25
Tx width(void) const
Definition: Rectangle.h:59
CentrePoint< Tx, Ty > centrePoint(void)
Definition: Rectangle.h:54
Tx xMax(void) const
Definition: Rectangle.h:58
void setCentre(Tx x, Ty y)
Definition: Rectangle.h:45
Definition: Rectangle.h:7
Width(Tx x)
Definition: Rectangle.h:10
Ty height(void) const
Definition: Rectangle.h:62
Tx m_x
Definition: Rectangle.h:29
Ty m_y
Definition: Rectangle.h:30
Rectangle(Tx x, Ty y)
Definition: Rectangle.h:39
Tx m_width
Definition: Rectangle.h:65
Definition: Rectangle.h:36
Tx xMin(void) const
Definition: Rectangle.h:57
Ty yMax(void) const
Definition: Rectangle.h:61
Tx m_xmax
Definition: Rectangle.h:65
CentrePoint(Tx x, Ty y)
Definition: Rectangle.h:28
Tx m_width
Definition: Rectangle.h:11
Definition: Rectangle.h:16
Height< uint32_t > Height_t
Definition: Rectangle.h:22
Rectangle(const CentrePoint< Tx, Ty > &centrePoint, const Width< Tx > &width, const Height< Ty > &height)
Definition: Rectangle.h:40
Tx xCentre(void) const
Definition: Rectangle.h:55
Ty m_height
Definition: Rectangle.h:20
CentrePoint< uint32_t, uint32_t > CentrePoint_t
Definition: Rectangle.h:32
Rectangle< uint32_t, uint32_t > Rectangle_t
Definition: Rectangle.h:70