vtf-logo

Ball.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__geom_kernel_Ball_h__)
00004 #define __geom_kernel_Ball_h__
00005 
00006 // If we are debugging the whole geom namespace.
00007 #if defined(DEBUG_geom) && !defined(DEBUG_Ball)
00008 #define DEBUG_Ball
00009 #endif
00010 
00011 #ifdef DEBUG_Ball
00012 #ifndef DEBUG_Point
00013 #define DEBUG_Point
00014 #endif
00015 #endif
00016 
00017 #include "Point.h"
00018 
00019 BEGIN_NAMESPACE_GEOM
00020 
00022 
00028 template<int N, typename T = double>
00029 class Ball {
00030   //
00031   // Types
00032   //
00033 
00034 public:
00035     
00037   typedef T Number;
00039   typedef ads::FixedArray<N,Number> Point;
00040 
00041   //
00042   // Data
00043   //
00044 
00045 private:
00046     
00047   Point _center;
00048   Number _radius;
00049     
00050 public:
00051     
00052   //--------------------------------------------------------------------------
00054   // @{
00055 
00057   Ball() 
00058   {}
00059 
00061   Ball(const Point& center, const Number radius) : 
00062     _center(center),
00063     _radius(radius) 
00064   {}
00065 
00067   Ball(const Ball& other) :
00068     _center(other._center),
00069     _radius(other._radius) 
00070   {}
00071 
00073   Ball& 
00074   operator=(const Ball& other);
00075 
00077   ~Ball() 
00078   {}
00079 
00081   void 
00082   make(const Point& center, const Number radius) { 
00083     _center = center;
00084     _radius = radius;
00085   }
00086 
00087   // @}
00088   //--------------------------------------------------------------------------
00090   // @{
00091 
00093   const Point&
00094   getCenter() const { 
00095     return _center; 
00096   }
00097 
00099   Number
00100   getRadius() const { 
00101     return _radius; 
00102   }
00103     
00104   // @}
00105   //--------------------------------------------------------------------------
00107   // @{
00108 
00110   void
00111   setCenter(const Point& center) { 
00112     _center = center;
00113   }
00114 
00116   void
00117   setRadius(const Number radius) { 
00118     _radius = radius;
00119   }
00120     
00121   // @}
00122   //--------------------------------------------------------------------------
00124   // @{
00125 
00127   Ball& 
00128   operator+=(const Point& x) {
00129     _center += x;
00130     return (*this);
00131   }
00132 
00134   Ball& 
00135   operator-=(const Point& x) {
00136     _center -= x;
00137     return (*this);
00138   }
00139 
00140   // @}
00141   //--------------------------------------------------------------------------
00143 
00144   
00146   bool
00147   isInside(const Point& position) const {
00148     return computeSquaredDistance(_center, position) < _radius * _radius;
00149   }
00150   
00152 };
00153 
00154 
00155 //
00156 // Equality Operators.
00157 //
00158 
00160 
00161 template<int N, typename T>
00162 inline
00163 bool 
00164 operator==(const Ball<N,T>& x, const Ball<N,T>& y) {
00165   return (x.getCenter() == y.getCenter() && x.getRadius() == y.getRadius());
00166 }
00167 
00168 
00170 
00171 template<int N, typename T>
00172 inline
00173 bool 
00174 operator!=(const Ball<N,T>& x, const Ball<N,T>& y) {
00175   return !(x == y);
00176 }
00177 
00178 
00179 //
00180 // Binary Operators.
00181 //
00182 
00184 
00185 template<int N, typename T>
00186 inline
00187 Ball<N,T> 
00188 operator+(const Ball<N,T>& b, const typename Ball<N,T>::Point& p) {
00189   return Ball<N,T>(b.getCenter() + p, b.getRadius());
00190 }
00191 
00193 
00194 template<int N, typename T>
00195 inline
00196 Ball<N,T> 
00197 operator-(const Ball<N,T>& b, const typename Ball<N,T>::Point& p) {
00198   return Ball<N,T>(b.getCenter() - p, b.getRadius());
00199 }
00200 
00201 
00202 //
00203 // File I/O Operators.
00204 //
00205 
00207 
00208 template<int N, typename T>
00209 std::istream& 
00210 operator>>(std::istream& in, Ball<N,T>& x);
00211 
00213 
00214 template<int N, typename T>
00215 inline
00216 std::ostream& 
00217 operator<<(std::ostream& out, const Ball<N,T>& x) {
00218   return out << x.getCenter() << " " << x.getRadius();
00219 }
00220 
00221 END_NAMESPACE_GEOM
00222 
00223 #define __geom_kernel_Ball_ipp__
00224 #include "Ball.ipp"
00225 #undef __geom_kernel_Ball_ipp__
00226   
00227 #endif

Generated on Fri Aug 24 12:55:51 2007 for Computational Geometry Package by  doxygen 1.4.7