1 /* Tests for multidimensional Hilbert curves */
6 #include "lib/mempool.h"
11 static struct mempool *pool;
19 for (uns i = 0; i < dim; i++)
20 vec[i] = (uns)rand() >> (32 - order);
26 byte *s = mp_alloc(pool, dim * 16), *res = s;
28 for (uns i = 0; i < dim; i++)
32 s += sprintf(s, "%x", vec[i]);
40 cmp_vec(uns *vec1, uns *vec2)
42 for (uns i = dim; i--; )
43 if (vec1[i] < vec2[i])
45 else if (vec1[i] > vec2[i])
52 param_dist(uns *vec1, uns *vec2)
54 long double d1 = 0, d2 = 0;
55 for (uns i = 0; i < dim; i++)
57 d1 = (d1 + vec1[i]) / ((u64)1 << order);
58 d2 = (d2 + vec2[i]) / ((u64)1 << order);
60 return fabsl(d1 - d2);
64 vec_dist(uns *vec1, uns *vec2)
67 for (uns i = 0; i < dim; i++)
69 long double x = fabsl(vec1[i] - vec2[i]) / ((u64)1 << order);
76 #define HILBERT_PREFIX(x) test1_##x
77 #define HILBERT_DIM dim
78 #define HILBERT_ORDER order
79 #define HILBERT_WANT_DECODE
80 #define HILBERT_WANT_ENCODE
81 #include "images/hilbert.h"
86 uns a[32], b[32], c[32];
87 for (dim = 2; dim <= 8; dim++)
88 for (order = 8; order <= 32; order++)
89 for (uns i = 0; i < 1000; i++)
95 die("Error... dim=%d order=%d testnum=%d ... %s -> %s -> %s",
96 dim, order, i, print_vec(a), print_vec(b), print_vec(c));
101 #include "images/hilbert-origin.h"
107 pt.hcode[0] = 0x12345678;
108 pt.hcode[1] = 0x654321;
109 pt.hcode[2] = 0x11122233;
111 pt2 = H_decode(code);
112 DBG("origin: [%08x, %08x, %08x] --> [%08x, %08x %08x] --> [%08x, %08x %08x]",
113 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]);
118 main(int argc UNUSED, char **argv UNUSED)
120 pool = mp_new(1 << 16);