I'm having trouble forming an algorithm to determine if neighbouring coordinates form a closed link (I don't know how to describe this encapsulation), take a look at the screenshots:
My algorithm (which most probably is wrong) goes like this:
Each time a point is plotted, get all points and use recursive functions (check if x +- 1 & y +-1) to determine if they are linked to each other. Once I got all the points that are linked to the last plotted point, append them into a list and sort them with x-axis ascending. Next I check if each element in the list is neighbour to the other elements, if so I mark these two elements as a line. (Line: (pointA, pointB))
If a point has a count of >= 2, means that it form links to two or more other points, therefore if all points within the list has a count of >= 2, they form a closed link: refer to the first image.
Here come's the problem:
If I plot the points as shown in the second image, 1st and 2nd point are not linked to the last plotted 8th point, so they are not related. But the 3rd and 4th point do link to the 8th point. How do I ignore the 3rd and 4th point even though both are linked to the last plotted 8th point, and only draw lines for 5th, 6th, 7th and 8th point?
How do I modify the algorithm or is the approach totally wrong?
PS: I feel like my explanation is very poor, I hope you all understand.