X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fspline.c;h=1a73ea61b3edb0df1b526758a9e22123d9b1dc7f;hb=4ade52359b6eba3621566dac79793a33aa4c915f;hp=d242d63f777b32d9be4382628dc0191ddab2a5de;hpb=65740e2a8dea3d6309ae6e8914a0fb79e993ada8;p=xscreensaver diff --git a/utils/spline.c b/utils/spline.c old mode 100755 new mode 100644 index d242d63f..1a73ea61 --- a/utils/spline.c +++ b/utils/spline.c @@ -24,18 +24,11 @@ from C++ to C by Matthieu Devin some time in 1992. */ -#include +#include "utils.h" #include "spline.h" -#if __STDC__ -#include -#endif -#include -/* Lifted from InterViews */ #define SMOOTHNESS 1.0 -#if __STDC__ -static void no_more_memory (void); static void grow_spline_points (spline* s); static void mid_point (double x0, double y0, double x1, double y1, double *mx, double *my); @@ -51,22 +44,11 @@ static void calc_section (spline* s, double cminus1x, double cminus1y, double cx, double cy, double cplus1x, double cplus1y, double cplus2x, double cplus2y); -#endif - -static void -no_more_memory () -{ - fprintf (stderr, "No more memory\n"); - exit (1); -} - spline* -make_spline (size) - u_int size; +make_spline (unsigned int size) { spline* s = (spline*)calloc (1, sizeof (spline)); - if (!s) - no_more_memory (); + if (!s) abort(); s->n_controls = size; s->control_x = (double*)calloc (s->n_controls, sizeof (double)); s->control_y = (double*)calloc (s->n_controls, sizeof (double)); @@ -76,42 +58,42 @@ make_spline (size) s->points = (XPoint*)calloc (s->allocated_points, sizeof (XPoint)); if (!s->control_x || !s->control_y || !s->points) - no_more_memory (); + abort(); return s; } static void -grow_spline_points (s) - spline* s; +grow_spline_points (spline *s) { - s->allocated_points *= 2; + s->allocated_points = 10 + (s->allocated_points * 1.3); s->points = (XPoint*)realloc (s->points, s->allocated_points * sizeof (XPoint)); - - if (!s->points) - no_more_memory (); + if (!s->points) abort(); } static void -mid_point (x0, y0, x1, y1, mx, my) - double x0, y0, x1, y1, *mx, *my; +mid_point (double x0, double y0, + double x1, double y1, + double *mx, double *my) { *mx = (x0 + x1) / 2.0; *my = (y0 + y1) / 2.0; } static void -third_point (x0, y0, x1, y1, tx, ty) - double x0, y0, x1, y1, *tx, *ty; +third_point (double x0, double y0, + double x1, double y1, + double *tx, double *ty) { *tx = (2 * x0 + x1) / 3.0; *ty = (2 * y0 + y1) / 3.0; } static int -can_approx_with_line (x0, y0, x2, y2, x3, y3) - double x0, y0, x2, y2, x3, y3; +can_approx_with_line (double x0, double y0, + double x2, double y2, + double x3, double y3) { double triangle_area, side_squared, dx, dy; @@ -125,9 +107,9 @@ can_approx_with_line (x0, y0, x2, y2, x3, y3) } static void -add_line (s, x0, y0, x1, y1) - spline* s; - double x0, y0, x1, y1; +add_line (spline *s, + double x0, double y0, + double x1, double y1) { if (s->n_points >= s->allocated_points) grow_spline_points (s); @@ -144,9 +126,11 @@ add_line (s, x0, y0, x1, y1) } static void -add_bezier_arc (s, x0, y0, x1, y1, x2, y2, x3, y3) - spline* s; - double x0, y0, x1, y1, x2, y2, x3, y3; +add_bezier_arc (spline *s, + double x0, double y0, + double x1, double y1, + double x2, double y2, + double x3, double y3) { double midx01, midx12, midx23, midlsegx, midrsegx, cx, midy01, midy12, midy23, midlsegy, midrsegy, cy; @@ -172,10 +156,11 @@ add_bezier_arc (s, x0, y0, x1, y1, x2, y2, x3, y3) } static void -calc_section (s, cminus1x, cminus1y, cx, cy, cplus1x, cplus1y, - cplus2x, cplus2y) - spline* s; - double cminus1x, cminus1y, cx, cy, cplus1x, cplus1y, cplus2x, cplus2y; +calc_section (spline *s, + double cminus1x, double cminus1y, + double cx, double cy, + double cplus1x, double cplus1y, + double cplus2x, double cplus2y) { double p0x, p1x, p2x, p3x, tempx, p0y, p1y, p2y, p3y, tempy; @@ -190,8 +175,7 @@ calc_section (s, cminus1x, cminus1y, cx, cy, cplus1x, cplus1y, } void -compute_spline (s) - spline* s; +compute_spline (spline *s) { int i; s->n_points = 0; @@ -223,8 +207,7 @@ compute_spline (s) } void -compute_closed_spline (s) - spline *s; +compute_closed_spline (spline *s) { int i; s->n_points = 0; @@ -256,8 +239,7 @@ compute_closed_spline (s) } void -just_fill_spline (s) - spline *s; +just_fill_spline (spline *s) { int i; @@ -275,8 +257,7 @@ just_fill_spline (s) } void -append_spline_points (s1, s2) - spline *s1, *s2; +append_spline_points (spline *s1, spline *s2) { int i; while (s1->allocated_points < s1->n_points + s2->n_points) @@ -290,9 +271,7 @@ append_spline_points (s1, s2) } void -spline_bounding_box (s, rectangle_out) - spline* s; - XRectangle* rectangle_out; +spline_bounding_box (spline *s, XRectangle *rectangle_out) { int min_x; int max_x; @@ -329,3 +308,12 @@ spline_bounding_box (s, rectangle_out) rectangle_out->width = max_x - min_x; rectangle_out->height = max_y - min_y; } + +void +free_spline(spline * s) +{ + free ((void *) s->control_x); + free ((void *) s->control_y); + free ((void *) s->points); + free ((void *) s); +}