/// <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); }
/// <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); }
public List <(Wall, bool[])> GetOpenWalls(List <Wall> walls) { List <(Wall, bool[])> openWalls = new List <(Wall, bool[])>(); foreach (Wall wall in walls) { Line wallLine = (wall.Location as LocationCurve).Curve as Line; bool connectedAt0 = false; bool connectedAt1 = false; XYZ p0 = wallLine.GetEndPoint(0); XYZ p1 = wallLine.GetEndPoint(1); foreach (Wall w in walls) { Line wLine = (w.Location as LocationCurve).Curve as Line; SetComparisonResult result = wallLine.Intersect(wLine, out IntersectionResultArray resultArray); if ((result != SetComparisonResult.Disjoint) && (result != SetComparisonResult.Equal)) { IntersectionResultArrayIterator iterator = resultArray.ForwardIterator(); IntersectionResult intersection = resultArray.get_Item(0); XYZ intersectionPoint = intersection.XYZPoint; if (intersectionPoint.IsAlmostEqualTo(p0)) { connectedAt0 = true; } else if (intersectionPoint.IsAlmostEqualTo(p1)) { connectedAt1 = true; } } } if (!(connectedAt0 && connectedAt1)) { bool[] openSide = { connectedAt0, connectedAt1 }; (Wall, bool[])openWall = (wall, openSide); openWalls.Add(openWall); } } return(openWalls); }