comparison src/xs_curve.c @ 520:81481e59e195

Almost working.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Feb 2007 02:33:03 +0000
parents 982cec405ef0
children 425da926d310
comparison
equal deleted inserted replaced
519:173e37b1c291 520:81481e59e195
218 gdk_draw_line(curve->pixmap, style->dark_gc[state], 218 gdk_draw_line(curve->pixmap, style->dark_gc[state],
219 i * (width / 4.0) + RADIUS, RADIUS, 219 i * (width / 4.0) + RADIUS, RADIUS,
220 i * (width / 4.0) + RADIUS, height + RADIUS); 220 i * (width / 4.0) + RADIUS, height + RADIUS);
221 } 221 }
222 222
223 223
224 #if 1
224 /* Draw the spline/curve itself */ 225 /* Draw the spline/curve itself */
225 p0 = curve->ctlpoints; 226 p0 = curve->ctlpoints;
226 p1 = p0; p1++; 227 p1 = p0;
227 p2 = p1; p2++; 228 p2 = p1; p2++;
228 p3 = p2; p3++; 229 p3 = p2; p3++;
229 230
230 /* Draw each curve segment */ 231 /* Draw each curve segment */
231 fprintf(stderr, "npoints = %d\n", curve->num_ctlpoints); 232 fprintf(stderr, "-- npoints = %d\n", curve->num_ctlpoints);
233 if (curve->num_ctlpoints > 5)
232 for (i = 0; i < curve->num_ctlpoints; i++, ++p0, ++p1, ++p2, ++p3) { 234 for (i = 0; i < curve->num_ctlpoints; i++, ++p0, ++p1, ++p2, ++p3) {
233 gfloat k1, k2, a, b, c, d, x; 235 gfloat k1, k2, a, b, c, d, x;
234 236 fprintf(stderr, "#%d: ", i);
235 if (p1->x == p2->x) 237 if (p1->x == p2->x)
236 continue; 238 continue;
237 239 #define PPASK(q, p) fprintf(stderr, q "=[%1.3f, %1.3f] ", p->x, p->y)
240
241 PPASK("p0", p1);
242 PPASK("p1", p1);
243 PPASK("p2", p2);
244 PPASK("p3", p3);
245
246 fprintf(stderr, "\ncase #");
238 if (p0->x == p1->x && p2->x == p3->x) { 247 if (p0->x == p1->x && p2->x == p3->x) {
248 fprintf(stderr, "1");
239 k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x); 249 k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x);
240 } else if (p0->x == p1->x) { 250 } else if (p0->x == p1->x) {
251 fprintf(stderr, "2");
241 k2 = (p3->y - p1->y) / (p3->x - p1->x); 252 k2 = (p3->y - p1->y) / (p3->x - p1->x);
242 k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2; 253 k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2;
243 } else if (p2->x == p3->x) { 254 } else if (p2->x == p3->x) {
255 fprintf(stderr, "3");
244 k1 = (p2->y - p0->y) / (p2->x - p0->x); 256 k1 = (p2->y - p0->y) / (p2->x - p0->x);
245 k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2; 257 k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2;
246 } else { 258 } else {
259 fprintf(stderr, "4");
247 k1 = (p2->y - p0->y) / (p2->x - p0->x); 260 k1 = (p2->y - p0->y) / (p2->x - p0->x);
248 k2 = (p3->y - p1->y) / (p3->x - p1->x); 261 k2 = (p3->y - p1->y) / (p3->x - p1->x);
249 } 262 }
250 263
251 xs_cubic_coeff(p1->x, p1->y, p2->x, p2->y, k1, k2, &a, &b, &c, &d); 264 xs_cubic_coeff(p1->x, p1->y, p2->x, p2->y, k1, k2, &a, &b, &c, &d);
252 fprintf(stderr, "--seg[%1.3f, %1.3f]=>[%1.3f, %1.3f]--\n", p1->x, p1->y, p2->x, p2->y); 265 fprintf(stderr, " seg[%1.3f, %1.3f] => [%1.3f, %1.3f] k1=%1.3f, k2=%1.3f\n\n",
266 p1->x, p1->y,
267 p2->x, p2->y,
268 k1, k2);
269 #if 1
253 for (x = p1->x; x <= p2->x; x += res) { 270 for (x = p1->x; x <= p2->x; x += res) {
254 gfloat y = ((a * x + b) * x + c) * x + d; 271 gfloat y = ((a * x + b) * x + c) * x + d;
255 gint qx, qy; 272 gint qx, qy;
256 qx = RADIUS + xs_project(x, curve->min_x, curve->max_x, width); 273 qx = RADIUS + xs_project(x, curve->min_x, curve->max_x, width);
257 qy = RADIUS + xs_project(y, curve->min_y, curve->max_y, height); 274 qy = RADIUS + xs_project(y, curve->min_y, curve->max_y, height);
258 fprintf(stderr, "[%1.3f, %1.3f] -> %d, %d\n", x, y, qx, qy); 275
259 gdk_draw_point(curve->pixmap, style->fg_gc[state], 276 gdk_draw_point(curve->pixmap, style->fg_gc[state],
260 RADIUS + xs_project(x, curve->min_x, curve->max_x, width), 277 RADIUS + xs_project(x, curve->min_x, curve->max_x, width),
261 RADIUS + xs_project(y, curve->min_y, curve->max_y, height)); 278 RADIUS + xs_project(y, curve->min_y, curve->max_y, height));
262 279
263 } 280 }
264 fprintf(stderr, "-------\n"); 281 #endif
265 } 282 }
266 283 fprintf(stderr, "-------\n");
284 #endif
285
267 /* Draw control points */ 286 /* Draw control points */
268 for (i = 0; i < curve->num_ctlpoints; ++i) { 287 for (i = 0; i < curve->num_ctlpoints; ++i) {
269 gint x, y; 288 gint x, y;
270 289
271 if (GET_X(i) < curve->min_x || GET_Y(i) < curve->min_y || 290 if (GET_X(i) < curve->min_x || GET_Y(i) < curve->min_y ||