MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Rect.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Rect.h 2D rectangle with location, width, and height
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef RECT_H
28 #define RECT_H
29 
30 #include "itype.h"
31 #include "Point.h"
32 #include "Random.h"
33 #include <stdio.h> /* For FILE */
34 
35 namespace MFM
36 {
40  class Rect
41  {
42  private:
43  SPoint m_position;
44  UPoint m_size;
45 
46  public:
47 
52  Rect() :
53  m_position(SPoint(0, 0)),
54  m_size(UPoint(0, 0))
55  { }
56 
63  Rect(const Rect & copy) :
64  m_position(copy.m_position),
65  m_size(copy.m_size)
66  { }
67 
75  Rect(const SPoint & pos, const UPoint & size)
76  : m_position(pos), m_size(size)
77  { }
78 
90  Rect(s32 x, s32 y, u32 w, u32 h) :
91  m_position(x, y),
92  m_size(w, h)
93  { }
94 
103  void IntersectWith(const Rect & other) ;
104 
112  bool IsEmpty() const
113  {
114  return m_size.IsZero();
115  }
116 
127  bool Contains(const SPoint & point)
128  {
129  return point.BoundedBy(m_position, m_position + MakeSigned(m_size));
130  }
131 
137  const SPoint & GetPosition() const
138  {
139  return m_position;
140  }
141 
147  s32 GetX() const
148  {
149  return m_position.GetX();
150  }
151 
157  s32 GetY() const
158  {
159  return m_position.GetY();
160  }
161 
167  void SetPosition(const SPoint & newPos)
168  {
169  m_position = newPos;
170  }
171 
178  void SetX(s32 newX)
179  {
180  m_position.SetX(newX);
181  }
182 
189  void SetY(s32 newY)
190  {
191  m_position.SetY(newY);
192  }
193 
199  const UPoint & GetSize() const
200  {
201  return m_size;
202  }
203 
209  u32 GetWidth() const
210  {
211  return m_size.GetX();
212  }
213 
219  u32 GetHeight() const
220  {
221  return m_size.GetY();
222  }
223 
229  void SetSize(const UPoint & newSize)
230  {
231  m_size = newSize;
232  }
233 
239  void SetWidth(u32 newWidth)
240  {
241  m_size.SetX(newWidth);
242  }
243 
249  void SetHeight(u32 newHeight)
250  {
251  m_size.SetY(newHeight);
252  }
253 
255 
264  Rect& operator=(const Rect & rhs)
265  {
266  m_position = rhs.m_position;
267  m_size = rhs.m_size;
268  return *this;
269  }
270 
279  Rect& operator&=(const Rect & rhs)
280  {
281  IntersectWith(rhs);
282  return *this;
283  }
284  };
285 } /* namespace MFM */
286 
287 #endif /*RECT_H*/
Definition: Rect.h:40
s32 GetX() const
Definition: Rect.h:147
const SPoint & GetPosition() const
Definition: Rect.h:137
void SetHeight(u32 newHeight)
Definition: Rect.h:249
void SetWidth(u32 newWidth)
Definition: Rect.h:239
Rect(s32 x, s32 y, u32 w, u32 h)
Definition: Rect.h:90
Rect()
Definition: Rect.h:52
u32 GetWidth() const
Definition: Rect.h:209
Rect(const Rect &copy)
Definition: Rect.h:63
bool IsEmpty() const
Definition: Rect.h:112
void SetSize(const UPoint &newSize)
Definition: Rect.h:229
void SetPosition(const SPoint &newPos)
Definition: Rect.h:167
Rect & operator=(const Rect &rhs)
Definition: Rect.h:264
bool BoundedBy(const Point< T > &lowerBound, const Point< T > &upperBound) const
Definition: Point.tcc:223
T GetY() const
Definition: Point.tcc:40
Rect & operator&=(const Rect &rhs)
Definition: Rect.h:279
const UPoint & GetSize() const
Definition: Rect.h:199
void SetX(T x)
Definition: Point.tcc:164
bool IsZero() const
Definition: Point.h:302
Rect(const SPoint &pos, const UPoint &size)
Definition: Rect.h:75
bool Contains(const SPoint &point)
Definition: Rect.h:127
void SetY(s32 newY)
Definition: Rect.h:189
void SetX(s32 newX)
Definition: Rect.h:178
void SetY(T y)
Definition: Point.tcc:170
void IntersectWith(const Rect &other)
Definition: Rect.cpp:6
u32 GetHeight() const
Definition: Rect.h:219
s32 GetY() const
Definition: Rect.h:157
T GetX() const
Definition: Point.tcc:34