Chemical Data Processing Library C++ API - Version 1.1.1
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
CDPL::Vis::Rectangle2D::reset
void reset()
Resets the rectangle to an undefinded state.
CDPL::Vis::Rectangle2D::addPoint
void addPoint(const Math::Vector2D &pt)
Adds the point pt to the current rectangle.
CDPL::Vis::Rectangle2D::scale
void scale(double factor)
Scales the minimum and maximum point of the rectangle by the specified factor.
CDPL::Vis::Rectangle2D::~Rectangle2D
virtual ~Rectangle2D()
Virtual destructor.
Definition: Rectangle2D.hpp:82
CDPL::Vis::Rectangle2D::getMin
const Math::Vector2D & getMin() const
Returns the minimum point of the rectangle.
CDPL::Vis::Rectangle2D::setBounds
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.
CDPL::Vis::Rectangle2D::intersectsRectangle
bool intersectsRectangle(const Rectangle2D &rect) const
Tests if the interior of this rectangle intersects the rectangle rect.
CDPL::Vis::Rectangle2D::containsPoint
bool containsPoint(double x, double y) const
Tests if the point (x, y) is within the boundary of the rectangle.
CDPL::Vis::Rectangle2D::setMin
void setMin(const Math::Vector2D &pt)
Sets the minimum point of the rectangle to pt.
CDPL::Vis::Rectangle2D::getArea
double getArea() const
Calculates the area of the rectangle.
CDPL::Vis::Rectangle2D::Rectangle2D
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.
CDPL::Vis::Rectangle2D::containsPoint
bool containsPoint(const Math::Vector2D &pt) const
Tests if the point pt is within the boundary of the rectangle.
CDPL::Vis::Rectangle2D::operator!=
bool operator!=(const Rectangle2D &rect) const
Inequality comparison operator.
CDPL::Vis::Rectangle2D::addRectangle
void addRectangle(const Rectangle2D &rect)
Adds the rectangle rect to the current rectangle.
CDPL::Vis::Rectangle2D::getMax
const Math::Vector2D & getMax() const
Returns the maximum point of the rectangle.
CDPL_VIS_API
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Vis::Rectangle2D::isDefined
bool isDefined() const
Tells if the rectangle is well defined.
CDPL::Math::vec
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
CDPL::Vis::Rectangle2D::getWidth
double getWidth() const
Returns the width of the rectangle.
CDPL::Vis::Rectangle2D::getCenter
void getCenter(Math::Vector2D &ctr) const
Calculates the center of the rectangle and stores the result in ctr.
CDPL::Vis::Rectangle2D::translate
void translate(const Math::Vector2D &vec)
Translates the minimum and maximum point of the rectangle by vec.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Vis::Rectangle2D::setMax
void setMax(double x, double y)
Sets the maximum point of the rectangle to (x, y).
CDPL::Vis::Rectangle2D
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
CDPL::Vis::Rectangle2D::Rectangle2D
Rectangle2D()
Constructs an undefined rectangle.
CDPL::Math::Vector2D
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
CDPL::Vis::Rectangle2D::addPoint
void addPoint(double x, double y)
Adds the point (x, y) to the current rectangle.
CDPL::Vis::Rectangle2D::getHeight
double getHeight() const
Returns the height of the rectangle.
CDPL::Vis::Rectangle2D::setMin
void setMin(double x, double y)
Sets the minimum point of the rectangle to (x, y).
CDPL::Vis::Rectangle2D::addMargin
void addMargin(double width, double height)
Extends the rectangle by adding a margin with the specified width and height.
CDPL::Vis::Rectangle2D::getCenter
Math::Vector2D getCenter() const
Calculates the center of the rectangle.
CDPL::Vis::Rectangle2D::operator==
bool operator==(const Rectangle2D &rect) const
Equality comparison operator.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_VIS_API.
CDPL::Vis::Rectangle2D::Rectangle2D
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...
CDPL::Vis::Rectangle2D::containsRectangle
bool containsRectangle(const Rectangle2D &rect) const
Tests if the specified rectangle rect is within the boundary of this rectangle.
CDPL::Vis::Rectangle2D::setBounds
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,...
CDPL::Vis::Rectangle2D::setMax
void setMax(const Math::Vector2D &pt)
Sets the maximum point of the rectangle to pt.
Vector.hpp
Definition of vector data types.