/// <summary> /// Get all the Datapoints that the lines intersect. /// </summary> /// <param name="series1">line 1</param> /// <param name="series2">line 2</param> /// <returns>the collection of intersecting datapoints, null otherwise</returns> public static DataPoint[] GetAllIntersections(Series series1, Series series2) { List <DataPoint> intersections = new List <DataPoint>(); for (int i = 0; i < series1.Points.Count - 1; i++) { for (int j = 0; j < series2.Points.Count - 1; j++) { DataPoint intersection = LineUtils.IsIntersect( series1.Points[i], series1.Points[i + 1], series2.Points[j], series2.Points[j + 1]); if (intersection != null) { intersections.Add(intersection); } } } if (intersections.Count == 0) { return(null); } return(intersections.ToArray()); }
/// <summary> /// Gets a RangePolygon between two intersecting points /// </summary> /// <param name="cg">for finding the absolute coordinates</param> /// <param name="line1">line 1</param> /// <param name="line2">line 2</param> /// <param name="startPoint">the first intersection point</param> /// <param name="endPoint">the second intersection point</param> /// <param name="polygonID">id for the new polygon</param> /// <returns>a RangePolygon, null otherwise</returns> private RangePolygon GetPolygonOfIntersection(ChartGraphics cg, Series line1, Series line2, DataPoint startPoint, DataPoint endPoint, int polygonID) { //System.Console.WriteLine("GetPolygonIntersection Start: " + DateTime.Now.Millisecond); Series tempLine1 = LineUtils.PointsInRange(startPoint, endPoint, line1); Series tempLine2 = LineUtils.PointsInRange(startPoint, endPoint, line2); if (tempLine1 == null || tempLine2 == null) { return(null); } RangePolygon.RANGETYPE rType; Series topLine; Series bottomLine; if (tempLine1.Points.Count == 0) { tempLine1.Points.Add(startPoint); tempLine1.Points.Add(endPoint); } if (tempLine2.Points.Count == 0) { tempLine2.Points.Add(startPoint); tempLine2.Points.Add(endPoint); } if (LineUtils.IsAbove(tempLine1, tempLine2)) { topLine = tempLine1; bottomLine = tempLine2; rType = RangePolygon.RANGETYPE.TOP; } else { rType = RangePolygon.RANGETYPE.BOTTOM; topLine = tempLine2; bottomLine = tempLine1; } List <PointF> points = new List <PointF>(); points.Add(LineUtils.GetAbsolutePoint(cg, startPoint)); foreach (DataPoint dp in topLine.Points) { points.Add(LineUtils.GetAbsolutePoint(cg, dp)); } points.Add(LineUtils.GetAbsolutePoint(cg, endPoint)); bottomLine.Sort(PointSortOrder.Descending, "X"); foreach (DataPoint dp in bottomLine.Points) { points.Add(LineUtils.GetAbsolutePoint(cg, dp)); } points.Add(LineUtils.GetAbsolutePoint(cg, startPoint)); //System.Console.WriteLine("GetPolygonIntersection END: " + DateTime.Now.Millisecond); return(new RangePolygon(points.ToArray(), rType, polygonID)); }
/// <summary> /// Gets all the RangePolygons between line1 and line2. /// </summary> /// <param name="cg">used for getting absolute values</param> /// <param name="line1">the line that has the 'good' values</param> /// <param name="line2">the line that has the 'bad' values </param> private void FillRangePolygons(ChartGraphics cg, Series line1, Series line2) { this.ClearRangePolygons(); //System.Console.WriteLine("GetRangePolygons Start: " + DateTime.Now.Millisecond); DataPoint[] dpIntersections = LineUtils.GetAllIntersections(line1, line2); //ArrayList rPolygons = new ArrayList(); if (dpIntersections != null) { switch (dpIntersections.Length) { case 0: //this is where tehre is no intersection break; case 1: //this is the special case that there is only one intersection RangePolygon sPolygon = GetStartPolygon(cg, line1, line2, dpIntersections[0], this.rPolygons.Count); if (sPolygon != null) { rPolygons.Add(sPolygon); } RangePolygon ePolygon = GetEndPolygon(cg, line1, line2, dpIntersections[dpIntersections.Length - 1], this.rPolygons.Count); if (ePolygon != null) { rPolygons.Add(ePolygon); } break; default: if (dpIntersections.Length >= 0) { RangePolygon startPolygon = GetStartPolygon(cg, line1, line2, dpIntersections[0], this.rPolygons.Count); if (startPolygon != null) { rPolygons.Add(startPolygon); } for (int dpInterIndex = 0; dpInterIndex < dpIntersections.Length - 1; dpInterIndex++) { RangePolygon rp = GetPolygonOfIntersection(cg, line1, line2, dpIntersections[dpInterIndex], dpIntersections[dpInterIndex + 1], this.rPolygons.Count); if (rp != null) { rPolygons.Add(rp); } } RangePolygon endPolygon = GetEndPolygon(cg, line1, line2, dpIntersections[dpIntersections.Length - 1], this.rPolygons.Count); if (endPolygon != null) { rPolygons.Add(endPolygon); } } else { break; } //System.Console.WriteLine("GetRangePolygons END: " + DateTime.Now.Millisecond); break; } } }