00001 #include <CGAL/circulator.h>
00002 #include <CGAL/Line_2_Line_2_intersection.h>
00003
00004
00005 namespace CEP {
00006 namespace intersection {
00007
00008
00020 template <class R, class InputIterator, class OutputIterator>
00021 void slice( InputIterator points_begin, InputIterator points_end,
00022 const CGAL::Line_2<R>& l,
00023 OutputIterator left_chain,
00024 OutputIterator right_chain )
00025 {
00026 using CGAL::assign;
00027
00028 CGAL_assertion_msg( points_begin != points_end,
00029 "polygon must be non-empty" );
00030
00031 typedef CGAL::Circulator_from_iterator<InputIterator> Circulator;
00032 typedef typename std::iterator_traits<InputIterator>::value_type Point;
00033
00034 Circulator p_begin( points_begin, points_end );
00035 Circulator p = p_begin;
00036
00037 do {
00038 CGAL::Oriented_side side = l.oriented_side(*p);
00039
00040 if ( side == CGAL::ON_POSITIVE_SIDE )
00041 *left_chain++ = *p;
00042 else if ( side == CGAL::ON_NEGATIVE_SIDE )
00043 *right_chain++ = *p;
00044 else {
00045 *left_chain++ = *p;
00046 *right_chain++ = *p;
00047 }
00048
00049 if ( side != CGAL::ON_ORIENTED_BOUNDARY ) {
00050 Circulator q(p);
00051 ++q;
00052 CGAL::Oriented_side q_side = l.oriented_side(*q);
00053
00054 if ( q_side != side && q_side != CGAL::ON_ORIENTED_BOUNDARY ) {
00055 CGAL::Object o_int
00056 = CGAL::intersection( l, CGAL::Line_2<R>(*p,*q) );
00057 Point p_int;
00058 bool intersection_is_point = assign(p_int,o_int);
00059 CGAL_assertion( intersection_is_point );
00060 *left_chain++ = p_int;
00061 *right_chain++ = p_int;
00062 }
00063 }
00064 } while( ++p != p_begin );
00065 }
00066
00067
00068 }
00069 }
00070