Chemical Data Processing Library C++ API - Version 1.2.0
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
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 a line segment in 2D space.
Definition: Line2D.hpp:48
const Math::Vector2D & getBegin() const
Returns the starting point of the line.
bool operator!=(const Line2D &line) const
Inequality comparison operator.
Math::Vector2D getCWPerpDirection() const
Calculates the normalized direction vector rotated by 90 degrees in clockwise direction.
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...
void translateBegin(const Math::Vector2D &vec)
Translates the starting point of the line by vec.
void getCCWPerpDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction and s...
Math::Vector2D getCenter() const
Calculates the center point of the line.
double getDistance(const Math::Vector2D &pt) const
Returns the perpendicular distance of the point pt to this line.
bool operator==(const Line2D &line) const
Equality comparison operator.
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,...
const Math::Vector2D & getEnd() const
Returns the end point of the line.
bool clipEndAgainstLineSeg(const Line2D &line)
Sets the end point of the line to the point of intersection with the specified line segment.
Math::Vector2D getCCWPerpDirection() const
Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction.
void getCenter(Math::Vector2D &ctr) const
Calculates the center point of the line and stores the result in ctr.
bool setBeginToLineSegIntersection(const Line2D &line)
Sets the starting point of the line to the point of intersection with the specified line segment.
void translateEnd(const Math::Vector2D &vec)
Translates the end of the line point by vec.
void setBegin(const Math::Vector2D &pt)
Sets the starting point of the line to pt.
Math::Vector2D getDirection() const
Calculates the normalized direction vector of the line.
bool setEndToLineSegIntersection(const Line2D &line)
Sets the end point of the line to the point of intersection with the specified line segment.
double getLength() const
Returns the length of the line segment.
bool getIntersectionPoint(const Line2D &line, Math::Vector2D &pt) const
Calculates the point of intersection with the specified line and stores the result in pt.
void setBegin(double x, double y)
Sets the starting point of the line to (x, y).
void setEnd(const Math::Vector2D &pt)
Sets the end point of the line to pt.
void getCWPerpDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector rotated by 90 degrees in clockwise direction and stores th...
Line2D(const Math::Vector2D &beg, const Math::Vector2D &end)
Constructs a line with the specified starting and end point.
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,...
bool containsPoint(const Math::Vector2D &pt) const
Tests if the point pt is contained within the boundary of the line segment.
bool clipBeginAgainstRectangle(const Rectangle2D &rect)
Sets the starting point of the line to the point of intersection between this line segment and the ed...
bool clipBeginAgainstLineSeg(const Line2D &line)
Sets the starting point of the line to the point of intersection with the specified line segment.
void setEnd(double x, double y)
Sets the end point of the line to (x, y).
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.
void getDirection(Math::Vector2D &dir) const
Calculates the normalized direction vector of the line and stores the result in dir.
Line2D()
Constructs a line whose starting and end point is set to (0, 0).
virtual ~Line2D()
Virtual destructor.
Definition: Line2D.hpp:76
void translate(const Math::Vector2D &vec)
Translates the starting and end point of the line by vec.
void swapPoints()
Swaps the starting and end point of the line.
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
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.