I have a data variable, contains, many [x,y] coordinates:
data = ([100,200],[250,110],[50,400]...)
When I receive a new [x,y], I append it to data:
data.append ([x_cor, y_cor])
BUT
I need to filter "neighbors" coordinates (to avoid appending them), whithin the a custom set "range".
For example, if I set the range to 2, then I need to filter all coordinates where either x or y coordinate is the same, or less/more with 1 or 2 round value, like e.g.:
101,200
100,199
248,111
50,400
and so on...
When the range is only 1, I can do it using an IF and a boolean by adding all variations, like this:
cord_exist = False
if ([x_cor + 1, y_cor + 1]) in data: cord_exist = True
if ([x_cor - 1, y_cor - 1]) in data: cord_exist = True
if ([x_cor + 1, y_cor]) in data: cord_exist = True
if ([x_cor, y_cor + 1]) in data: cord_exist = True
if ([x_cor - 1, y_cor]) in data: cord_exist = True
if ([x_cor, y_cor - 1]) in data: cord_exist = True
if ([x_cor + 1, y_cor - 1]) in data: cord_exist = True
if ([x_cor - 1, y_cor + 1]) in data: cord_exist = True
if cord_exist == False: data.append ([x_cor, y_cor])
This is impossible to maintain if range is 2,3 or more.
How could I solve this in a way where the range can be set freely?