BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Parabola_segment_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2003,2004  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Apollonius_graph_2/include/CGAL/Parabola_segment_2.h $
00015 // $Id: Parabola_segment_2.h 46265 2008-10-14 10:43:45Z lrineau $
00016 // 
00017 //
00018 // Author(s)     : Menelaos Karavelas <mkaravel@cse.nd.edu>
00019 
00020 
00021 
00022 #ifndef CGAL_PARABOLA_SEGMENT_2_H
00023 #define CGAL_PARABOLA_SEGMENT_2_H
00024 
00025 #include <CGAL/Parabola_2.h>
00026 
00027 CGAL_BEGIN_NAMESPACE
00028 
00029 namespace Qt {
00030   template <typename K> class PainterOstream;
00031 }
00032 
00033 template < class Gt >
00034 class Parabola_segment_2 : public Parabola_2< Gt >
00035 {
00036   typedef CGAL::Parabola_2<Gt>            Base;
00037   typedef typename Base::Site_2           Site_2;
00038   typedef typename Base::FT               FT;
00039   typedef typename Base::Point_2          Point_2;
00040   typedef typename Base::Segment_2        Segment_2;
00041   typedef typename Base::Line_2           Line_2;
00042 
00043 protected:
00044   Point_2 p1, p2;
00045 
00046 public:
00047   Parabola_segment_2() : Parabola_2< Gt >() {}
00048 
00049   template<class ApolloniusSite>
00050   Parabola_segment_2(const ApolloniusSite &p, const Line_2 &l,
00051                      const Point_2 &p1, const Point_2 &p2)
00052     : Parabola_2< Gt >(p, l)
00053   {
00054     this->p1 = p1;
00055     this->p2 = p2;
00056   }
00057 
00058   Parabola_segment_2(const Point_2 &p, const Line_2 &l,
00059                      const Point_2 &p1, const Point_2 &p2)
00060     : Parabola_2< Gt >(p, l)
00061   {
00062     this->p1 = p1;
00063     this->p2 = p2;
00064   }
00065 
00066   int compute_k(const FT& tt) const {
00067     //    return int(CGAL::to_double(CGAL::sqrt(tt / this->STEP())));
00068     return int(CGAL::sqrt(CGAL::to_double(tt) / CGAL::to_double(this->STEP())));
00069   }
00070 
00071   void generate_points(std::vector<Point_2>& p) const
00072   {
00073     FT s0, s1;
00074 
00075     s0 = t(p1);
00076     s1 = t(p2);
00077 
00078     if (CGAL::compare(s0, s1) == LARGER) {
00079       std::swap(s0, s1);
00080     }
00081 
00082     p.clear();
00083 
00084     if ( !(CGAL::is_positive(s0)) &&
00085          !(CGAL::is_negative(s1)) ) {
00086       FT tt;
00087       int k;
00088 
00089       p.push_back( this->o );
00090       k = -1;
00091       tt = -this->STEP();
00092       while ( CGAL::compare(tt, s0) == LARGER ) {
00093         p.insert( p.begin(), f(tt) );
00094         k--;
00095         tt = -FT(k * k) * this->STEP();
00096       }
00097       p.insert( p.begin(), f(s0) );
00098 
00099       k = 1;
00100       tt = this->STEP();
00101       while ( CGAL::compare(tt, s1) == SMALLER ) {
00102         p.push_back( f(tt) );
00103         k++;
00104         tt = FT(k * k) * this->STEP();
00105       }
00106       p.push_back( f(s1) );
00107     } else if ( !(CGAL::is_negative(s0)) &&
00108                 !(CGAL::is_negative(s1)) ) {
00109       FT tt;
00110       int k;
00111 
00112 
00113       p.push_back( f(s0) );
00114 
00115       tt = s0;
00116       k = compute_k(tt);
00117 
00118       while ( CGAL::compare(tt, s1) == SMALLER ) {
00119         if ( CGAL::compare(tt, s0) != SMALLER )
00120           p.push_back( f(tt) );
00121         k++;
00122         tt = FT(k * k) * this->STEP();
00123       }
00124       p.push_back( f(s1) );
00125     } else {
00126       FT tt;
00127       int k;
00128 
00129       p.push_back( f(s1) );
00130 
00131       tt = s1;
00132       k = -compute_k(-tt);
00133 
00134       while ( CGAL::compare(tt, s0) == LARGER ) {
00135         if ( CGAL::compare(tt, s1) != LARGER )
00136           p.push_back( f(tt) );
00137         k--;
00138         tt = -FT(k * k) * this->STEP();
00139       }
00140       p.push_back( f(s0) );
00141     }
00142   }
00143 
00144 
00145   template< class Stream >
00146   void draw(Stream& W) const
00147   {
00148     std::vector< Point_2 > p;
00149     generate_points(p);
00150 
00151     for (unsigned int i = 0; i < p.size() - 1; i++) {
00152       W << Segment_2(p[i], p[i+1]);
00153     }
00154   }
00155 
00156   template< class K >
00157   void draw(CGAL::Qt::PainterOstream<K>& stream) const {
00158     stream.draw_parabola_segment(this->center(), this->line(), p1, p2);
00159   }
00160 };
00161 
00162 
00163 
00164 template< class Stream, class Gt >
00165 inline
00166 Stream& operator<<(Stream &s, const Parabola_segment_2<Gt> &P)
00167 {
00168   P.draw(s);
00169   return s;
00170 }
00171 
00172 CGAL_END_NAMESPACE
00173 
00174 #endif // CGAL_PARABOLA_SEGMENT_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines