Chemical Data Processing Library C++ API - Version 1.2.0
Rectangle2D.hpp
Go to the documentation of this file.
1 /*
2  * Rectangle2D.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_VIS_RECTANGLE2D_HPP
30 #define CDPL_VIS_RECTANGLE2D_HPP
31 
32 #include "CDPL/Vis/APIPrefix.hpp"
33 #include "CDPL/Math/Vector.hpp"
34 
35 
36 namespace CDPL
37 {
38 
39  namespace Vis
40  {
41 
51  {
52 
53  public:
61 
67  Rectangle2D(const Math::Vector2D& min, const Math::Vector2D& max);
68 
77  Rectangle2D(double min_x, double min_y, double max_x, double max_y);
78 
82  virtual ~Rectangle2D() {}
83 
92  bool isDefined() const;
93 
102  void addPoint(const Math::Vector2D& pt);
103 
113  void addPoint(double x, double y);
114 
123  void addMargin(double width, double height);
124 
133  void addRectangle(const Rectangle2D& rect);
134 
143  bool containsPoint(const Math::Vector2D& pt) const;
144 
155  bool containsPoint(double x, double y) const;
156 
165  bool containsRectangle(const Rectangle2D& rect) const;
166 
175  bool intersectsRectangle(const Rectangle2D& rect) const;
176 
181  void setMin(const Math::Vector2D& pt);
182 
188  void setMin(double x, double y);
189 
194  void setMax(const Math::Vector2D& pt);
195 
201  void setMax(double x, double y);
202 
210  void setBounds(double min_x, double min_y, double max_x, double max_y);
211 
217  void setBounds(const Math::Vector2D& min, const Math::Vector2D& max);
218 
223  const Math::Vector2D& getMin() const;
224 
229  const Math::Vector2D& getMax() const;
230 
236 
241  void getCenter(Math::Vector2D& ctr) const;
242 
251  double getWidth() const;
252 
261  double getHeight() const;
262 
267  double getArea() const;
268 
275  void reset();
276 
282 
287  void scale(double factor);
288 
294  bool operator==(const Rectangle2D& rect) const;
295 
304  bool operator!=(const Rectangle2D& rect) const;
305 
306  private:
307  Math::Vector2D min;
308  Math::Vector2D max;
309  };
310  } // namespace Vis
311 } // namespace CDPL
312 
313 #endif // CDPL_VIS_RECTANGLE2D_HPP
Definition of vector data types.
Definition of the preprocessor macro CDPL_VIS_API.
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
bool isDefined() const
Tells if the rectangle is well defined.
double getWidth() const
Returns the width of the rectangle.
const Math::Vector2D & getMin() const
Returns the minimum point of the rectangle.
void addPoint(double x, double y)
Adds the point (x, y) to the current rectangle.
void setBounds(double min_x, double min_y, double max_x, double max_y)
Sets the minimum point of the rectangle to (min_x, min_y) and the maximum point to (max_x,...
void reset()
Resets the rectangle to an undefinded state.
virtual ~Rectangle2D()
Virtual destructor.
Definition: Rectangle2D.hpp:82
Math::Vector2D getCenter() const
Calculates the center of the rectangle.
void translate(const Math::Vector2D &vec)
Translates the minimum and maximum point of the rectangle by vec.
void setMin(const Math::Vector2D &pt)
Sets the minimum point of the rectangle to pt.
void scale(double factor)
Scales the minimum and maximum point of the rectangle by the specified factor.
bool intersectsRectangle(const Rectangle2D &rect) const
Tests if the interior of this rectangle intersects the rectangle rect.
void addRectangle(const Rectangle2D &rect)
Adds the rectangle rect to the current rectangle.
bool operator==(const Rectangle2D &rect) const
Equality comparison operator.
double getArea() const
Calculates the area of the rectangle.
void setMax(double x, double y)
Sets the maximum point of the rectangle to (x, y).
void addMargin(double width, double height)
Extends the rectangle by adding a margin with the specified width and height.
Rectangle2D(double min_x, double min_y, double max_x, double max_y)
Constructs a rectangle with the minimum point set to (min_x, min_y) and the maximum point set to (max...
void addPoint(const Math::Vector2D &pt)
Adds the point pt to the current rectangle.
void getCenter(Math::Vector2D &ctr) const
Calculates the center of the rectangle and stores the result in ctr.
bool operator!=(const Rectangle2D &rect) const
Inequality comparison operator.
void setBounds(const Math::Vector2D &min, const Math::Vector2D &max)
Sets the minimum point of the rectangle to min and the maximum point to max.
void setMin(double x, double y)
Sets the minimum point of the rectangle to (x, y).
bool containsPoint(double x, double y) const
Tests if the point (x, y) is within the boundary of the rectangle.
bool containsRectangle(const Rectangle2D &rect) const
Tests if the specified rectangle rect is within the boundary of this rectangle.
Rectangle2D(const Math::Vector2D &min, const Math::Vector2D &max)
Constructs a rectangle with the minimum point set to min and the maximum point set to max.
Rectangle2D()
Constructs an undefined rectangle.
bool containsPoint(const Math::Vector2D &pt) const
Tests if the point pt is within the boundary of the rectangle.
void setMax(const Math::Vector2D &pt)
Sets the maximum point of the rectangle to pt.
const Math::Vector2D & getMax() const
Returns the maximum point of the rectangle.
double getHeight() const
Returns the height of the rectangle.
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
The namespace of the Chemical Data Processing Library.