public static int ComputeOrientation(Coordinate p1, Coordinate p2, Coordinate q) { return((int)Orientation.Index(p1, p2, q)); }
public static bool IsCCW(Coordinate[] ring) { return(Orientation.IsCCW(ring)); }
public static bool IsCCW(ICoordinateSequence ring) { return(Orientation.IsCCW(ring)); }
///<summary> /// Counts a segment ///</summary> /// <param name="p1">An endpoint of the segment</param> /// <param name="p2">Another endpoint of the segment</param> public void CountSegment(Coordinate p1, Coordinate p2) { /* * For each segment, check if it crosses * a horizontal ray running from the test point in the positive x direction. */ // check if the segment is strictly to the left of the test point if (p1.X < _p.X && p2.X < _p.X) { return; } // check if the point is equal to the current ring vertex if (_p.X == p2.X && _p.Y == p2.Y) { _isPointOnSegment = true; return; } /* * For horizontal segments, check if the point is on the segment. * Otherwise, horizontal segments are not counted. */ if (p1.Y == _p.Y && p2.Y == _p.Y) { double minx = p1.X; double maxx = p2.X; if (minx > maxx) { minx = p2.X; maxx = p1.X; } if (_p.X >= minx && _p.X <= maxx) { _isPointOnSegment = true; } return; } /* * Evaluate all non-horizontal segments which cross a horizontal ray to the * right of the test pt. To avoid double-counting shared vertices, we use the * convention that * <ul> * <li>an upward edge includes its starting endpoint, and excludes its * final endpoint * <li>a downward edge excludes its starting endpoint, and includes its * final endpoint * </ul> */ if (((p1.Y > _p.Y) && (p2.Y <= _p.Y)) || ((p2.Y > _p.Y) && (p1.Y <= _p.Y))) { var orient = Orientation.Index(p1, p2, _p); if (orient == OrientationIndex.Collinear) { _isPointOnSegment = true; return; } // Re-orient the result if needed to ensure effective segment direction is upwards if (p2.Y < p1.Y) { orient = Orientation.ReOrient(orient); } // The upward segment crosses the ray if the test point lies to the left (CCW) of the segment. if (orient == OrientationIndex.Left) { _crossingCount++; } } }