@@ 101-112 (lines=12) @@ | ||
98 | } |
|
99 | ||
100 | ||
101 | function point_to_hilbert($x, $y, $order = 16, $map = "hilbert_map_1", $mode = "hilbert") { |
|
102 | $current_square = 'a'; |
|
103 | $position = 0; |
|
104 | foreach (range($order - 1, 0, -1) as $i) { |
|
105 | $position <<= 2; |
|
106 | $quad_x = $x & (1 << $i) ? 1 : 0; |
|
107 | $quad_y = $y & (1 << $i) ? 1 : 0; |
|
108 | list($quad_position, $current_square) = $this->{$map}[$current_square]["$quad_x, $quad_y"]; |
|
109 | $position |= $quad_position; |
|
110 | } |
|
111 | return $position; |
|
112 | } |
|
113 | ||
114 | function hilbert_to_point($hilbert, $order) { |
|
115 | $current_square = "a"; |
|
@@ 141-154 (lines=14) @@ | ||
138 | } |
|
139 | ||
140 | ||
141 | function xy2d($x, $y, $order = 16) { |
|
142 | $current_square = 'a'; |
|
143 | $position = 0; |
|
144 | ||
145 | foreach (range($order - 1, 0, -1) as $i) { |
|
146 | $position <<= 2; |
|
147 | $quad_x = $x & (1 << $i) ? 1 : 0; |
|
148 | $quad_y = $y & (1 << $i) ? 1 : 0; |
|
149 | list($quad_position, $current_square) = $this->hilbert_map[$current_square]["$quad_x, $quad_y"]; |
|
150 | $position |= $quad_position; |
|
151 | } |
|
152 | ||
153 | return $position; |
|
154 | } |
|
155 | ||
156 | function d2xy($hilbert, $order = 16) { |
|
157 | $current_square = "a"; |