// // Generate all covering intersection clauses; that is, generate maximal intersections (a subset of all intersections) // private void CalculateIntersections() { // // Iterate over all polygons // for (int sidesIndex = Polygon.MIN_POLY_INDEX; sidesIndex < Polygon.MAX_EXC_POLY_INDEX; sidesIndex++) { foreach (Polygon poly in polygons[sidesIndex]) { // // Add intersection clauses for all sides the polygon // List <Segment> sides = poly.orderedSides; for (int s1 = 0; s1 < sides.Count - 1; s1++) { for (int s2 = s1 + 1; s2 < sides.Count; s2++) { // The shared vertex must be a vertex of the polygon Point vertex = sides[s1].SharedVertex(sides[s2]); if (vertex != null && poly.points.Contains(vertex)) { GeometryTutorLib.Utilities.AddStructurallyUnique(ssIntersections, new Intersection(vertex, sides[s1], sides[s2])); } } } // // Handle quadrilateral diagonals // if (poly is Quadrilateral) { Quadrilateral quad = poly as Quadrilateral; if (GetMaximalProblemSegment(quad.bottomLeftTopRightDiagonal) == null) { quad.SetBottomRightDiagonalInValid(); } if (GetMaximalProblemSegment(quad.topLeftBottomRightDiagonal) == null) { quad.SetTopLeftDiagonalInValid(); } // If both diagonals exist in the figure, create an intersection and provide the quadrilateral with the intersection. if (quad.TopLeftDiagonalIsValid() && quad.BottomRightDiagonalIsValid()) { // The calculated intersection Point inter = quad.bottomLeftTopRightDiagonal.FindIntersection(quad.topLeftBottomRightDiagonal); // The actual point in the figure Point knownPt = GeometryTutorLib.Utilities.GetStructurally <Point>(allFigurePoints, inter); if (knownPt == null) { throw new Exception("Expected to find the point (did not):"); } Intersection diagInter = new Intersection(knownPt, quad.bottomLeftTopRightDiagonal, quad.topLeftBottomRightDiagonal); GeometryTutorLib.Utilities.AddStructurallyUnique <Intersection>(ssIntersections, diagInter); quad.SetIntersection(diagInter); } } } } CalculateMaximalMinimalSegments(); ConstructMaximalSegmentSegmentIntersections(); }