/// <summary> /// Helper to walk a polygon, starting from a pair of intersection points. /// increment determines the direction we are walking. /// NOTE: when walking from i1 -> i2 along c, we should be moving through the interior of the polygon. /// </summary> private static Polygon WalkPolygon(Polygon parent, Polygon walking, Circle c, int pair, List <IntersectionPoint> iPoints, bool increment) { Polygon newPoly = new Polygon(); IntersectionPoint iPoint1, iPoint2; GetPairPoints(iPoints, pair, increment, out iPoint1, out iPoint2); Vector3D startLocation = iPoint1.Location; int iSeg = 0; Segment current = SplicedArc(parent, c, iPoints, ref pair, increment, ref iSeg); newPoly.Segments.Add(current.Clone()); while (true) { // NOTE: Since we don't allow tangent intersections, there will never // be multiple spliced arcs added in succession. // Add in the next one. current = walking.Segments[iSeg]; newPoly.Segments.Add(current.Clone()); iSeg = GetNextSegmentIndex(walking, iSeg); if (current.P2.Compare(startLocation)) { break; } // Do we need to splice in at this point? Vector3D segEnd = current.P2; if (iPoints.Select(p => p.Location).Contains(segEnd)) // ZZZ - Performance { current = SplicedArc(parent, c, iPoints, ref pair, increment, ref iSeg); newPoly.Segments.Add(current.Clone()); if (current.P2.Compare(startLocation)) { break; } } } return(newPoly); }
private static void MeshEdges(Mesh mesh, Tile tile, HashSet <Vector3D> completed, Polygon boundary) { for (int i = 0; i < tile.Boundary.Segments.Count; i++) { Segment boundarySeg = tile.Boundary.Segments[i]; Segment d1 = tile.Drawn.Segments[i]; if (completed.Contains(boundarySeg.Midpoint)) { continue; } // Find the incident segment. Segment seg2 = null, d2 = null; foreach (Tile incident in tile.EdgeIncidences) { for (int j = 0; j < incident.Boundary.Segments.Count; j++) { if (boundarySeg.Midpoint == incident.Boundary.Segments[j].Midpoint) { seg2 = incident.Boundary.Segments[j]; d2 = incident.Drawn.Segments[j]; break; } } if (seg2 != null) { break; } } // Found our incident edge? bool foundIncident = seg2 != null; if (!foundIncident) { seg2 = d2 = boundarySeg; } // Do the endpoints mismatch? if (boundarySeg.P1 != seg2.P1) { Segment clone = d2.Clone(); clone.Reverse(); d2 = clone; } // Add the two vertices (careful of orientation). if (foundIncident) { CheckAndAdd(mesh, new Mesh.Triangle(boundarySeg.P1, d1.P1, d2.P1), boundary); CheckAndAdd(mesh, new Mesh.Triangle(boundarySeg.P2, d2.P2, d1.P2), boundary); } int num = 1 + (int)(d1.Length * m_divisions); Vector3D[] list1 = d1.Subdivide(num); Vector3D[] list2 = d2.Subdivide(num); for (int j = 0; j < num; j++) { CheckAndAdd(mesh, new Mesh.Triangle(list1[j], list1[j + 1], list2[j + 1]), boundary); CheckAndAdd(mesh, new Mesh.Triangle(list2[j], list1[j], list2[j + 1]), boundary); } completed.Add(boundarySeg.Midpoint); } }