// ============================================================================ // // Copyright (c) 2000 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------------- // // release : $CGAL_Revision $ // release_date : $CGAL_Date $ // // file : include/CGAL/is_y_monotone_2.h // package : $CGAL_Package: Partition_2 $ // maintainer : Susan Hert // chapter : Planar Polygon Partitioning // // revision : $Revision$ // revision_date : $Date$ // // author(s) : Susan Hert // // coordinator : MPI (Susan Hert ) // // implementation: y-monotonicity testing for polygon // ============================================================================ #ifndef CGAL_IS_Y_MONOTONE_2_H #define CGAL_IS_Y_MONOTONE_2_H #include #include #include #include namespace CGAL { template bool is_y_monotone_2(InputIterator first, InputIterator last, const Traits& traits) { typedef typename Traits::Point_2 Point_2; typedef typename Traits::Less_yx_2 Less_yx_2; typedef std::list Vertex_list; typedef typename Vertex_list::iterator I; typedef Circulator_from_iterator Circulator; Vertex_list polygon(first, last); I n_point_ref; I s_point_ref; // find the extreme north and south points ch_n_point(polygon.begin(), polygon.end(), n_point_ref, traits); ch_s_point(polygon.begin(), polygon.end(), s_point_ref, traits); Circulator north_c(polygon.begin(), polygon.end(), n_point_ref); Circulator south_c(polygon.begin(), polygon.end(), s_point_ref); Less_yx_2 less_yx = traits.less_yx_2_object(); Circulator prev_c = south_c; Circulator c = south_c; for (c++; c != north_c; c++) { if (!less_yx(*prev_c, *c)) return false; prev_c = c; } prev_c = north_c; c = north_c; for (c++; c != south_c; c++) { if (!less_yx(*c, *prev_c)) return false; prev_c = c; } return true; } template bool is_y_monotone_2(InputIterator first, InputIterator last) { typedef typename std::iterator_traits::value_type Point_2; typedef typename Kernel_traits::Kernel K; return is_y_monotone_2(first, last, K()); } } #endif // CGAL_IS_Y_MONOTONE_2_H