diff options
Diffstat (limited to 'apps/plugins/puzzles/src/hat.h')
-rw-r--r-- | apps/plugins/puzzles/src/hat.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/src/hat.h b/apps/plugins/puzzles/src/hat.h new file mode 100644 index 0000000000..39e2d31a66 --- /dev/null +++ b/apps/plugins/puzzles/src/hat.h | |||
@@ -0,0 +1,67 @@ | |||
1 | #ifndef PUZZLES_HAT_H | ||
2 | #define PUZZLES_HAT_H | ||
3 | |||
4 | struct HatPatchParams { | ||
5 | /* | ||
6 | * A patch of hat tiling is identified by giving the coordinates | ||
7 | * of the kite in one corner, using a multi-level coordinate | ||
8 | * system based on metatile expansions. Coordinates are a sequence | ||
9 | * of small non-negative integers. The valid range for each | ||
10 | * coordinate depends on the next coordinate, or on final_metatile | ||
11 | * if it's the last one in the list. The largest valid range is | ||
12 | * {0,...,12}. | ||
13 | * | ||
14 | * 'final_metatile' is one of the characters 'H', 'T', 'P' or 'F'. | ||
15 | */ | ||
16 | size_t ncoords; | ||
17 | unsigned char *coords; | ||
18 | char final_metatile; | ||
19 | }; | ||
20 | |||
21 | /* | ||
22 | * Fill in HatPatchParams with a randomly selected set of coordinates, | ||
23 | * in enough detail to generate a patch of tiling covering an area of | ||
24 | * w x h 'squares' of a kite tiling. | ||
25 | * | ||
26 | * The kites grid is considered to be oriented so that it includes | ||
27 | * horizontal lines and not vertical ones. So each of the smallest | ||
28 | * equilateral triangles in the grid has a bounding rectangle whose | ||
29 | * height is sqrt(3)/2 times its width, and either the top or the | ||
30 | * bottom of that bounding rectangle is the horizontal edge of the | ||
31 | * triangle. A 'square' of a kite tiling (for convenience of choosing | ||
32 | * grid dimensions) counts as one of those bounding rectangles. | ||
33 | * | ||
34 | * The 'coords' field of the structure will be filled in with a new | ||
35 | * dynamically allocated array. Any previous pointer in that field | ||
36 | * will be overwritten. | ||
37 | */ | ||
38 | void hat_tiling_randomise(struct HatPatchParams *params, int w, int h, | ||
39 | random_state *rs); | ||
40 | |||
41 | /* | ||
42 | * Validate a HatPatchParams to ensure it contains no illegal | ||
43 | * coordinates. Returns NULL if it's acceptable, or an error string if | ||
44 | * not. | ||
45 | */ | ||
46 | const char *hat_tiling_params_invalid(const struct HatPatchParams *params); | ||
47 | |||
48 | /* | ||
49 | * Generate the actual set of hat tiles from a HatPatchParams, passing | ||
50 | * each one to a callback. The callback receives the vertices of each | ||
51 | * point, as a sequence of 2*nvertices integers, with x,y coordinates | ||
52 | * interleaved. | ||
53 | * | ||
54 | * The x coordinates are measured in units of 1/4 of the side length | ||
55 | * of the smallest equilateral triangle, or equivalently, 1/2 the | ||
56 | * length of one of the long edges of a single kite. The y coordinates | ||
57 | * are measured in units of 1/6 the height of the triangle, which is | ||
58 | * also 1/2 the length of the short edge of a kite. Therefore, you can | ||
59 | * expect x to go up to 4*w and y up to 6*h. | ||
60 | */ | ||
61 | typedef void (*hat_tile_callback_fn)(void *ctx, size_t nvertices, | ||
62 | int *coords); | ||
63 | |||
64 | void hat_tiling_generate(const struct HatPatchParams *params, int w, int h, | ||
65 | hat_tile_callback_fn cb, void *cbctx); | ||
66 | |||
67 | #endif | ||