00001 
00002 
00003 #if !defined(__geom_SegmentMath_h__)
00004 #define __geom_SegmentMath_h__
00005 
00006 
00007 #if defined(DEBUG_geom) && !defined(DEBUG_SegmentMath)
00008 #define DEBUG_SegmentMath
00009 #endif
00010 
00011 #ifdef DEBUG_SegmentMath
00012 #ifndef DEBUG_Segment
00013 #define DEBUG_Segment
00014 #endif
00015 #endif
00016 
00017 #include "Segment.h"
00018 #include "content.h"
00019 
00020 #include <iosfwd>
00021 #include <cmath>
00022 
00023 BEGIN_NAMESPACE_GEOM
00024 
00026 
00033 template<int N, typename T = double>
00034 class SegmentMath : 
00035   public Segment<N,T> {
00036   
00037   
00038   
00039 
00040 private:
00041 
00042   typedef Segment<N,T> Base;
00043 
00044 public:
00045 
00047   typedef typename Base::Number Number;
00049   typedef typename Base::Point Point;
00050       
00051 private:
00052     
00053   Point _tangent;
00054   T _length;
00055     
00056 public:
00057     
00058   
00060   
00061 
00063   SegmentMath() :
00064     Base(),
00065     _tangent(),
00066     _length() 
00067   {}
00068 
00070   SegmentMath(const Point& source, const Point& target);
00071 
00073   SegmentMath(const Segment<N,T>& s)
00074     : SegmentMath(s.source(), s.target()) 
00075   {}
00076 
00078   SegmentMath(const SegmentMath& other) : 
00079     Segment<N,T>(other.getSource(), other.getTarget()), 
00080     _tangent(other._tangent),
00081     _length(other._length) 
00082   {}
00083 
00085   SegmentMath& 
00086   operator=(const SegmentMath& other);
00087 
00089   ~SegmentMath() 
00090   {}
00091 
00093   void 
00094   make(const Point& source, const Point& target);
00095 
00096   
00097   
00099   
00100 
00101   
00102   
00103   
00104 
00106   using Base::getSource;
00107 
00109   using Base::getTarget;
00110     
00111   
00112   
00113   
00114 
00116   const Point& 
00117   getTangent() const { 
00118     return _tangent; 
00119   }
00120 
00122   T 
00123   getLength() const { 
00124     return _length; 
00125   }
00126     
00127   
00128   
00130   
00131 
00133   SegmentMath& 
00134   operator+=(const Point& p);
00135 
00137   SegmentMath& 
00138   operator-=(const Point& p);
00139 
00140   
00141   
00143   
00144 
00146   bool 
00147   isValid() const;
00148 
00149   
00150 };
00151   
00152   
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00163 
00164 template<int N, typename T>
00165 inline
00166 const SegmentMath<N,T>&
00167 operator+(const SegmentMath<N,T>& x) {
00168   return x;
00169 }
00170 
00171 
00173 
00174 template<int N, typename T>
00175 inline
00176 SegmentMath<N,T> 
00177 operator-(const SegmentMath<N,T>& x) {
00178   return SegmentMath<N,T>(x.getTarget(), x.getSource());
00179 }
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00188 
00189 template<int N, typename T>
00190 SegmentMath<N,T> 
00191 operator+(const SegmentMath<N,T>& s, 
00192           const typename SegmentMath<N,T>::Point& p);
00193 
00194 
00196 
00197 template<int N, typename T>
00198 SegmentMath<N,T> 
00199 operator-(const SegmentMath<N,T>& s, 
00200           const typename SegmentMath<N,T>::Point& p);
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00209 
00210 template<int N, typename T>
00211 inline 
00212 bool 
00213 operator==(const SegmentMath<N,T>& x, const SegmentMath<N,T>& y) {
00214   return (Segment<N,T>(x) == Segment<N,T>(y) &&
00215            x.getTangent() == y.getTangent() && x.getLength() == y.getLength());
00216 }
00217 
00218 
00220 
00221 template<int N, typename T>
00222 inline 
00223 bool 
00224 operator!=(const SegmentMath<N,T>& x, const SegmentMath<N,T>& y) {
00225   return !(x == y);
00226 }
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00235 
00236 template<int N, typename T>
00237 T 
00238 computeDistance(const SegmentMath<N,T>& segment, 
00239                 const typename SegmentMath<N,T>::Point& x);
00240 
00241 
00243 
00244 template<int N, typename T>
00245 void
00246 computeClosestPoint(const SegmentMath<N,T>& segment, 
00247                     const typename SegmentMath<N,T>::Point& x, 
00248                     typename SegmentMath<N,T>::Point* closestPoint);
00249 
00250 
00252 
00253 template<int N, typename T>
00254 T 
00255 computeDistanceAndClosestPoint(const SegmentMath<N,T>& segment, 
00256                                const typename SegmentMath<N,T>::Point& x, 
00257                                typename SegmentMath<N,T>::Point* closestPoint);
00258 
00259 
00261 
00262 template<int N, typename T>
00263 T 
00264 computeUnsignedDistanceToSupportingLine
00265 (const SegmentMath<N,T>& segment, 
00266  const typename SegmentMath<N,T>::Point& x);
00267 
00268 
00270 
00271 template<int N, typename T>
00272 T 
00273 computeUnsignedDistanceAndClosestPointToSupportingLine
00274 (const SegmentMath<N,T>& segment, const typename SegmentMath<N,T>::Point& x, 
00275  typename SegmentMath<N,T>::Point* closestPoint);
00276 
00277 
00279 
00283 template<typename T>
00284 bool 
00285 computeZIntersection(const SegmentMath<3,T>& segment, T* x, T* y, T z);
00286 
00288 
00289 template<typename T>
00290 bool
00291 computeIntersection(const SegmentMath<2,T>& s1, const SegmentMath<2,T>& s2,
00292                     typename SegmentMath<2,T>::Point* intersectionPoint);
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00301 
00302 template<int N, typename T>
00303 std::istream& 
00304 operator>>(std::istream& in, SegmentMath<N,T>& s);
00305 
00306 
00308 
00309 template<int N, typename T>
00310 std::ostream& 
00311 operator<<(std::ostream& out, const SegmentMath<N,T>& s);
00312 
00313 
00314 END_NAMESPACE_GEOM
00315 
00316 #define __geom_SegmentMath_ipp__
00317 #include "SegmentMath.ipp"
00318 #undef __geom_SegmentMath_ipp__
00319   
00320 #endif