/// <summary> /// Calculate the intersection points when a line across many segments (Special). /// </summary> /// <param name="sEqs">The segment equations.</param> /// <param name="lEq">The line equation.</param> /// <returns>Returns the intersection points.</returns> public static List <Point> GetIntersectionSp(IEnumerable <SegmentEquation> sEqs, LinearEquation lEq) { var pts = new List <Point>(); foreach (var sEq in sEqs) { var pt = SegmentEquation.GetIntersectionSp(sEq, lEq); if (null != pt && sEq.IsPointInRange(pt)) { pts.Add(pt); } } return(pts); }
/// <summary> /// Judge wether the specified point lies within the interior or on the boundary of the specified polygon. /// </summary> /// <param name="pt">The specified point.</param> /// <returns>Return true if the specified point intersects the polygon, otherwise false.</returns> public bool IsIntersects(Point pt) { var line = new LinearEquation(pt, LinearType.ParallelXAxis); var pts = SegmentEquation.GetIntersectionSp(this.sides, line); int counter = 0; foreach (var point in pts) { if (point == pt) { return(true); } else { if (point.X < pt.X) { counter++; } } } return(counter % 2 == 1); }