bool Poly::vertexInside2(const Vector2d &point, double maxoffset) const { // Shoot a ray along +X and count the number of intersections. // If n_intersections is even, return false, else return true Vector2d EndP(point.x()+10000, point.y()); int intersectcount = 1; // we want to test if uneven double maxoffsetSq = maxoffset*maxoffset; Vector2d dummy; for(size_t i=0; i<vertices.size();i++) { const Vector2d P1 = getVertexCircular(i-1); const Vector2d P2 = vertices[i]; if (point_segment_distance_Sq(point, P1, P2, dummy) <= maxoffsetSq) return true; // Skip horizontal lines, we can't intersect with them, // because the test line is horizontal if(P1.y() == P2.y()) continue; Intersection hit; if(IntersectXY(point,EndP,P1,P2,hit,maxoffset)) intersectcount++; } return (intersectcount%2==0); }
// returns length and two points double Poly::shortestConnectionSq(const Poly &p2, Vector2d &start, Vector2d &end) const { double min1 = 100000000, min2 = 100000000; int minindex1=0, minindex2=0; Vector2d onpoint1, onpoint2; // test this vertices for (uint i = 0; i < vertices.size(); i++) { for (uint j = 0; j < p2.vertices.size(); j++) { Vector2d onpoint; // on p2 // dist from point i to lines on p2 const double mindist = point_segment_distance_Sq(p2.vertices[j], p2.getVertexCircular(j+1), vertices[i], onpoint); if (mindist < min1) { min1 = mindist; onpoint1 = onpoint; minindex1 = i; } } } // test p2 vertices for (uint i = 0; i < p2.vertices.size(); i++) { for (uint j = 0; j < vertices.size(); j++) { Vector2d onpoint; // on this // dist from p2 point i to lines on this const double mindist = point_segment_distance_Sq(vertices[j], getVertexCircular(j+1), p2.vertices[i], onpoint); if (mindist < min2) { min2 = mindist; onpoint2 = onpoint; minindex2 = i; } } } if (min1 < min2) { // this vertex, some point on p2 lines start = getVertexCircular(minindex1); end = onpoint1; } else { // p2 vertex, some point of this lines start = p2.getVertexCircular(minindex2); end = onpoint2; } return (end-start).squared_length(); }