What is an algorithm that maps back and forth from (x,y) coordinates to the index of that point in a space filling curve over a rectangle?
I found the math behind the hilbert curve very interesting (generates the space filling coordinates, with index)
http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html

Python package refer,
https://github.com/galtay/hilbertcurve

for rectangles , you need pseudo Hilbert curve generation 
https://stackoverflow.com/questions/38463130/hilbert-peano-curve-to-scan-image-of-arbitrary-size

and refer this
https://github.com/jakubcerveny/gilbert