source: rrlib_geometry/tLineSegment.h @ 59:de0986db717a

Last change on this file since 59:de0986db717a was 59:de0986db717a, checked in by Tobias Föhst <foehst@…>, 6 years ago

Reformatted with astyle 2.03

File size: 5.6 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tLineSegment.h
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-12-27
27 *
28 * \brief   Contains tLineSegment
29 *
30 * \b tLineSegment
31 *
32 * A few words for tLineSegment
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__geometry__tLineSegment_h__
37#define __rrlib__geometry__tLineSegment_h__
38
39#ifndef __rrlib__geometry__tLine_h__
40#error Invalid include directive. Try #include "rrlib/geometry/tLine.h" instead.
41#endif
42
43//----------------------------------------------------------------------
44// External includes (system with <>, local with "")
45//----------------------------------------------------------------------
46#ifdef _LIB_RRLIB_CANVAS_PRESENT_
47#include "rrlib/canvas/tCanvas2D.h"
48#endif
49
50//----------------------------------------------------------------------
51// Internal includes with ""
52//----------------------------------------------------------------------
53
54//----------------------------------------------------------------------
55// Debugging
56//----------------------------------------------------------------------
57
58//----------------------------------------------------------------------
59// Namespace declaration
60//----------------------------------------------------------------------
61namespace rrlib
62{
63namespace geometry
64{
65
66//----------------------------------------------------------------------
67// Forward declarations / typedefs / enums
68//----------------------------------------------------------------------
69
70//----------------------------------------------------------------------
71// Class declaration
72//----------------------------------------------------------------------
73//! Short description of tLineSegment
74/*! A more detailed description of tLineSegment, which
75    Tobias Foehst hasn't done yet !!
76*/
77template <size_t Tdimension, typename TElement = double>
78class tLineSegment : public tLine<Tdimension, TElement>
79{
80
81  typedef geometry::tLine<Tdimension, TElement> tLine;
82  typedef geometry::tShape<Tdimension, TElement> tShape;
83
84//----------------------------------------------------------------------
85// Public methods and typedefs
86//----------------------------------------------------------------------
87public:
88
89  tLineSegment();
90  tLineSegment(const typename tShape::tPoint &begin, const typename tShape::tPoint &end);
91
92  inline const typename tShape::tPoint &Begin() const
93  {
94    return this->Support();
95  }
96  inline const typename tShape::tPoint &End() const
97  {
98    return this->end;
99  }
100
101  void Set(const typename tShape::tPoint &begin, const typename tShape::tPoint &end);
102
103  inline const typename tShape::tPoint &MidPoint()
104  {
105    return this->CenterOfGravity();
106  }
107
108  inline const TElement Length() const
109  {
110    return (this->Begin() - this->End()).Length();
111  }
112
113  virtual const typename tShape::tPoint GetClosestPoint(const typename tShape::tPoint &reference_point) const;
114
115  virtual tLineSegment &Translate(const math::tVector<Tdimension, TElement> &translation);
116  virtual tLineSegment &Rotate(const math::tMatrix<Tdimension, Tdimension, TElement> &rotation);
117  virtual tLineSegment &Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation);
118
119//----------------------------------------------------------------------
120// Private fields and methods
121//----------------------------------------------------------------------
122private:
123
124  typename tShape::tPoint end;
125
126  virtual void UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const;
127  virtual void UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const;
128
129};
130
131typedef tLineSegment<2, double> tLineSegment2D;
132typedef tLineSegment<3, double> tLineSegment3D;
133
134//----------------------------------------------------------------------
135// Explicit template instantiation
136//----------------------------------------------------------------------
137
138extern template class tLineSegment<2, float>;
139extern template class tLineSegment<3, float>;
140
141extern template class tLineSegment<2, double>;
142extern template class tLineSegment<3, double>;
143
144extern template class tLineSegment<2, int>;
145extern template class tLineSegment<3, int>;
146
147extern template class tLineSegment<2, unsigned int>;
148extern template class tLineSegment<3, unsigned int>;
149
150//----------------------------------------------------------------------
151// Operators for rrlib_canvas
152//----------------------------------------------------------------------
153#ifdef _LIB_RRLIB_CANVAS_PRESENT_
154
155template <typename TElement>
156canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tLineSegment<2, TElement> &line);
157
158#endif
159
160//----------------------------------------------------------------------
161// End of namespace declaration
162//----------------------------------------------------------------------
163}
164}
165
166
167#include "rrlib/geometry/tLineSegment.hpp"
168
169#endif
Note: See TracBrowser for help on using the repository browser.