]> granicus.if.org Git - poly2tri-c/commitdiff
1. Make the compiler strict with ANSI C
authorBarak Itkin <lightningismyname@gmail.com>
Sat, 12 May 2012 20:10:54 +0000 (23:10 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Sat, 12 May 2012 20:10:54 +0000 (23:10 +0300)
2. Fix remaining code to compile with ANSI C
3. Fix a wrong call in the main test program that created a (0,0) point

bin/main.c
configure.ac
render/mesh-render.c
render/svg-plot.c
render/svg-plot.h

index 68c02f32a9f5f93db1b6ad37ac2ac5315ff57894..33266fbcc483b7d1f3f2ea7d54602d4b4d20268e 100755 (executable)
@@ -115,7 +115,7 @@ read_points_file (const gchar       *path,
 
           if (points != NULL)
             {
-              g_ptr_array_add (*points, p2t_point_new (ptc[0], ptc[1]));
+              g_ptr_array_add (*points, p2t_point_new_dd (ptc[0], ptc[1]));
               countPts++;
             }
         }
@@ -153,16 +153,6 @@ read_points_file (const gchar       *path,
     g_print ("Read %d points and %d colors\n", countPts, countCls);
 }
 
-/* In order to find the maximal length of a filename path, most
- * platforms have either the macro MAX_PATH, or PATH_MAX. This is a
- * guess which tries them both */
-#ifdef MAX_PATH
-#define P2TC_MAX_PATH MAX_PATH
-#else
-#define P2TC_MAX_PATH PATH_MAX
-#endif
-
 /* Calculate a "deterministic random" color for each point
  * based on its memory address. Since we know that least-significant bytes
  * of the point address will change more than the mor-important ones, we
@@ -191,14 +181,13 @@ gint main (int argc, char *argv[])
   P2trCDT *rcdt;
   P2trDelaunayTerminator *dt;
 
-  gchar buf[P2TC_MAX_PATH+1];
+  gchar *buf;
   gfloat *im;
+  P2trImageConfig imc;
 
   context = g_option_context_new ("- Create a fine mesh from a given PSLG");
   g_option_context_add_main_entries (context, entries, NULL);
 
-//  g_option_context_add_group (context, gtk_get_option_group (TRUE));
-
   if (!g_option_context_parse (context, &argc, &argv, &error))
     {
       g_print ("option parsing failed: %s\n", error->message);
@@ -242,6 +231,7 @@ gint main (int argc, char *argv[])
 
   fclose (out);
 
+  buf = g_newa(char, strlen(output_file) + 5);
   sprintf (buf, "%s.ppm", output_file);
 
   if ((out = fopen (buf, "w")) == NULL)
@@ -250,8 +240,9 @@ gint main (int argc, char *argv[])
       exit (1);
     }
 
-  P2trImageConfig imc;
-  
+  g_free (buf);
+  buf = NULL;
+
   imc.cpp = 4;
   imc.min_x = imc.min_y = 0;
   imc.step_x = imc.step_y = 0.2;
@@ -266,12 +257,14 @@ gint main (int argc, char *argv[])
 
   g_free (im);
 
-  // p2tr_triangulation_free (T);
+#if FALSE
+  p2tr_triangulation_free (T);
 
-//  for (i = 0; i < pts->len; i++)
-//    {
-//      p2tr_point_unref ((P2trPoint*) g_ptr_array_index (pts, i));
-//    }
+  for (i = 0; i < pts->len; i++)
+    {
+      p2tr_point_unref ((P2trPoint*) g_ptr_array_index (pts, i));
+    }
+#endif
 
   g_ptr_array_free (pts, TRUE);
   g_array_free (colors, TRUE);
index 5259d046cc82b2945c3f84de38f28cc17f8004b9..9dc739c15105228bf5bfd47efef9ee8af36f8fae 100644 (file)
@@ -27,6 +27,9 @@ LT_INIT
 # Find a C compiler
 AC_PROG_CC
 
+# Pedantic errors please
+CFLAGS="$CFLAGS -Wall -Werror -ansi -pedantic"
+
 # Find the standard math functions
 # Taken from http://www.flameeyes.eu/autotools-mythbuster/autoconf/finding.html
 AC_SEARCH_LIBS([log10], [m], [], [
index 50ba8b72d8a52afda69e19f7567b3785901d7cb2..3b7eb048655a0564660df1d7a14cc424e8c42988 100755 (executable)
@@ -128,7 +128,6 @@ p2tr_mesh_render_scanline2 (P2truvt              *uvt_cache,
 
   P2trPoint *A = NULL, *B = NULL, *C = NULL;
 
-  gfloat *col =  g_new (gfloat, config->cpp);
   gfloat *colA = g_new (gfloat, config->cpp);
   gfloat *colB = g_new (gfloat, config->cpp);
   gfloat *colC = g_new (gfloat, config->cpp);
@@ -186,11 +185,13 @@ p2tr_write_ppm (FILE            *f,
                 P2trImageConfig *config)
 {
   gint x, y;
+  gfloat *pixel;
+
   fprintf (f, "P3\n");
   fprintf (f, "%d %d\n", config->x_samples, config->y_samples);
   fprintf (f, "255\n");
 
-  gfloat *pixel = dest;
+  pixel = dest;
 
   for (y = 0; y < config->y_samples; y++)
     {
index 6f12fcd909231f72fea878bc523c8a1adc23aca8..27ec77c98b9dd19510f8be1d8b233a5e166cf4c4 100755 (executable)
@@ -33,13 +33,13 @@ p2tr_plot_svg_plot_line (gdouble x1, gdouble y1, gdouble x2, gdouble y2, const g
 void
 p2tr_plot_svg_plot_arrow (gdouble x1, gdouble y1, gdouble x2, gdouble y2, const gchar* color, FILE *outfile)
 {
-  p2tr_plot_svg_plot_line (x1, y1, x2, y2, color, outfile);
-
   gdouble dy = y2 - y1;
   gdouble dx = x2 - x1;
   gdouble angle = atan2 (dy, dx);
-
   gdouble temp = angle - ARROW_SIDE_ANGLE;
+
+  p2tr_plot_svg_plot_line (x1, y1, x2, y2, color, outfile);
+
   p2tr_plot_svg_plot_line (x2, y2, x2 - ARROW_HEAD_SIZE * cos (temp), y2 - ARROW_HEAD_SIZE * sin (temp), color, outfile);
 
   temp = angle + ARROW_SIDE_ANGLE;
@@ -111,8 +111,10 @@ p2tr_plot_svg_plot_edge (P2trEdge *self, const gchar* color, FILE* outfile)
 
   p2tr_plot_svg_plot_line (x1, y1, x2, y2, color, outfile);
 
-//  if (p2tr_edge_is_encroached (self))
-//    p2tr_plot_svg_plot_circle ((x1 + x2) / 2, (y1 + y2) / 2, R, "red", outfile);
+#if FALSE
+  if (p2tr_edge_is_encroached (self))
+    p2tr_plot_svg_plot_circle ((x1 + x2) / 2, (y1 + y2) / 2, R, "red", outfile);
+#endif
 }
 
 void
index 2acc12425d44aaf9656c6d9216ab7b8e600b610d..0431c902641f1e1af3ddc9a6485f7e4f0ec215e2 100755 (executable)
@@ -39,7 +39,7 @@
 #include <refine/refine.h>
 
 #define PLOT_LINE_WIDTH 0.40
-#define ARROW_SIDE_ANGLE (M_PI / 180 * 30)
+#define ARROW_SIDE_ANGLE (G_PI / 180 * 30)
 #define ARROW_HEAD_SIZE 2.0
 
 #define X_SCALE 3.