Inspired by this question
Another way to unroll a 2D image into a 1D string is to use an Hilbert Curve.
There are many version of this curve, depending on the number of iterations used while computing it. Below follow example of Hilbert Curves from first order to fifth order.
The way of computing this curve is the following. First we define the first order Hilbert Curve as the one shown in figure (the one for n = 1), so that it fits in a 1x1 square. We than make four copies of this curve, spacing them in a 4x4 square, so that they all present the "concavity" towards the left side. We then flip the two leftmost order 1 curves, so that the top one concavity faces toward the top, while the bottom's faces the bottom. We finally connect the the corners of the adjacent Hilbert Curves. If wanting to obtain a (n+1)-order Curve, we just need to repeat the process with four n-order Curves. We can see a visualisation of the process here (I will also add an image detailing the process soon)
Your task in this challenge is to unroll a matrix of integers along the lowest order Hilbert Curve for that matrix.
For simplicity's sake, we will have the curve starting from the top left corner of the matrix.
You can receive the input either as a list of list of integers, where each sub-list represents a row of the matrix.
You can assume that the input will be a square matrix (n*n).
[[ 1, 2,] [ 3, 4 ]]
[ 1, 2, 4, 3 ]
Since we are using the first order Hilbert Curve shown in figure
[[ 1, 2, 3, 4, ] [ 5, 6, 7, 8, ] [ 9, 10, 11, 12, ] [ 13, 14, 15, 16 ]]
[ 1, 5, 6, 2, 3, 4, 8, 7, 11, 12, 16, 15, 14, 10, 9, 13 ]
Using the second order Hilbert Curve
As usual, standard loopholes are not permitted.
This is code-golf, so the shortest answer in byte wins.