BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polygon_2_algorithms.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Polygon/include/CGAL/Polygon_2_algorithms.h $
00019 // $Id: Polygon_2_algorithms.h 41437 2008-01-03 19:13:08Z spion $
00020 // 
00021 //
00022 // Author(s)     : Wieger Wesselink <wieger@cs.ruu.nl>
00023 
00024 #ifndef CGAL_POLYGON_2_ALGORITHMS_H
00025 #define CGAL_POLYGON_2_ALGORITHMS_H
00026 
00027 #include <CGAL/basic.h>
00028 #include <CGAL/enum.h>
00029 #include <CGAL/Bbox_2.h>
00030 #include <CGAL/Polygon_2/polygon_assertions.h>
00031 
00032 CGAL_BEGIN_NAMESPACE
00033 
00034 //-----------------------------------------------------------------------//
00035 //                  algorithms for sequences of 2D points
00036 //-----------------------------------------------------------------------//
00037 
00038 template <class ForwardIterator, class Traits>
00039 ForwardIterator left_vertex_2(ForwardIterator first,
00040                               ForwardIterator last,
00041                               const Traits& traits);
00042 
00043 template <class ForwardIterator, class Traits>
00044 ForwardIterator right_vertex_2(ForwardIterator first,
00045                                ForwardIterator last,
00046                                const Traits& traits);
00047 
00048 template <class ForwardIterator, class Traits>
00049 ForwardIterator top_vertex_2(ForwardIterator first,
00050                              ForwardIterator last,
00051                              const Traits& traits);
00052 
00053 template <class ForwardIterator, class Traits>
00054 ForwardIterator bottom_vertex_2(ForwardIterator first,
00055                                 ForwardIterator last,
00056                                 const Traits& traits);
00057 
00058 template <class InputIterator, class Traits>
00059 Bbox_2 bbox_2(InputIterator first, 
00060               InputIterator last,
00061               const Traits& traits);
00062 
00063 
00064 template <class ForwardIterator, class Traits>
00065 void 
00066 area_2( ForwardIterator first, ForwardIterator last,
00067         typename Traits::FT &result,
00068         const Traits& traits)
00069 {
00070    typedef typename Traits::FT FT;
00071    result = FT(0);
00072    // check if the polygon is empty
00073    if (first == last) return;
00074    ForwardIterator second = first; ++second;
00075    // check if the polygon has only one point
00076    if (second == last) return;
00077    typename Traits::Compute_area_2 compute_area_2 =
00078             traits.compute_area_2_object();
00079    ForwardIterator third = second;
00080    while (++third != last) {
00081         result = result + compute_area_2(*first, *second, *third);
00082         second = third;
00083    }
00084 }
00085 
00086 template <class ForwardIterator, class Traits>
00087 typename Traits::FT 
00088 polygon_area_2( ForwardIterator first, ForwardIterator last,
00089                 const Traits& traits)
00090 {
00091    typedef typename Traits::FT FT;
00092    FT result = FT(0);
00093    // check if the polygon is empty
00094    if (first == last) return result;
00095    ForwardIterator second = first; ++second;
00096    // check if the polygon has only one point
00097    if (second == last) return result;
00098    typename Traits::Compute_area_2 compute_area_2 =
00099             traits.compute_area_2_object();
00100    ForwardIterator third = second;
00101    while (++third != last) {
00102         result = result + compute_area_2(*first, *second, *third);
00103         second = third;
00104    }
00105    return result;
00106 }
00107 
00108 template <class ForwardIterator, class Traits>
00109 bool is_convex_2(ForwardIterator first,
00110                  ForwardIterator last,
00111                  const Traits& traits);
00112 
00113 template <class ForwardIterator, class Traits>
00114 bool is_simple_2(ForwardIterator first,
00115                  ForwardIterator last,
00116                  const Traits& traits);
00117 
00118 // In the following two functions we would like to use Traits::Point_2 instead
00119 // of Point, but this is not allowed by g++ 2.7.2.
00120 
00121 template <class ForwardIterator, class Point, class Traits>
00122 Oriented_side oriented_side_2(ForwardIterator first,
00123                               ForwardIterator last,
00124                               const Point& point,
00125                               const Traits& traits);
00126 
00127 template <class ForwardIterator, class Point, class Traits>
00128 Bounded_side bounded_side_2(ForwardIterator first,
00129                             ForwardIterator last,
00130                             const Point& point,
00131                             const Traits& traits);
00132 
00133 template <class ForwardIterator, class Traits>
00134 Orientation orientation_2(ForwardIterator first,
00135                           ForwardIterator last,
00136                           const Traits& traits);
00137 
00138 //-----------------------------------------------------------------------//
00139 //                         implementation
00140 //-----------------------------------------------------------------------//
00141 
00142 template <class ForwardIterator>
00143 inline
00144 ForwardIterator left_vertex_2(ForwardIterator first,
00145                               ForwardIterator last)
00146 {  
00147   typedef typename Kernel_traits<
00148     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00149   return left_vertex_2(first, last, K());
00150 }
00151 
00152 
00153 template <class ForwardIterator>
00154 inline
00155 ForwardIterator right_vertex_2(ForwardIterator first,
00156                                ForwardIterator last)
00157 { 
00158   typedef typename Kernel_traits<
00159     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00160   return right_vertex_2(first, last, K());
00161 }
00162 
00163 
00164 template <class ForwardIterator>
00165 inline
00166 ForwardIterator top_vertex_2(ForwardIterator first,
00167                              ForwardIterator last)
00168 {
00169   typedef typename Kernel_traits<
00170     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00171   return top_vertex_2(first, last, K());
00172 }
00173 
00174 
00175 template <class ForwardIterator>
00176 inline
00177 ForwardIterator bottom_vertex_2(ForwardIterator first,
00178                                 ForwardIterator last)
00179 {
00180   typedef typename Kernel_traits<
00181     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00182   return bottom_vertex_2(first, last, K());
00183 }
00184 
00185 template <class InputIterator>
00186 inline
00187 Bbox_2 bbox_2(InputIterator first,
00188               InputIterator last)
00189 {
00190   typedef typename Kernel_traits<
00191     typename std::iterator_traits<InputIterator>::value_type>::Kernel K; 
00192   return bbox_2(first, last, K());
00193 }
00194 
00195 
00196 template <class ForwardIterator, class Numbertype>
00197 inline
00198 void area_2(ForwardIterator first,
00199             ForwardIterator last,
00200             Numbertype& result)
00201 {
00202   typedef typename Kernel_traits<
00203     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00204   area_2(first, last, result, K());
00205 }
00206 
00207 
00208 
00209 template <class ForwardIterator>
00210 inline
00211 bool is_convex_2(ForwardIterator first,
00212                  ForwardIterator last)
00213 {
00214   typedef typename Kernel_traits<
00215     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00216   return is_convex_2(first, last, K());
00217 }
00218 
00219 
00220 
00221 template <class ForwardIterator>
00222 inline
00223 bool is_simple_2(ForwardIterator first,
00224                  ForwardIterator last)
00225 {
00226   typedef typename Kernel_traits<
00227     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00228   return is_simple_2(first, last, K());
00229 }
00230 
00231 template <class ForwardIterator>
00232 inline
00233 Oriented_side oriented_side_2(
00234   ForwardIterator first,
00235   ForwardIterator last,
00236   const typename std::iterator_traits<ForwardIterator>::value_type& point)
00237 {
00238   typedef typename Kernel_traits<
00239     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00240   return oriented_side_2(first, last, point, K());
00241 }
00242 
00243 
00244 template <class ForwardIterator>
00245 inline
00246 Bounded_side bounded_side_2(
00247   ForwardIterator first,
00248   ForwardIterator last,
00249   const typename std::iterator_traits<ForwardIterator>::value_type& point)
00250 {
00251   typedef typename Kernel_traits<
00252     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00253   return bounded_side_2(first, last, point, K());
00254 }
00255 
00256 
00257 
00258 template <class ForwardIterator>
00259 inline
00260 Orientation orientation_2(ForwardIterator first,
00261                           ForwardIterator last)
00262 {
00263   typedef typename Kernel_traits<
00264     typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K; 
00265   return orientation_2(first, last, K());
00266 }
00267 
00268 CGAL_END_NAMESPACE
00269 
00270 #include <CGAL/Polygon_2/Polygon_2_algorithms_impl.h>
00271 
00272 #endif // CGAL_POLYGON_2_ALGORITHMS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines