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? Suppose that I have a space filling curve over a rectangle of width W and height H. For example, for the rectangle:

W = 4
H = 4


I have the following curve:



Now, given the following coordinate:

X = 1
Y = 2


We can say that its position on the space-filling curve is 7, as it takes 7 steps walking over the curve to reach that tile. Using that logic, we can build a mapping width → height → x → y → index, such as:

spaceFillingIndex(4,4,1,2) = 7


As well as its inverse, width → height → index → (x,y).

spaceFillingCoordinate(4,4,7) = (1,2)


My question is: what is an algorithm that implements spaceFillingIndex, and what is an algorithm that implements spaceFillingCoodinate?
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