Chemical Data Processing Library C++ API - Version 1.1.1
Line2D.hpp
Go to the documentation of this file.
1 /*
2  * Line2D.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_LINE2D_HPP
30 #define CDPL_VIS_LINE2D_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 
42  class Rectangle2D;
43 
48  {
49 
50  public:
54  Line2D();
55 
61  Line2D(const Math::Vector2D& beg, const Math::Vector2D& end);
62 
71  Line2D(double beg_x, double beg_y, double end_x, double end_y);
72 
76  virtual ~Line2D() {}
77 
82  void setBegin(const Math::Vector2D& pt);
83 
89  void setBegin(double x, double y);
90 
95  const Math::Vector2D& getBegin() const;
96 
101  void setEnd(const Math::Vector2D& pt);
102 
108  void setEnd(double x, double y);
109 
114  const Math::Vector2D& getEnd() const;
115 
123  void setPoints(double beg_x, double beg_y, double end_x, double end_y);
124 
130  void setPoints(const Math::Vector2D& beg, const Math::Vector2D& end);
131 
137  void swapPoints();
138 
143  void getDirection(Math::Vector2D& dir) const;
144 
150 
157 
163 
170 
176 
181  void getCenter(Math::Vector2D& ctr) const;
182 
188 
193  double getLength() const;
194 
200 
206 
212 
224  bool containsPoint(const Math::Vector2D& pt) const;
225 
233  bool getIntersectionPoint(const Line2D& line, Math::Vector2D& pt) const;
234 
246  bool clipBeginAgainstLineSeg(const Line2D& line);
247 
259  bool clipEndAgainstLineSeg(const Line2D& line);
260 
273 
286 
299 
312 
322  double getDistance(const Math::Vector2D& pt) const;
323 
329  bool operator==(const Line2D& line) const;
330 
339  bool operator!=(const Line2D& line) const;
340 
341  private:
342  Math::Vector2D begin;
343  Math::Vector2D end;
344  };
345  } // namespace Vis
346 } // namespace CDPL
347 
348 #endif // CDPL_VIS_LINE2D_HPP
CDPL::Vis::Line2D::Line2D
Line2D()
Constructs a line whose starting and end point is set to (0, 0).
CDPL::Vis::Line2D::operator!=
bool operator!=(const Line2D &line) const
Inequality comparison operator.
CDPL::Vis::Line2D::setEnd
void setEnd(const Math::Vector2D &pt)
Sets the end point of the line to pt.
CDPL::Vis::Line2D::translateBegin
void translateBegin(const Math::Vector2D &vec)
Translates the starting point of the line by vec.
CDPL::Vis::Line2D::translateEnd
void translateEnd(const Math::Vector2D &vec)
Translates the end of the line point by vec.
CDPL::Vis::Line2D::setPoints
void setPoints(const Math::Vector2D &beg, const Math::Vector2D &end)
Sets the starting point of the line to beg and the end point to end.
CDPL::Vis::Line2D::setBegin
void setBegin(double x, double y)
Sets the starting point of the line to (x, y).
CDPL::Vis::Line2D::getDistance
double getDistance(const Math::Vector2D &pt) const
Returns the perpendicular distance of the point pt to this line.
CDPL::Vis::Line2D::Line2D
Line2D(double beg_x, double beg_y, double end_x, double end_y)
Constructs a line with the starting point set to (beg_x, beg_y) and the end point set to (end_x,...
CDPL::Vis::Line2D::setEnd
void setEnd(double x, double y)
Sets the end point of the line to (x, y).
CDPL::Vis::Line2D::getLength
double getLength() const
Returns the length of the line segment.
CDPL::Vis::Line2D::setBeginToLineSegIntersection
bool setBeginToLineSegIntersection(const Line2D &line)
Sets the starting point of the line to the point of intersection with the specified line segment.
CDPL::Vis::Line2D::clipEndAgainstLineSeg
bool clipEndAgainstLineSeg(const Line2D &line)
Sets the end point of the line to the point of intersection with the specified line segment.
CDPL::Vis::Line2D::getCWPerpDirection
Math::Vector2D getCWPerpDirection() const
Calculates the normalized direction vector rotated by 90 degrees in clockwise direction.
CDPL::Vis::Line2D::setPoints
void setPoints(double beg_x, double beg_y, double end_x, double end_y)
Sets the starting point of the line to (beg_x, beg_y) and the end point to (end_x,...
CDPL::Vis::Line2D::setEndToLineSegIntersection
bool setEndToLineSegIntersection(const Line2D &line)
Sets the end point of the line to the point of intersection with the specified line segment.
CDPL::Vis::Line2D::clipBeginAgainstLineSeg
bool clipBeginAgainstLineSeg(const Line2D &line)
Sets the starting point of the line to the point of intersection with the specified line segment.
CDPL::Vis::Line2D::clipEndAgainstRectangle
bool clipEndAgainstRectangle(const Rectangle2D &rect)
Sets the end point of the line to the point of intersection between this line segment and the edges o...
CDPL_VIS_API
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Vis::Line2D::setBegin
void setBegin(const Math::Vector2D &pt)
Sets the starting point of the line to pt.
CDPL::Vis::Line2D::translate
void translate(const Math::Vector2D &vec)
Translates the starting and end point of the line by vec.
CDPL::Math::vec
QuaternionVectorAdapter< E > vec(QuaternionExpression< E > &e)
Definition: QuaternionAdapter.hpp:237
CDPL::Vis::Line2D::operator==
bool operator==(const Line2D &line) const
Equality comparison operator.
CDPL::Vis::Line2D::swapPoints
void swapPoints()
Swaps the starting and end point of the line.
CDPL::Vis::Line2D::containsPoint
bool containsPoint(const Math::Vector2D &pt) const
Tests if the point pt is contained within the boundary of the line segment.
CDPL::Vis::Line2D::getCCWPerpDirection
Math::Vector2D getCCWPerpDirection() const
Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction.
CDPL::Vis::Line2D::clipBeginAgainstRectangle
bool clipBeginAgainstRectangle(const Rectangle2D &rect)
Sets the starting point of the line to the point of intersection between this line segment and the ed...
CDPL::Vis::Line2D::getBegin
const Math::Vector2D & getBegin() const
Returns the starting point of the line.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Vis::Line2D::getDirection
Math::Vector2D getDirection() const
Calculates the normalized direction vector of the line.
CDPL::Vis::Line2D::Line2D
Line2D(const Math::Vector2D &beg, const Math::Vector2D &end)
Constructs a line with the specified starting and end point.
CDPL::Vis::Rectangle2D
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
CDPL::Vis::Line2D::~Line2D
virtual ~Line2D()
Virtual destructor.
Definition: Line2D.hpp:76
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::Line2D::getIntersectionPoint
bool getIntersectionPoint(const Line2D &line, Math::Vector2D &pt) const
Calculates the point of intersection with the specified line and stores the result in pt.
CDPL::Vis::Line2D::getCWPerpDirection
void getCWPerpDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector rotated by 90 degrees in clockwise direction and stores th...
CDPL::Vis::Line2D::getCenter
void getCenter(Math::Vector2D &ctr) const
Calculates the center point of the line and stores the result in ctr.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_VIS_API.
CDPL::Vis::Line2D::getEnd
const Math::Vector2D & getEnd() const
Returns the end point of the line.
CDPL::Vis::Line2D::getCCWPerpDirection
void getCCWPerpDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction and s...
CDPL::Vis::Line2D::getDirection
void getDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector of the line and stores the result in dir.
Vector.hpp
Definition of vector data types.
CDPL::Vis::Line2D
Specifies a line segment in 2D space.
Definition: Line2D.hpp:48
CDPL::Vis::Line2D::getCenter
Math::Vector2D getCenter() const
Calculates the center point of the line.