bool boundaries_intersect(const Polygon_2& P, const Polygon_2& Q, bool proper) { std::list<Segment_2> segments0, segments1; segments0.insert(segments0.end(), P.edges_begin(), P.edges_end()); segments1.insert(segments1.end(), Q.edges_begin(), Q.edges_end()); bool intersects = has_intersection(segments0.begin(), segments0.end(), segments1.begin(), segments1.end(), true, true); if (!intersects || !proper) return intersects; if (has_intersection(segments0.begin(), segments0.end(), segments1.begin(), segments1.end(), false, false)) return true; typedef Polygon_2::Vertex_const_iterator Iter; for (Iter it = P.vertices_begin(); it != P.vertices_end(); ++it) { if (Q.has_on_bounded_side(*it)) return true; } for (Iter it = Q.vertices_begin(); it != Q.vertices_end(); ++it) { if (P.has_on_bounded_side(*it)) return true; } return false; }
bool can_cut(const Polygon_2& polygon, Polygon_2::Vertex_circulator p, Polygon_2::Vertex_circulator c, Polygon_2::Vertex_circulator n, const boost::unordered_map<Point_3, boost::unordered_set<Segment_3_undirected> >& point2edges) { Segment_2 seg(*p, *n); Point_2 mid((p->x()+n->x())/2.0, (p->y()+n->y())/2.0); return (CGAL::left_turn(*p, *c, *n) && is_legal(*p, *c, *n, point2edges) && !intersects_boundary(polygon, seg, true, false) && polygon.has_on_bounded_side(mid)); }
//----------------------------------------------------------------------------- bool Polygon::inside(dolfin::Point p) const { typedef CGAL::Cartesian<double> K; typedef CGAL::Point_2<K> Point_2; typedef CGAL::Polygon_2<K> Polygon_2; Polygon_2 polygon; for (const dolfin::Point& vertex : _vertices) polygon.push_back(Point_2(vertex.x(), vertex.y())); return polygon.has_on_bounded_side(Point_2(p.x(), p.y())); }