public void Load(IList <MapPoint> points, int firstPointIndex, int segmentLength, PolygonClosingPole closingPole) { MapPoint mapPoint = points[firstPointIndex]; MapPoint mapPoint2 = points[firstPointIndex + segmentLength - 1]; this.m_polygonIsClosed = mapPoint.Equals(mapPoint2); this.m_polygonIsCut = false; this.m_polygonPartsList = new List <PolygonPart>(); PolygonPart polygonPart = new PolygonPart(closingPole); MapPoint mapPoint3 = default(MapPoint); for (int i = 0; i < segmentLength; i++) { MapPoint mapPoint4 = points[firstPointIndex + i]; if (i == 0) { polygonPart.Points.Add(mapPoint4); } else { MapPoint mapPoint5 = mapPoint3; foreach (MapPoint item in GeoUtils.DensifyLine(mapPoint3, mapPoint4, GeoUtils.DEFAULT_DENSIFICATION_ANGLE)) { if (Math.Abs(item.X - mapPoint5.X) <= 180.0) { polygonPart.Points.Add(item); mapPoint5 = item; } else if (Math.Abs(item.X) == 180.0) { MapPoint mapPoint6 = new MapPoint(0.0 - item.X, item.Y); polygonPart.Points.Add(mapPoint6); mapPoint5 = mapPoint6; } else if (Math.Abs(mapPoint5.X) == 180.0 && polygonPart.Points.Count == 1) { mapPoint5.X = 0.0 - mapPoint5.X; polygonPart.Points[polygonPart.Points.Count - 1] = mapPoint5; polygonPart.Points.Add(item); mapPoint5 = item; } else { MapPoint mapPoint7 = default(MapPoint); MapPoint mapPoint8 = default(MapPoint); this.FindIntersectionPoints(mapPoint5, item, out mapPoint7, out mapPoint8); if (!mapPoint5.Equals(mapPoint7)) { polygonPart.Points.Add(mapPoint7); } this.m_polygonPartsList.Add(polygonPart); polygonPart = new PolygonPart(closingPole); if (!item.Equals(mapPoint8)) { polygonPart.Points.Add(mapPoint8); } polygonPart.Points.Add(item); this.m_polygonIsCut = true; mapPoint5 = item; } } mapPoint4 = mapPoint5; } mapPoint3 = mapPoint4; } if (this.m_polygonIsCut && this.m_polygonIsClosed && polygonPart.LastPoint.Equals(this.m_polygonPartsList[0].FirstPoint)) { polygonPart.Points.RemoveAt(polygonPart.Points.Count - 1); this.m_polygonPartsList[0].Points.InsertRange(0, polygonPart.Points); } else { this.m_polygonPartsList.Add(polygonPart); } if (!this.m_polygonIsCut && this.m_polygonIsClosed && Math.Abs(polygonPart.FirstPoint.X) == 180.0 && polygonPart.FirstPoint.X == 0.0 - polygonPart.LastPoint.X) { this.m_polygonIsCut = true; } }
private void FindIntersectionPoints(MapPoint point1, MapPoint point2, out MapPoint intersectionPoint1, out MapPoint intersectionPoint2) { double num = (double)((point1.X > 0.0) ? 180 : (-180)); MapPoint mapPoint = default(MapPoint); mapPoint.X = point2.X + num * 2.0; mapPoint.Y = point2.Y; double num2 = mapPoint.X - point1.X; double num3 = mapPoint.Y - point1.Y; intersectionPoint1 = default(MapPoint); intersectionPoint1.X = num; if (num2 != 0.0) { intersectionPoint1.Y = point1.Y + (num - point1.X) * num3 / num2; } else { intersectionPoint1.Y = point1.Y + num3 / 2.0; } intersectionPoint2 = default(MapPoint); intersectionPoint2.X = 0.0 - num; intersectionPoint2.Y = intersectionPoint1.Y; }