New grid type: compass dodecagonal

A grid based on dodecagons with square symmetry. In between dodecagons
there are 4 triangles around 1 square, which resembles a compass rose.
https://en.wikipedia.org/wiki/3-4-3-12_tiling
This commit is contained in:
Michael Quevillon
2019-05-28 00:19:33 -04:00
committed by Simon Tatham
parent 3cf0a3b7b0
commit 56ef86f92b
3 changed files with 101 additions and 1 deletions

98
grid.c
View File

@ -2747,7 +2747,7 @@ static grid *grid_new_greatgreatdodecagonal(int width, int height, const char *d
d = grid_get_dot(g, points, px + (2*a + 2*b), py - 2*a); grid_face_set_dot(g, d, 5);
}
/* hexagon on bottom right of dodecagon */
/* hexagon on bottom right of dodecagon */
if ((y < height - 1) && (x < width - 1 || !(y % 2))) {
grid_face_add_new(g, 6);
d = grid_get_dot(g, points, px + (a + 2*b), py + (2*a + b)); grid_face_set_dot(g, d, 0);
@ -2839,6 +2839,102 @@ static grid *grid_new_greatgreatdodecagonal(int width, int height, const char *d
return g;
}
static void grid_size_compassdodecagonal(int width, int height,
int *tilesize, int *xextent, int *yextent)
{
int a = DODEC_A;
int b = DODEC_B;
*tilesize = DODEC_TILESIZE;
*xextent = (4*a + 2*b) * width;
*yextent = (4*a + 2*b) * height;
}
static grid *grid_new_compassdodecagonal(int width, int height, const char *desc)
{
int x, y;
/* Vector for side of triangle - ratio is close to sqrt(3) */
int a = DODEC_A;
int b = DODEC_B;
/* Upper bounds - don't have to be exact */
int max_faces = 6 * width * height;
int max_dots = 18 * width * height;
tree234 *points;
grid *g = grid_empty();
g->tilesize = DODEC_TILESIZE;
g->faces = snewn(max_faces, grid_face);
g->dots = snewn(max_dots, grid_dot);
points = newtree234(grid_point_cmp_fn);
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
grid_dot *d;
/* centre of dodecagon */
int px = (4*a + 2*b) * x;
int py = (4*a + 2*b) * y;
/* dodecagon */
grid_face_add_new(g, 12);
d = grid_get_dot(g, points, px + ( a ), py - (2*a + b)); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + ( a + b), py - ( a + b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + (2*a + b), py - ( a )); grid_face_set_dot(g, d, 2);
d = grid_get_dot(g, points, px + (2*a + b), py + ( a )); grid_face_set_dot(g, d, 3);
d = grid_get_dot(g, points, px + ( a + b), py + ( a + b)); grid_face_set_dot(g, d, 4);
d = grid_get_dot(g, points, px + ( a ), py + (2*a + b)); grid_face_set_dot(g, d, 5);
d = grid_get_dot(g, points, px - ( a ), py + (2*a + b)); grid_face_set_dot(g, d, 6);
d = grid_get_dot(g, points, px - ( a + b), py + ( a + b)); grid_face_set_dot(g, d, 7);
d = grid_get_dot(g, points, px - (2*a + b), py + ( a )); grid_face_set_dot(g, d, 8);
d = grid_get_dot(g, points, px - (2*a + b), py - ( a )); grid_face_set_dot(g, d, 9);
d = grid_get_dot(g, points, px - ( a + b), py - ( a + b)); grid_face_set_dot(g, d, 10);
d = grid_get_dot(g, points, px - ( a ), py - (2*a + b)); grid_face_set_dot(g, d, 11);
if (x < width - 1 && y < height - 1) {
/* north triangle */
grid_face_add_new(g, 3);
d = grid_get_dot(g, points, px + (2*a + b), py + ( a )); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + (3*a + b), py + ( a + b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + ( a + b), py + ( a + b)); grid_face_set_dot(g, d, 2);
/* east triangle */
grid_face_add_new(g, 3);
d = grid_get_dot(g, points, px + (3*a + 2*b), py + (2*a + b)); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + (3*a + b), py + (3*a + b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + (3*a + b), py + ( a + b)); grid_face_set_dot(g, d, 2);
/* south triangle */
grid_face_add_new(g, 3);
d = grid_get_dot(g, points, px + (3*a + b), py + (3*a + b)); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + (2*a + b), py + (3*a + 2*b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + ( a + b), py + (3*a + b)); grid_face_set_dot(g, d, 2);
/* west triangle */
grid_face_add_new(g, 3);
d = grid_get_dot(g, points, px + (a + b), py + ( a + b)); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + (a + b), py + (3*a + b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + (a ), py + (2*a + b)); grid_face_set_dot(g, d, 2);
/* square in center */
grid_face_add_new(g, 4);
d = grid_get_dot(g, points, px + (3*a + b), py + ( a + b)); grid_face_set_dot(g, d, 0);
d = grid_get_dot(g, points, px + (3*a + b), py + (3*a + b)); grid_face_set_dot(g, d, 1);
d = grid_get_dot(g, points, px + ( a + b), py + (3*a + b)); grid_face_set_dot(g, d, 2);
d = grid_get_dot(g, points, px + ( a + b), py + ( a + b)); grid_face_set_dot(g, d, 3);
}
}
}
freetree234(points);
assert(g->num_faces <= max_faces);
assert(g->num_dots <= max_dots);
grid_make_consistent(g);
return g;
}
typedef struct setface_ctx
{
int xmin, xmax, ymin, ymax;

1
grid.h
View File

@ -107,6 +107,7 @@ typedef struct grid {
A(DODECAGONAL,dodecagonal) \
A(GREATDODECAGONAL,greatdodecagonal) \
A(GREATGREATDODECAGONAL,greatgreatdodecagonal) \
A(COMPASSDODECAGONAL,compassdodecagonal) \
A(PENROSE_P2,penrose_p2_kite) \
A(PENROSE_P3,penrose_p3_thick)

View File

@ -279,6 +279,7 @@ static void check_caches(const solver_state* sstate);
A("Penrose (rhombs)",PENROSE_P3,3,3) \
A("Great-Great-Dodecagonal",GREATGREATDODECAGONAL,2,2) \
A("Kagome",KAGOME,3,3) \
A("Compass-Dodecagonal",COMPASSDODECAGONAL,2,2) \
/* end of list */
#define GRID_NAME(title,type,amin,omin) title,
@ -552,6 +553,7 @@ static const game_params loopy_presets_more[] = {
{ 3, 3, DIFF_HARD, LOOPY_GRID_DODECAGONAL },
{ 3, 3, DIFF_HARD, LOOPY_GRID_GREATDODECAGONAL },
{ 3, 2, DIFF_HARD, LOOPY_GRID_GREATGREATDODECAGONAL },
{ 3, 3, DIFF_HARD, LOOPY_GRID_COMPASSDODECAGONAL },
#else
{ 10, 10, DIFF_HARD, LOOPY_GRID_HONEYCOMB },
{ 5, 4, DIFF_HARD, LOOPY_GRID_GREATHEXAGONAL },
@ -561,6 +563,7 @@ static const game_params loopy_presets_more[] = {
{ 5, 4, DIFF_HARD, LOOPY_GRID_DODECAGONAL },
{ 5, 4, DIFF_HARD, LOOPY_GRID_GREATDODECAGONAL },
{ 5, 3, DIFF_HARD, LOOPY_GRID_GREATGREATDODECAGONAL },
{ 5, 4, DIFF_HARD, LOOPY_GRID_COMPASSDODECAGONAL },
#endif
};