PolyInclusionInfo pointInPoly(const std::vector<T> &points, adapt_t adapt, const P2 &p, double EPSILON, double EPSILON2) { P2Vector::size_type l = points.size(); for (unsigned i = 0; i < l; i++) { if (equal(adapt(points[i]), p, EPSILON)) return PolyInclusionInfo(POINT_VERTEX, i); } for (unsigned i = 0; i < l; i++) { unsigned j = (i + 1) % l; if (std::min(adapt(points[i]).x, adapt(points[j]).x) - EPSILON < p.x && std::max(adapt(points[i]).x, adapt(points[j]).x) + EPSILON > p.x && std::min(adapt(points[i]).y, adapt(points[j]).y) - EPSILON < p.y && std::max(adapt(points[i]).y, adapt(points[j]).y) + EPSILON > p.y && distance2(carve::geom::rayThrough(adapt(points[i]), adapt(points[j])), p) < EPSILON2) { return PolyInclusionInfo(POINT_EDGE, i); } } if (pointInPolySimple(points, adapt, p, EPSILON)) { return PolyInclusionInfo(POINT_IN); } return PolyInclusionInfo(POINT_OUT); }
bool pickContainedPoint(const std::vector<T> &poly, adapt_t adapt, P2 &result, double EPSILON) { #if defined(CARVE_DEBUG) std::cerr << "pickContainedPoint "; for (unsigned i = 0; i < poly.size(); ++i) std::cerr << " " << adapt(poly[i]); std::cerr << std::endl; #endif const size_t S = poly.size(); P2 a, b, c; for (unsigned i = 0; i < S; ++i) { a = adapt(poly[i]); b = adapt(poly[(i + 1) % S]); c = adapt(poly[(i + 2) % S]); if (cross(a - b, c - b) < 0) { P2 p = (a + b + c) / 3; if (pointInPolySimple(poly, adapt, p, EPSILON)) { result = p; return true; } } } return false; }
bool pointInPolySimple(const P2Vector &points, const P2 &p) { return pointInPolySimple(points, p2_adapt_ident(), p); }