From: Barak Itkin Date: Sat, 12 May 2012 20:10:54 +0000 (+0300) Subject: 1. Make the compiler strict with ANSI C X-Git-Tag: p2tc-0.1.0~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be1cacd530c99c93cba9a92a3923f4b4e05f693f;p=poly2tri-c 1. Make the compiler strict with ANSI C 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 --- diff --git a/bin/main.c b/bin/main.c index 68c02f3..33266fb 100755 --- a/bin/main.c +++ b/bin/main.c @@ -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); diff --git a/configure.ac b/configure.ac index 5259d04..9dc739c 100644 --- a/configure.ac +++ b/configure.ac @@ -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], [], [ diff --git a/render/mesh-render.c b/render/mesh-render.c index 50ba8b7..3b7eb04 100755 --- a/render/mesh-render.c +++ b/render/mesh-render.c @@ -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++) { diff --git a/render/svg-plot.c b/render/svg-plot.c index 6f12fcd..27ec77c 100755 --- a/render/svg-plot.c +++ b/render/svg-plot.c @@ -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 diff --git a/render/svg-plot.h b/render/svg-plot.h index 2acc124..0431c90 100755 --- a/render/svg-plot.h +++ b/render/svg-plot.h @@ -39,7 +39,7 @@ #include #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.