]> mj.ucw.cz Git - libucw.git/blob - images/hilbert-test.c
235c3ae4ebf1fe8814bbd8470a6c00b5ed594cf4
[libucw.git] / images / hilbert-test.c
1 /* Tests for multidimensional Hilbert curves */
2
3 #define LOCAL_DEBUG
4
5 #include "lib/lib.h"
6
7 #include <stdlib.h>
8
9 static uns test1_dim;
10 static uns test1_order;
11 #define HILBERT_PREFIX(x) test1_##x
12 #define HILBERT_DIM test1_dim
13 #define HILBERT_ORDER test1_order
14 #define HILBERT_WANT_DECODE
15 #define HILBERT_WANT_ENCODE
16 #include "images/hilbert.h"
17
18 static void
19 test1(void)
20 {
21   uns a[32], b[32], c[32];
22   for (test1_dim = 2; test1_dim <= 8; test1_dim++)
23     for (test1_order = 8; test1_order <= 32; test1_order++)
24       for (uns i = 0; i < 1000; i++)
25         {
26           for (uns j = 0; j < test1_dim; j++)
27             a[j] = (uns)rand() >> (32 - test1_order);
28           test1_encode(b, a);
29           test1_decode(c, b);
30           for (uns j = 0; j < test1_dim; j++)
31             if (a[j] != c[j])
32               die("Error... dim=%d order=%d testnum=%d index=%d val1=0x%08x val2=0x%08x", test1_dim, test1_order, i, j, a[j], c[j]);
33         }
34 }
35
36 #if 0
37 #include "images/hilbert-origin.h"
38 static void
39 test_origin(void)
40 {
41   Hcode code;
42   Point pt, pt2;
43   pt.hcode[0] = 0x12345678;
44   pt.hcode[1] = 0x654321;
45   pt.hcode[2] = 0x11122233;
46   code = H_encode(pt);
47   pt2 = H_decode(code);
48   DBG("origin: [%08x, %08x, %08x] --> [%08x, %08x %08x] --> [%08x, %08x %08x]", 
49     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]);
50 }
51 #endif
52
53 int
54 main(int argc UNUSED, char **argv UNUSED)
55 {
56   test1();
57   //test_origin();
58   return 0;
59 }