As input we only have a set of segments, here is an example :
[AB] = [(0, 0), (0, 4)] ; [BC] = [(0, 4), (2, 6)]
[CD] = [(2, 6), (4, 0)] ; [DA] = [(4, 0), (0, 0)]
[CE] = [(2, 6), (5, 6)] ; [EF] = [(5, 6), (5, 3)]
[FG] = [(5, 3), (3, 3)] ; [HI] = [(2, 1), (4, 5)]
[JK] = [(1, 3), (2, 3)] ; [KL] = [(2, 3), (1, 1)]
[LJ] = [(1, 1), (1, 3)]
(sorry i tried my best but my images are a bit blurred)
I need to find all the individual areas. From the figure above i would have 3 different areas, JKL, CEFG and {ABCD, JKL}:
Note that segments which don't make any area are ignored (such as [HI]), and an area cannot be split by a segment, e.g:
I could do it easily with some spaghetti code which would be totally unefficient, but before doing it, do you have any idea of an algorithm i can start working on? i'm looking for something as efficient as possible...