[DISCUSSION] Grid snapping algorithm, and requirement of maps data structure
I am also thinking about snapping the roads to grid lines as some other issues mentioned #274 #97, which is something like minecraft needs. This is a demonstration algorithm that adds 'actuation force' to nodes based on the edge orientation. If the edge angle is too close to 0/90/180/270 (also 45/135/... if you want), it adds corresponding force couple (not exactly physical force, but like 1st order damping in heat transfer), and simulates the dynamics. For a small graph like this it can snap to grid lines in only 10 iterations. Two angle thresholds are used: 10deg, 5deg
Fig.1 Original randomly fluctuated network
Fig.2 snap within 10deg
Fig.3 snap within 5deg
In order to realize this and maybe other map editing feature, we need to add a middle layer between getting the raw data and discretizing to minecraft coordinates. A middle layer that stores the maps data we need and are able to manipulate, call algorithms like this one, rotate, scaling, translate, or maybe drag and edit in the future. For simply snapping the road system, this needs a data structure like this (in numpy for demonstration):
node = np.zeros((nNodes, 2), dtype=float) # coordinate
edge = np.zeros((nEdges, 2), dtype=int) # two nodes indexes
For buildings, it seems a little more complicated because logically they should belong to a 'cell' made up by the surrounding roads.