Convenience constructor that uses AB as the fixed edge, and C as the first vertex of the vertex chain (equivalent to calling RestartAt(c)).
This function determines whether the edge AB intersects the edge CD. Returns +1 if AB crosses CD at a point that is interior to both edges. Returns 0 if any two vertices from different edges are the same. Returns -1 otherwise.
Like CrossingSign above, but uses the last vertex passed to one of the crossing methods (or RestartAt) as the first vertex of the current edge.
Like EdgeOrVertexCrossing above, but uses the last vertex passed to one of the crossing methods (or RestartAt) as the first vertex of the current edge.
This method extends the concept of a "crossing" to the case where AB and CD have a vertex in common. The two edges may or may not cross, according to the rules defined in VertexCrossing() below. The rules are designed so that point containment tests can be implemented simply by counting edge crossings. Similarly, determining whether one edge chain crosses another edge chain can be implemented by counting.
Call this method when your chain 'jumps' to a new place. The argument must point to a value that persists until the next call.
Returns the last vertex of the current edge chain being tested, i.e. the C vertex that will be used to construct the edge CD when one of the methods above is called.
This class allows edges to be efficiently tested for intersection with a given fixed edge AB. It is especially efficient when testing for intersection with an edge chain connecting vertices v0, v1, v2, ...
Example usage:
void CountIntersections(const S2Point& a, const S2Point& b, const vector<pair<S2Point, S2Point>>& edges) { int count = 0; S2EdgeCrosser crosser(&a, &b); for (const auto& edge : edges) { if (crosser.CrossingSign(&edge.first, &edge.second) >= 0) { ++count; } } return count; }
This class expects that the client already has all the necessary vertices stored in memory, so that this class can refer to them with pointers and does not need to make its own copies. If this is not the case (e.g., you want to pass temporary objects as vertices), see S2CopyingEdgeCrosser.