// Copyright (c) 1997 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), // and Tel-Aviv University (Israel). All rights reserved. // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // // // Author(s) : Wieger Wesselink #ifndef CGAL_POLYGON_2_ALGORITHMS_H #define CGAL_POLYGON_2_ALGORITHMS_H #include #include #include #include namespace CGAL { //-----------------------------------------------------------------------// // algorithms for sequences of 2D points //-----------------------------------------------------------------------// template ForwardIterator left_vertex_2(ForwardIterator first, ForwardIterator last, const Traits& traits); template ForwardIterator right_vertex_2(ForwardIterator first, ForwardIterator last, const Traits& traits); template ForwardIterator top_vertex_2(ForwardIterator first, ForwardIterator last, const Traits& traits); template ForwardIterator bottom_vertex_2(ForwardIterator first, ForwardIterator last, const Traits& traits); template Bbox_2 bbox_2(InputIterator first, InputIterator last, const Traits& traits); template void area_2( ForwardIterator first, ForwardIterator last, typename Traits::FT &result, const Traits& traits) { typedef typename Traits::FT FT; result = FT(0); // check if the polygon is empty if (first == last) return; ForwardIterator second = first; ++second; // check if the polygon has only one point if (second == last) return; typename Traits::Compute_area_2 compute_area_2 = traits.compute_area_2_object(); ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); second = third; } } template typename Traits::FT polygon_area_2( ForwardIterator first, ForwardIterator last, const Traits& traits) { typedef typename Traits::FT FT; FT result = FT(0); // check if the polygon is empty if (first == last) return result; ForwardIterator second = first; ++second; // check if the polygon has only one point if (second == last) return result; typename Traits::Compute_area_2 compute_area_2 = traits.compute_area_2_object(); ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); second = third; } return result; } template bool is_convex_2(ForwardIterator first, ForwardIterator last, const Traits& traits); template bool is_simple_2(ForwardIterator first, ForwardIterator last, const Traits& traits); // In the following two functions we would like to use Traits::Point_2 instead // of Point, but this is not allowed by g++ 2.7.2. template Oriented_side oriented_side_2(ForwardIterator first, ForwardIterator last, const Point& point, const Traits& traits); template Bounded_side bounded_side_2(ForwardIterator first, ForwardIterator last, const Point& point, const Traits& traits); template Orientation orientation_2(ForwardIterator first, ForwardIterator last, const Traits& traits); //-----------------------------------------------------------------------// // implementation //-----------------------------------------------------------------------// template inline ForwardIterator left_vertex_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return left_vertex_2(first, last, K()); } template inline ForwardIterator right_vertex_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return right_vertex_2(first, last, K()); } template inline ForwardIterator top_vertex_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return top_vertex_2(first, last, K()); } template inline ForwardIterator bottom_vertex_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return bottom_vertex_2(first, last, K()); } template inline Bbox_2 bbox_2(InputIterator first, InputIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return bbox_2(first, last, K()); } template inline void area_2(ForwardIterator first, ForwardIterator last, Numbertype& result) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; area_2(first, last, result, K()); } template inline bool is_convex_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return is_convex_2(first, last, K()); } template inline bool is_simple_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return is_simple_2(first, last, K()); } template inline Oriented_side oriented_side_2( ForwardIterator first, ForwardIterator last, const typename std::iterator_traits::value_type& point) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return oriented_side_2(first, last, point, K()); } template inline Bounded_side bounded_side_2( ForwardIterator first, ForwardIterator last, const typename std::iterator_traits::value_type& point) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return bounded_side_2(first, last, point, K()); } template inline Orientation orientation_2(ForwardIterator first, ForwardIterator last) { typedef typename Kernel_traits< typename std::iterator_traits::value_type>::Kernel K; return orientation_2(first, last, K()); } } //namespace CGAL #include #endif // CGAL_POLYGON_2_ALGORITHMS_H