BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Euclidean_distance.h
Go to the documentation of this file.
00001 // Copyright (c) 2002 Utrecht University (The Netherlands).
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/Spatial_searching/include/CGAL/Euclidean_distance.h $
00015 // $Id: Euclidean_distance.h 37183 2007-03-17 09:21:06Z afabri $
00016 // 
00017 //
00018 // Author(s)     : Hans Tangelder (<hanst@cs.uu.nl>)
00019 
00020 
00021 #ifndef CGAL_EUCLIDEAN_DISTANCE_H
00022 #define CGAL_EUCLIDEAN_DISTANCE_H
00023 #include <CGAL/Kd_tree_rectangle.h>
00024 
00025 namespace CGAL {
00026 
00027 
00028 
00029   template <class SearchTraits>
00030   class Euclidean_distance {
00031 
00032     public:
00033 
00034     typedef typename SearchTraits::FT    FT;
00035     typedef typename SearchTraits::Point_d Point_d;
00036     typedef Point_d Query_item;
00037     
00038     public:
00039 
00040         // default constructor
00041         Euclidean_distance() {}
00042 
00043 
00044         inline FT transformed_distance(const Query_item& q, const Point_d& p) const {
00045                 FT distance = FT(0);
00046                 typename SearchTraits::Construct_cartesian_const_iterator_d construct_it;
00047                 typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q),
00048                   qe = construct_it(q,1), pit = construct_it(p);
00049                 for(; qit != qe; qit++, pit++){
00050                   distance += ((*qit)-(*pit))*((*qit)-(*pit));
00051                 }
00052                 return distance;
00053         }
00054 
00055 
00056         inline FT min_distance_to_rectangle(const Query_item& q,
00057                                             const Kd_tree_rectangle<SearchTraits>& r) const {
00058                 FT distance = FT(0);
00059                 typename SearchTraits::Construct_cartesian_const_iterator_d construct_it;
00060                 typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q),
00061                   qe = construct_it(q,1);
00062                 for(unsigned int i = 0;qit != qe; i++, qit++){
00063                   if((*qit) < r.min_coord(i))
00064                                 distance += 
00065                                 (r.min_coord(i)-(*qit))*(r.min_coord(i)-(*qit));
00066                   else if ((*qit) > r.max_coord(i))
00067                                 distance +=  
00068                                 ((*qit)-r.max_coord(i))*((*qit)-r.max_coord(i));
00069                         
00070                 }
00071                 return distance;
00072         }
00073 
00074         inline FT max_distance_to_rectangle(const Query_item& q,
00075                                              const Kd_tree_rectangle<SearchTraits>& r) const {
00076                 FT distance=FT(0);
00077                 typename SearchTraits::Construct_cartesian_const_iterator_d construct_it;
00078                 typename SearchTraits::Cartesian_const_iterator_d qit = construct_it(q),
00079                   qe = construct_it(q,1);
00080                 for(unsigned int i = 0;qit != qe; i++, qit++){
00081                                 if ((*qit) <= (r.min_coord(i)+r.max_coord(i))/FT(2.0))
00082                                         distance += (r.max_coord(i)-(*qit))*(r.max_coord(i)-(*qit));
00083                                 else
00084                                         distance += ((*qit)-r.min_coord(i))*((*qit)-r.min_coord(i));
00085                 };
00086                 return distance;
00087         }
00088 
00089         inline FT new_distance(FT dist, FT old_off, FT new_off,
00090                                int /* cutting_dimension */)  const {
00091                 
00092                 FT new_dist = dist + new_off*new_off - old_off*old_off;
00093                 return new_dist;
00094         }
00095 
00096   inline FT transformed_distance(FT d) const {
00097                 return d*d;
00098         }
00099 
00100   inline FT inverse_of_transformed_distance(FT d) const {
00101                 return CGAL::sqrt(d);
00102         }
00103 
00104   }; // class Euclidean_distance
00105 
00106 } // namespace CGAL
00107 #endif // EUCLIDEAN_DISTANCE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines