It must only allow a new dot to be added if it connects to either the beginning or end dot.
The beginning and end dots are constantly being updated as new dots are added, ie, if I connect dot x to the end dot, dot x will now become the end dot. I am using the following code to establish whether or not a newly selected dot connects to the existing beginning or end dot.
if((data.clickedDot.x != data.beginning.x)||(data.clickedDot.y != data.beginning.y)&&(data.clickedDot.x != data.end.x)||(data.clickedDot.y != data.end.y))
The problem is that although the new dot is connecting to an existing end or beginning dot, the algorithm returns that it isn’t.
The full code is posted here https://pastebin.com/VqxWQZeh
I thank you all for your help