1
/* curve.c: operations on the lists of pixels and lists of curves.
3
* Copyright (C) 1992 Free Software Foundation, Inc.
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2, or (at your option)
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
/* Return an entirely empty curve. */
33
curve_type curve = g_new (struct curve, 1);
35
curve->point_list = NULL;
36
CURVE_LENGTH (curve) = 0;
37
CURVE_CYCLIC (curve) = false;
38
CURVE_START_TANGENT (curve) = CURVE_END_TANGENT (curve) = NULL;
39
PREVIOUS_CURVE (curve) = NEXT_CURVE (curve) = NULL;
45
/* Start the returned curve off with COORD as the first point. */
48
init_curve (coordinate_type coord)
50
curve_type curve = new_curve ();
52
curve->point_list = g_new (point_type, 1);
53
CURVE_LENGTH (curve) = 1;
55
CURVE_POINT (curve, 0) = int_to_real_coord (coord);
61
/* Don't copy the points or tangents, but copy everything else. */
64
copy_most_of_curve (curve_type old_curve)
66
curve_type curve = new_curve ();
68
CURVE_CYCLIC (curve) = CURVE_CYCLIC (old_curve);
69
PREVIOUS_CURVE (curve) = PREVIOUS_CURVE (old_curve);
70
NEXT_CURVE (curve) = NEXT_CURVE (old_curve);
76
/* The length of CURVE will be zero if we ended up not being able to fit
77
it (which in turn implies a problem elsewhere in the program, but at
78
any rate, we shouldn't try here to free the nonexistent curve). */
81
free_curve (curve_type curve)
83
if (CURVE_LENGTH (curve) > 0)
84
safe_free ((address *) &(curve->point_list));
89
append_pixel (curve_type curve, coordinate_type coord)
91
append_point (curve, int_to_real_coord (coord));
96
append_point (curve_type curve, real_coordinate_type coord)
98
CURVE_LENGTH (curve)++;
99
curve->point_list = g_realloc (curve->point_list,CURVE_LENGTH (curve) * sizeof(point_type));
100
LAST_CURVE_POINT (curve) = coord;
101
/* The t value does not need to be set. */
104
/* Return an initialized but empty curve list. */
107
new_curve_list (void)
109
curve_list_type curve_list;
111
curve_list.length = 0;
112
curve_list.data = NULL;
113
curve_list.clockwise = FALSE;
119
/* Free a curve list and all the curves it contains. */
122
free_curve_list (curve_list_type *curve_list)
126
for (this_curve = 0; this_curve < curve_list->length; this_curve++)
127
free_curve (curve_list->data[this_curve]);
129
/* If the character was empty, it won't have any curves. */
130
if (curve_list->data != NULL)
131
safe_free ((address *) &(curve_list->data));
135
/* Add an element to a curve list. */
138
append_curve (curve_list_type *curve_list, curve_type curve)
140
curve_list->length++;
141
curve_list->data = g_realloc (curve_list->data,curve_list->length*sizeof(curve_type));
142
curve_list->data[curve_list->length - 1] = curve;
146
/* Return an initialized but empty curve list array. */
148
curve_list_array_type
149
new_curve_list_array (void)
151
curve_list_array_type curve_list_array;
153
CURVE_LIST_ARRAY_LENGTH (curve_list_array) = 0;
154
curve_list_array.data = NULL;
156
return curve_list_array;
160
/* Free a curve list array and all the curve lists it contains. */
163
free_curve_list_array (curve_list_array_type *curve_list_array)
167
for (this_list = 0; this_list < CURVE_LIST_ARRAY_LENGTH (*curve_list_array);
169
free_curve_list (&CURVE_LIST_ARRAY_ELT (*curve_list_array, this_list));
171
/* If the character was empty, it won't have any curves. */
172
if (curve_list_array->data != NULL)
173
safe_free ((address *) &(curve_list_array->data));
177
/* Add an element to a curve list array. */
180
append_curve_list (curve_list_array_type *l, curve_list_type curve_list)
182
CURVE_LIST_ARRAY_LENGTH (*l)++;
183
l->data = g_realloc (l->data,( CURVE_LIST_ARRAY_LENGTH (*l))*sizeof(curve_list_type));
184
LAST_CURVE_LIST_ARRAY_ELT (*l) = curve_list;