From 5e3de7d95bee214a95a01f8d16778987da75b04c Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 23 Apr 2011 11:44:43 +0000 Subject: Move most of face_text_pos() into grid.c, leaving in loopy.c only the part that converts from abstract grid coordinates into screen coordinates. This should speed up window-resizing by eliminating pointless reiteration of the complicated part of the algorithm: now when a game_drawstate is renewed, only the conversion into screen coordinates has to be redone. [originally from svn r9157] --- grid.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'grid.h') diff --git a/grid.h b/grid.h index 9adf3a9..65ced86 100644 --- a/grid.h +++ b/grid.h @@ -34,6 +34,22 @@ struct grid_face { int order; /* Number of edges, also the number of dots */ grid_edge **edges; /* edges around this face */ grid_dot **dots; /* corners of this face */ + /* + * For each face, we optionally compute and store its 'incentre'. + * The incentre of a triangle is the centre of a circle tangent to + * all three edges; I generalise the concept to arbitrary polygons + * by defining it to be the centre of the largest circle you can fit + * anywhere in the polygon. It's a useful thing to know because if + * you want to draw any symbol or text in the face (e.g. clue + * numbers in Loopy), that's the place it will most easily fit. + * + * When a grid is first generated, no face has this information + * computed, because it's fiddly to do. You can call + * grid_find_incentre() on a face, and it will fill in ix,iy below + * and set has_incentre to indicate that it's done so. + */ + int has_incentre; + int ix, iy; /* incentre (centre of largest inscribed circle) */ }; struct grid_edge { grid_dot *dot1, *dot2; @@ -89,4 +105,6 @@ void grid_free(grid *g); grid_edge *grid_nearest_edge(grid *g, int x, int y); +void grid_find_incentre(grid_face *f); + #endif /* PUZZLES_GRID_H */ -- cgit v1.1