I have a 'square' class with the representation of its limits from the variables x1, y1 and x2, y1 these variables define points 1 and 3 of the same, in this case the coordinates would be (0,0), (10, - 10):
From this drawing I want to insert rectangular areas, also defined through x1, y1, x2, y2 coordinates, within that area. In this example case I will use the following values (input):
area1 = (0,0)(3,-3),
area2 = (4,-2)(6,-4),
area3 = (8,-1)(10,-4),
area4 = (1,-5)(6,-7),
area5 = (7,-6)(9,-9)
How to obtain a function from there that returns the rectangles (coordinates) of the largest possible areas within the remaining empty areas and not occupied within the main square, as shown in the visual representation?
Notice, the output of the function in this case should be:
outputArea1 = (3,0)(8,-2),
outputArea2 = (8,0)(10,-1),
outputArea3 = (3,0)(4,-3),
outputArea4 = (6,-2)(8,-4),
outputArea5 = (6,-4)(10,-6),
outputArea6 = (0,-5)(1,-7),
outputArea7 = (6,-6)(7,-7),
outputArea8 = (9,-6)(10,-10),
outputArea9 = (0,-7)(7,-10),
outputArea10 = (7, -7)(9,-9),
outputArea11 = (7,-8)(9,-10)
The following code demonstrates the implementation without the requested function:
class Retangle {
borderLimitX1 = 0;
borderLimitX2 = 10;
borderLimitY1 = 0;
borderLimitX2 = -10;
static void Main() {
List < Retangle > areas = new List < Retangle > ();
///areas.Add(x1,x2,y1,y2)
areas.Add(0, 0, 3, -3);
areas.Add(4, -2, 6, -4);
areas.Add(8, -1, 10, -4);
areas.Add(1, -5, 6, -7);
areas.Add(7, -6, 9, -9);
List < Retangle > remainingAreas = CalculateRemainingAreas(areas);
}
List < Retangle > CalculateRemainingAreas(List < Retangle > originalAreas) {
List < Retangle > remainingAreas = new List < Retangle > ();
///// --> Algorithm to calculate Remaining Areas <-- ///
return remainingAreas;
}
}
internal class Retangle {
int x1,
y1;
int x2,
y2;
Retangle(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
}