1 /* Tests for multidimensional Hilbert curves */
6 #include "lib/mempool.h"
12 static struct mempool *pool;
20 for (uns i = 0; i < dim; i++)
21 vec[i] = (uns)rand() >> (32 - order);
27 byte *s = mp_alloc(pool, dim * 16), *res = s;
29 for (uns i = 0; i < dim; i++)
33 s += sprintf(s, "%x", vec[i]);
41 cmp_vec(uns *vec1, uns *vec2)
43 for (uns i = dim; i--; )
44 if (vec1[i] < vec2[i])
46 else if (vec1[i] > vec2[i])
53 param_dist(uns *vec1, uns *vec2)
55 long double d1 = 0, d2 = 0;
56 for (uns i = 0; i < dim; i++)
58 d1 = (d1 + vec1[i]) / ((u64)1 << order);
59 d2 = (d2 + vec2[i]) / ((u64)1 << order);
61 return fabsl(d1 - d2);
65 vec_dist(uns *vec1, uns *vec2)
68 for (uns i = 0; i < dim; i++)
70 long double x = fabsl(vec1[i] - vec2[i]) / ((u64)1 << order);
77 #define HILBERT_PREFIX(x) test1_##x
78 #define HILBERT_DIM dim
79 #define HILBERT_ORDER order
80 #define HILBERT_WANT_DECODE
81 #define HILBERT_WANT_ENCODE
82 #include "images/hilbert.h"
87 uns a[32], b[32], c[32];
88 for (dim = 2; dim <= 8; dim++)
89 for (order = 8; order <= 32; order++)
90 for (uns i = 0; i < 1000; i++)
96 die("Error... dim=%d order=%d testnum=%d ... %s -> %s -> %s",
97 dim, order, i, print_vec(a), print_vec(b), print_vec(c));
102 #include "images/hilbert-origin.h"
108 pt.hcode[0] = 0x12345678;
109 pt.hcode[1] = 0x654321;
110 pt.hcode[2] = 0x11122233;
112 pt2 = H_decode(code);
113 DBG("origin: [%08x, %08x, %08x] --> [%08x, %08x %08x] --> [%08x, %08x %08x]",
114 pt.hcode[0], pt.hcode[1], pt.hcode[2], code.hcode[0], code.hcode[1], code.hcode[2], pt2.hcode[0], pt2.hcode[1], pt2.hcode[2]);
119 main(int argc UNUSED, char **argv UNUSED)
121 pool = mp_new(1 << 16);