#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/iterator.h>
#include <CGAL/point_generators_2.h>
typedef K::Point_2 Point;
typedef K::Segment_2 Segment;
typedef CGAL::Random_points_on_segment_2<Point,Pt_creator> P1;
typedef CGAL::Random_points_on_circle_2<Point,Pt_creator> P2;
struct Intersector{
const Segment& s;
K::Intersect_2 intersect;
Intersector(const Segment& seg): s(seg) {}
decltype(auto)
operator() ( const Segment& other) const
{
return intersect(s, other);
}
};
int main()
{
std::vector<Segment> input;
P1 p1( Point(-100,0), Point(100,0));
P2 p2( 250);
Seg_iterator g( p1, p2);
std::copy_n( g, 200, std::back_inserter(input));
std::vector<Point> points;
std::vector<Segment> segments;
std::tuple<Point,Segment>, std::tuple< std::back_insert_iterator<std::vector<Point> >,
std::back_insert_iterator<std::vector<Segment> > > >
Dispatcher;
Dispatcher disp = CGAL::dispatch_output<Point,Segment>( std::back_inserter(points),
std::back_inserter(segments) );
std::transform( input.begin(), input.end(), disp,
Intersector(input.front()) );
std::cout << "Point intersections: " << points.size() << std::endl;
std::cout << "Segment intersections: " << segments.size() << std::endl;
return 0;
}