X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fspline.c;h=ed3d31cbca13308270d339d4c46cd11e2884d284;hb=278c59e14c53fd412b734e699bd4f314f766f804;hp=ed5a224a8ac41bf6497d4d27adf082ee1c8e1e0f;hpb=0a1527cc01e9894017614b7c36b838b2b6914ba9;p=xscreensaver diff --git a/utils/spline.c b/utils/spline.c index ed5a224a..ed3d31cb 100644 --- a/utils/spline.c +++ b/utils/spline.c @@ -1,23 +1,59 @@ -#include +/* + * Copyright (c) 1987, 1988, 1989 Stanford University + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Stanford not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Stanford makes no representations about + * the suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* This code came with the InterViews distribution, and was translated + from C++ to C by Matthieu Devin some time in 1992. + */ + +#include "utils.h" #include "spline.h" -#if __STDC__ -#include -#endif -#include -/* Lifted from InterViews */ #define SMOOTHNESS 1.0 +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); +static int can_approx_with_line (double x0, double y0, double x2, + double y2, double x3, double y3); +static void add_line (spline* s, double x0, double y0, double x1, double y1); +static void add_bezier_arc (spline* s, + double x0, double y0, double x1, double y1, + double x2, double y2, double x3, double y3); +static void third_point (double x0, double y0, double x1, double y1, + double *tx, double *ty); +static void calc_section (spline* s, double cminus1x, double cminus1y, + double cx, double cy, double cplus1x, double cplus1y, + double cplus2x, double cplus2y); + static void -no_more_memory () +no_more_memory (void) { 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) @@ -37,8 +73,7 @@ make_spline (size) } static void -grow_spline_points (s) - spline* s; +grow_spline_points (spline *s) { s->allocated_points *= 2; s->points = @@ -49,24 +84,27 @@ grow_spline_points (s) } 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; @@ -80,9 +118,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); @@ -99,9 +137,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; @@ -127,10 +167,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; @@ -145,8 +186,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; @@ -178,8 +218,7 @@ compute_spline (s) } void -compute_closed_spline (s) - spline *s; +compute_closed_spline (spline *s) { int i; s->n_points = 0; @@ -211,8 +250,7 @@ compute_closed_spline (s) } void -just_fill_spline (s) - spline *s; +just_fill_spline (spline *s) { int i; @@ -230,8 +268,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) @@ -245,9 +282,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; @@ -284,3 +319,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); +}