#include <vector>
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/box_intersection_d.h>
template <typename Poly>
class Polylines_do_intersect
{
typedef typename Poly::const_iterator
Iterator;
typedef typename std::iterator_traits<Iterator>::value_type Point_2;
const Poly& pA, &pB;
: Base(b,it)
{}
};
class FirstIntersection
{};
class Overlap {
const Poly& pA, &pB;
public:
Overlap(const Poly& pA, const Poly& pB)
: pA(pA), pB(pB)
{}
void operator()(const Box& a, const Box& b) {
Segment_2 sa(*(a.handle()), *(++(a.handle())));
Segment_2 sb(*(b.handle()), *(++(b.handle())));
throw FirstIntersection();
}
}
};
public:
Polylines_do_intersect(const Poly& pA, const Poly& pB)
: pA(pA), pB(pB)
{}
bool operator()() const
{
std::vector<Box> bA, bB;
bA.reserve(pA.size() - 1 );
bB.reserve(pB.size() - 1 );
for(std::size_t j=0; j < pA.size()-1; j++){
Bbox_2 bb = pA[j].bbox() + pA[j+1].bbox();
bA.push_back(Box(bb, begin+j));
}
begin = pB.begin();
for(std::size_t j=0; j < pB.size()-1; j++){
Bbox_2 bb = pB[j].bbox() + pB[j+1].bbox();
bB.push_back(Box(bb, begin+j));
}
Overlap overlap(pA,pB);
try {
} catch(const FirstIntersection& ) {
return true;
}
return false;
}
};
template <typename Poly>
bool polylines_do_intersect(const Poly& pA,const Poly& pB)
{
Polylines_do_intersect<Poly> pdi(pA,pB);
return pdi();
}
typedef K::Point_2 Point_2;
typedef std::vector<Point_2> CGAL_polyline;
int main()
{
CGAL_polyline pA = { Point_2(0,0), Point_2(1,0) };
CGAL_polyline pB = { Point_2(0,0), Point_2(0,1), Point_2(2,1) , Point_2(1,0)};
if(polylines_do_intersect(pA,pB)){
std::cout << "intersection" << std::endl;
} else {
std::cout << "no intersection" << std::endl;
}
return 0;
}
Box_with_handle_d is a generic iso-oriented bounding box in dimension that stores additionally a han...
Definition: Box_with_handle_d.h:66
void box_intersection_d(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, Callback callback, std::ptrdiff_t cutoff=10, CGAL::Box_intersection_d::Topology topology=CGAL::Box_intersection_d::CLOSED, CGAL::Box_intersection_d::Setting setting=CGAL::Box_intersection_d::BIPARTITE)
Invocation of box intersection with default box traits Box_intersection_d::Box_traits_d<Box_handle>,...
bool do_intersect(Type1< Kernel > obj1, Type2< Kernel > obj2)