KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_rectangle_2d.h
Go to the documentation of this file.
1 /* =========================================================================== *
2 |
3 | Copyright (c) 1994-2008 by Kobus Barnard (author).
4 |
5 | Personal and educational use of this code is granted, provided that this
6 | header is kept intact, and that the authorship is not misrepresented, that
7 | its use is acknowledged in publications, and relevant papers are cited.
8 |
9 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10 |
11 | Please note that the code in this file has not necessarily been adequately
12 | tested. Naturally, there is no guarantee of performance, support, or fitness
13 | for any particular task. Nonetheless, I am interested in hearing about
14 | problems that you encounter.
15 |
16 | Authors:
17 | Ernesto Brau
18 |
19 * =========================================================================== */
20 
30 #ifndef KJB_RECTANGLE_2D_H
31 #define KJB_RECTANGLE_2D_H
32 
33 #include <m_cpp/m_vector.h>
34 #include <m_cpp/m_matrix.h>
35 #include <g_cpp/g_util.h>
36 
37 namespace kjb {
38 
46 {
47 public:
50  (
51  const Vector& center = Vector().set(0.0, 0.0),
52  double orientation = 0.0,
53  double width = 1.0,
54  double height = 1.0
55  ) :
56  m_center(center),
57  m_orientation(orientation),
58  m_width(width),
59  m_height(height)
60  {}
61 
63  const Vector& get_center() const
64  {
65  return m_center;
66  }
67 
69  double get_orientation() const
70  {
71  return m_orientation;
72  }
73 
75  double get_width() const
76  {
77  return m_width;
78  }
79 
81  double get_height() const
82  {
83  return m_height;
84  }
85 
87  std::vector<Vector> get_corners() const;
88 
90  std::vector<Vector> get_side_midpoints() const;
91 
93  void set_center(const Vector& center)
94  {
95  m_center = center;
96  }
97 
99  void set_orientation(double orientation)
100  {
101  // TODO: keep orientation between -M_PI and M_PI.
102  m_orientation = orientation;
103  }
104 
106  void set_width(double width)
107  {
108  m_width = width;
109  }
110 
112  void set_height(double height)
113  {
114  m_height = height;
115  }
116 
117  /*===================================================================== *
118  * GEOMETRY *
119  *===================================================================== */
120 
121  void translate(const Vector& t)
122  {
123  set_center(get_center() + t);
124  }
125 
126  void rotate(double angle)
127  {
128  set_orientation(get_orientation() + angle);
129  }
130 
131  /*===================================================================== *
132  * RENDERING *
133  *===================================================================== */
134 
135  void wire_render() const;
136 
137 private:
138  Vector m_center;
139  double m_orientation;
140  double m_width;
141  double m_height;
142 
143 };
144 
145 } // namespace kjb
146 
147 #endif /*KJB_RECTANGLE_2D_H */
148 
double get_orientation() const
Returns the orientation of this rectangle.
Definition: gr_rectangle_2d.h:69
void set_height(double height)
sets the height of this rectangle.
Definition: gr_rectangle_2d.h:112
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
std::vector< Vector > get_corners() const
Returns the corners of this rectangle.
Definition: gr_rectangle_2d.cpp:7
double get_height() const
returns the height of this rectangle.
Definition: gr_rectangle_2d.h:81
void set_width(double width)
sets the width of this rectangle.
Definition: gr_rectangle_2d.h:106
height
Definition: APPgetLargeConnectedEdges.m:33
void rotate(double angle)
Definition: gr_rectangle_2d.h:126
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
std::vector< Vector > get_side_midpoints() const
Returns the midpoints of the sides of this rectangle.
Definition: gr_rectangle_2d.cpp:24
Rectangle_2d(const Vector &center=Vector().set(0.0, 0.0), double orientation=0.0, double width=1.0, double height=1.0)
Constructs a Rectangle_2d.
Definition: gr_rectangle_2d.h:50
const Vector & get_center() const
returns the center of this rectangle.
Definition: gr_rectangle_2d.h:63
double get_width() const
returns the width of this rectangle.
Definition: gr_rectangle_2d.h:75
Class that represents an axis-aligned 2D rectangle. It is defined in terms of its (2D) center...
Definition: gr_rectangle_2d.h:45
void set_orientation(double orientation)
Sets the orientation of this rectangle.
Definition: gr_rectangle_2d.h:99
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void wire_render() const
Definition: gr_rectangle_2d.cpp:41
void set_center(const Vector &center)
sets the center of this rectangle.
Definition: gr_rectangle_2d.h:93
void translate(const Vector &t)
Definition: gr_rectangle_2d.h:121