public void Insert(MarkGeometryPoint point) { if (Value == null) { Value = point; } else if (IsLesser(Origin, point, Value)) { if (LeftNode == null) { LeftNode = new IntersectionsBinaryTree(Origin, point); } else { LeftNode.Insert(point); } } else { if (RightNode == null) { RightNode = new IntersectionsBinaryTree(Origin, point); } else { RightNode.Insert(point); } } }
public void InsertRange(IntersectionsBinaryTree tree) { tree.Traverse( (point) => { Insert(point); } ); }
private IntersectionsBinaryTree Intersect(MarkGeometryLine line, LineEquation equation) { if (!equation.PassesThroughRect(Boundary)) { return(null); } // using binary tree to sort points relative to the line's starting point var intersections = new IntersectionsBinaryTree(line.StartPoint); if (ChildrenExists) { IntersectionsBinaryTree childIntersections; if ((childIntersections = NorthWest.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = NorthEast.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = SouthWest.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } if ((childIntersections = SouthEast.Intersect(line)) != null) { intersections.InsertRange(childIntersections); } } MarkGeometryPoint intersection; for (int i = 0; i < Segments.Count; i++) { if (( intersection = GeometricArithmeticModule.CalculateIntersection2D( line, Segments[i] )) != null ) { intersections.Insert(intersection); } } return(intersections); }