chiark / gitweb /
Patch from James H to make new-Loopy port more easily.
authorSimon Tatham <anakin@pobox.com>
Wed, 10 Sep 2008 21:44:23 +0000 (21:44 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 10 Sep 2008 21:44:23 +0000 (21:44 +0000)
[originally from svn r8174]

grid.c
loopy.c

diff --git a/grid.c b/grid.c
index 0218b8b6f34a1416956de0d95d130b6bab381f4e..75887eb7fa7235d059863f96ebf42674c9247f2f 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -50,7 +50,7 @@ void grid_free(grid *g)
 
 /* Used by the other grid generators.  Create a brand new grid with nothing
  * initialised (all lists are NULL) */
-static grid *grid_new()
+static grid *grid_new(void)
 {
     grid *g = snew(grid);
     g->faces = NULL;
@@ -76,11 +76,11 @@ static grid *grid_new()
  *
  * Combining gives: distance = determinant / line-length(a,b)
  */
-static double point_line_distance(int px, int py,
-                                  int ax, int ay,
-                                  int bx, int by)
+static double point_line_distance(long px, long py,
+                                  long ax, long ay,
+                                  long bx, long by)
 {
-    int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
+    long det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
     double len;
     det = max(det, -det);
     len = sqrt(SQ(ax - bx) + SQ(ay - by));
@@ -125,7 +125,7 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
 
     for (;;) {
         /* Target to beat */
-        int dist = SQ(cur->x - x) + SQ(cur->y - y);
+        long dist = SQ((long)cur->x - (long)x) + SQ((long)cur->y - (long)y);
         /* Look for nearer dot - if found, store in 'new'. */
         grid_dot *new = cur;
         int i;
@@ -137,10 +137,10 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
             int j;
             if (!f) continue;
             for (j = 0; j < f->order; j++) {
-               int new_dist;
+               long new_dist;
                 grid_dot *d = f->dots[j];
                 if (d == cur) continue;
-                new_dist = SQ(d->x - x) + SQ(d->y - y);
+                new_dist = SQ((long)d->x - (long)x) + SQ((long)d->y - (long)y);
                 if (new_dist < dist) {
                     new = d;
                     break; /* found closer dot */
@@ -157,23 +157,22 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
             cur = new;
         }
     }
-    
     /* 'cur' is nearest dot, so find which of the dot's edges is closest. */
     best_edge = NULL;
 
     for (i = 0; i < cur->order; i++) {
         grid_edge *e = cur->edges[i];
-        int e2; /* squared length of edge */
-        int a2, b2; /* squared lengths of other sides */
+        long e2; /* squared length of edge */
+        long a2, b2; /* squared lengths of other sides */
         double dist;
 
         /* See if edge e is eligible - the triangle must have acute angles
          * at the edge's dots.
          * Pythagoras formula h^2 = a^2 + b^2 detects right-angles,
          * so detect acute angles by testing for h^2 < a^2 + b^2 */
-        e2 = SQ(e->dot1->x - e->dot2->x) + SQ(e->dot1->y - e->dot2->y);
-        a2 = SQ(e->dot1->x - x) + SQ(e->dot1->y - y);
-        b2 = SQ(e->dot2->x - x) + SQ(e->dot2->y - y);
+        e2 = SQ((long)e->dot1->x - (long)e->dot2->x) + SQ((long)e->dot1->y - (long)e->dot2->y);
+        a2 = SQ((long)e->dot1->x - (long)x) + SQ((long)e->dot1->y - (long)y);
+        b2 = SQ((long)e->dot2->x - (long)x) + SQ((long)e->dot2->y - (long)y);
         if (a2 >= e2 + b2) continue;
         if (b2 >= e2 + a2) continue;
          
@@ -187,9 +186,9 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
          * Alternatively, we could check that the angle at the point is obtuse.
          * That would amount to testing a circular region with the edge as
          * diameter. */
-        dist = point_line_distance(x, y,
-                                   e->dot1->x, e->dot1->y,
-                                   e->dot2->x, e->dot2->y);
+        dist = point_line_distance((long)x, (long)y,
+                                   (long)e->dot1->x, (long)e->dot1->y,
+                                   (long)e->dot2->x, (long)e->dot2->y);
         /* Is dist more than half edge length ? */
         if (4 * SQ(dist) > e2)
             continue;
diff --git a/loopy.c b/loopy.c
index 5f3c601e7426c884e677bf7e171ae61b1c8db3c2..b54922a6cd16df315b2a402b09484a0e96d7b534 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -236,7 +236,7 @@ static void check_caches(const solver_state* sstate);
 static char const *const gridnames[] = { GRIDLIST(GRID_NAME) };
 #define GRID_CONFIGS GRIDLIST(GRID_CONFIG)
 static grid * (*(grid_fns[]))(int w, int h) = { GRIDLIST(GRID_FN) };
-static const int NUM_GRID_TYPES = sizeof(grid_fns) / sizeof(grid_fns[0]);
+#define NUM_GRID_TYPES (sizeof(grid_fns) / sizeof(grid_fns[0]))
 
 /* Generates a (dynamically allocated) new grid, according to the
  * type and size requested in params.  Does nothing if the grid is already
@@ -464,6 +464,18 @@ static game_params *dup_params(game_params *params)
 }
 
 static const game_params presets[] = {
+#ifdef SMALL_SCREEN
+    {  7,  7, DIFF_EASY, 0, NULL },
+    {  7,  7, DIFF_NORMAL, 0, NULL },
+    {  7,  7, DIFF_HARD, 0, NULL },
+    {  7,  7, DIFF_HARD, 1, NULL },
+    {  7,  7, DIFF_HARD, 2, NULL },
+    {  5,  5, DIFF_HARD, 3, NULL },
+    {  7,  7, DIFF_HARD, 4, NULL },
+    {  5,  4, DIFF_HARD, 5, NULL },
+    {  5,  5, DIFF_HARD, 6, NULL },
+    {  5,  5, DIFF_HARD, 7, NULL },
+#else
     {  7,  7, DIFF_EASY, 0, NULL },
     {  10,  10, DIFF_EASY, 0, NULL },
     {  7,  7, DIFF_NORMAL, 0, NULL },
@@ -477,6 +489,7 @@ static const game_params presets[] = {
     {  5,  4, DIFF_HARD, 5, NULL },
     {  7,  7, DIFF_HARD, 6, NULL },
     {  5,  5, DIFF_HARD, 7, NULL },
+#endif
 };
 
 static int game_fetch_preset(int i, char **name, game_params **params)
@@ -3291,14 +3304,14 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
 
             dx = (dx * ds->tilesize) / thickness;
             dy = (dy * ds->tilesize) / thickness;
-           points[0] = x1 + dy;
-           points[1] = y1 - dx;
-           points[2] = x1 - dy;
-           points[3] = y1 + dx;
-           points[4] = x2 - dy;
-           points[5] = y2 + dx;
-           points[6] = x2 + dy;
-           points[7] = y2 - dx;
+           points[0] = x1 + (int)dy;
+           points[1] = y1 - (int)dx;
+           points[2] = x1 - (int)dy;
+           points[3] = y1 + (int)dx;
+           points[4] = x2 - (int)dy;
+           points[5] = y2 + (int)dx;
+           points[6] = x2 + (int)dy;
+           points[7] = y2 - (int)dx;
             draw_polygon(dr, points, 4, ink, ink);
         }
         else