00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef WFMATH_LINE_H
00027 #define WFMATH_LINE_H
00028
00029 #include <wfmath/const.h>
00030 #include <wfmath/point.h>
00031
00032 #include <vector>
00033
00034 namespace WFMath {
00035
00037
00041 template<int dim = 3>
00042 class Line
00043 {
00044 public:
00046 Line() : m_points() {}
00048 Line(const Line<dim>& l) : m_points(l.m_points) {}
00050 explicit Line(const AtlasInType& a);
00052 ~Line() {}
00053
00055 AtlasOutType toAtlas() const;
00057 void fromAtlas(const AtlasInType& a);
00058
00060 Line& operator=(const Line& a);
00061
00063 bool isEqualTo(const Line& s, CoordType epsilon = numeric_constants<CoordType>::epsilon()) const;
00065 bool operator==(const Line& s) const {return isEqualTo(s);}
00067 bool operator!=(const Line& s) const {return !isEqualTo(s);}
00068
00070 bool isValid() const {return m_points.size() > 1;}
00071
00072
00073
00074
00075
00077
00080 size_t numCorners() const {return m_points.size();}
00082 Point<dim> getCorner(size_t i) const {return m_points[i];}
00084 Point<dim> getCenter() const {return Barycenter(m_points);}
00085
00086
00087 bool addCorner(size_t i, const Point<dim>& p, CoordType = numeric_constants<CoordType>::epsilon())
00088 {m_points.insert(m_points.begin() + i, p); return true;}
00089
00090
00091 void removeCorner(size_t i) {m_points.erase(m_points.begin() + i);}
00092
00093 bool moveCorner(size_t i,
00094 const Point<dim>& p,
00095 CoordType = numeric_constants<CoordType>::epsilon())
00096 {m_points[i] = p; return true;}
00097
00098
00099
00101 Line& shift(const Vector<dim>& v);
00103
00106 Line& moveCornerTo(const Point<dim>& p, size_t corner)
00107 {return shift(p - getCorner(corner));}
00109
00112 Line& moveCenterTo(const Point<dim>& p)
00113 {return shift(p - getCenter());}
00114
00115
00117
00120 Line& rotateCorner(const RotMatrix<dim>& m, size_t corner)
00121 {return rotatePoint(m, getCorner(corner));}
00123
00126 Line& rotateCenter(const RotMatrix<dim>& m)
00127 {return rotatePoint(m, getCenter());}
00129
00133 Line& rotatePoint(const RotMatrix<dim>& m, const Point<dim>& p);
00134
00135 AxisBox<dim> boundingBox() const {return BoundingBox(m_points);}
00136 Ball<dim> boundingSphere() const {return BoundingSphere(m_points);}
00137 Ball<dim> boundingSphereSloppy() const {return BoundingSphereSloppy(m_points);}
00138
00139 private:
00140 std::vector<Point<dim> > m_points;
00141 typedef typename std::vector<Point<dim> >::iterator iterator;
00142 typedef typename std::vector<Point<dim> >::const_iterator const_iterator;
00143 typedef typename std::vector<Point<dim> >::size_type size_type;
00144 };
00145
00146 template<int dim>
00147 inline Line<dim>& Line<dim>::operator=(const Line& rhs)
00148 {
00149 m_points = rhs.m_points;
00150 return *this;
00151 }
00152
00153
00154 }
00155
00156 #endif // WFMATH_LINE_H