#include #include #include #include "gegl.h" #include "property-types/gegl-path.h" #define SUCCESS 0 #define FAILURE -1 #define EPSILON 0.00001 #define NSMP 3 static gboolean equals(double a, double b) { return fabs(a-b) < EPSILON; } static void distribute(double length, int num_samples, gdouble *result) { int i=0; gdouble spacing = 0; if (num_samples>1) spacing = length/(num_samples-1); for (i=0; i1) result[num_samples-1]= length; } static int test_path_get_length (GeglPath *path, gdouble exp_length) { gdouble length; length = gegl_path_get_length(path); if (! equals(length, exp_length)) { g_printerr("test_path_get_length()\n"); g_printerr("The length of path is incorrect.\n"); g_printerr("length is %f, should be %f\n", length, exp_length); return FALSE; } return TRUE; } static int test_path_calc_values (GeglPath *path, int num_samples, gdouble *exp_x, gdouble *exp_y) { int i=0; gdouble x[num_samples], y[num_samples]; //gdouble length; /* gegl_path_calc_values: * Compute @num_samples for a path into the provided arrays @xs and @ys * the returned values include the start and end positions of the path. */ //length = gegl_path_get_length(path); gegl_path_calc_values(path,num_samples,x,y); for (i=0; i-1;j--) if(! test_path_calc(path, exp_x[j], exp_x[j], exp_y[j]) ) { g_printerr("The gegl_path_calc() reverse test #%d.%d failed.\n",i,j+1); result += FAILURE; } if(! test_path_calc_values(path, NSMP, exp_x, exp_y) ) { g_printerr("The gegl_path_calc_values() test #%d failed.\n",i); result += FAILURE; } i++; path = gegl_path_new (); gegl_path_append (path, 'M', 0.0, 0.0); gegl_path_append (path, 'L', 0.5, 0.0); gegl_path_append (path, 'M', 0.5, 0.0); gegl_path_append (path, 'L', 1.0, 0.0); if(! test_path_get_length(path, 1.0) ) { g_printerr("The gegl_path_get_length() test #%d failed.\n",i); result += FAILURE; } /* path_calc forwards */ for ( j=0;j-1;j--) if(! test_path_calc(path, exp_x[j], exp_x[j], exp_y[j]) ) { g_printerr("The gegl_path_calc() reverse test #%d.%d failed.\n",i,j+1); result += FAILURE; } if(! test_path_calc_values(path, NSMP, exp_x, exp_y) ) { g_printerr("The gegl_path_calc_values() test #%d failed.\n",i); result += FAILURE; } /* path1 : |--+--+--|--+--+--| * path2 : |--+--+--| * |--+--+--| * 1sampl : ^ ? * 2sampl : ^ ^ * 3sampl : ^ ^ ^ * 4sampl : ^ ^ ^ ^ */ gegl_exit (); return result; }