/// <summary> /// Add a new vertice in order in the list of vertices of the polygon given the IntersectionResultArray. /// </summary> /// <param name="points"></param> /// <param name="resultArray"></param> /// <param name="curve"></param> private static CircularLinkedListNode <UV> AddPointsInList(CircularLinkedList <UV> points, IntersectionResultArray resultArray, Curve curve) { UV p0 = VectorManipulator.ProjectInPlaneXY(curve.GetEndPoint(0)); CircularLinkedListNode <UV> newNode = null; CircularLinkedListNode <UV> node = FindPoint(points, p0); IntersectionResultArrayIterator iterator = resultArray.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { IntersectionResult result = iterator.Current as IntersectionResult; UV intersectionPoint = VectorManipulator.ProjectInPlaneXY(result.XYZPoint); newNode = points.AddAfter(node, intersectionPoint); } if (newNode.Next.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Next.Value); } else if (newNode.Previous.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Previous.Value); } return(newNode); }
private static CircularLinkedListNode <UV> AddPointBetween(CircularLinkedList <UV> points, UV p0, UV p1, UV newPoint) { CircularLinkedListNode <UV> p0Node = FindPoint(points, p0); CircularLinkedListNode <UV> p1Node = FindPoint(points, p1); if (p0Node.Next.Equals(p1Node)) { return(points.AddAfter(p0Node, newPoint)); } if (p1Node.Next.Equals(p0Node)) { return(points.AddAfter(p1Node, newPoint)); } throw new ArgumentException("The points are not sequential."); }
/// <summary> /// Finds a point that /// </summary> /// <param name="points"></param> /// <param name="line1"></param> /// <param name="posibleCurves"></param> /// <returns></returns> private static CircularLinkedListNode <UV> FindNewNode(ref CircularLinkedList <UV> points, Line line, CurveArray posibleCurves, UV notch) { // iterate for each possible curve, and if // a intersection is found, the point will // be added in the linked list CircularLinkedListNode <UV> newNode = null; // get the closest point UV newPoint = null, previousPoint = null; double minDistance = double.MaxValue; foreach (Curve curve in posibleCurves) { SetComparisonResult intersection = curve.Intersect(line, out IntersectionResultArray resultArray); if (intersection == SetComparisonResult.Overlap) { IntersectionResultArrayIterator iterator = resultArray.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { IntersectionResult result = iterator.Current as IntersectionResult; UV point = VectorManipulator.ProjectInPlaneXY(result.XYZPoint); double distance = point.DistanceTo(notch); if (distance < minDistance) { minDistance = distance; newPoint = point; previousPoint = VectorManipulator.ProjectInPlaneXY(curve.GetEndPoint(0)); } } } } // insert the new point in the list CircularLinkedListNode <UV> node = FindPoint(points, previousPoint); newNode = points.AddAfter(node, newPoint); if (newNode.Next.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Next.Value); } else if (newNode.Previous.Value.IsAlmostEqualTo(newNode.Value)) { points.Remove(newNode.Previous.Value); } return(newNode); }