changeset 514:982cec405ef0

Cleaned up the drawing function a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 29 Jan 2007 03:26:05 +0000
parents e5b302358312
children 449d4eaa5081
files src/xs_curve.c
diffstat 1 files changed, 22 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_curve.c	Mon Jan 29 03:19:04 2007 +0000
+++ b/src/xs_curve.c	Mon Jan 29 03:26:05 2007 +0000
@@ -10,10 +10,6 @@
 #include <gtk/gtksignal.h>
 
 
-#define GET_X(i)	curve->ctlpoints[i].x
-#define GET_Y(i)	curve->ctlpoints[i].y
-
-
 #define RADIUS		3	/* radius of the control points */
 #define RADIUS2		(RADIUS * 2)
 
@@ -27,6 +23,10 @@
 			GDK_BUTTON_RELEASE_MASK |	\
 			GDK_BUTTON1_MOTION_MASK)
 
+#define GET_X(i)	curve->ctlpoints[i].x
+#define GET_Y(i)	curve->ctlpoints[i].y
+
+
 enum {
 	ARG_0,
 	ARG_CURVE_TYPE,
@@ -182,8 +182,6 @@
 	*d = y1 - ((x1 * (*a) + (*b)) * x1 + (*c)) * x1;
 }
 
-#define x(val) val->x
-#define y(val) val->y
 
 static void xs_curve_draw(XSCurve *curve, gint width, gint height)
 {
@@ -233,51 +231,36 @@
 	fprintf(stderr, "npoints = %d\n", curve->num_ctlpoints);
 	for (i = 0; i < curve->num_ctlpoints; i++, ++p0, ++p1, ++p2, ++p3) {
 		gfloat k1, k2, a, b, c, d, x;
-		
-		/* p1 and p2 equal; single point */
-		if (x(p1) == x(p2))
+
+		if (p1->x == p2->x)
 			continue;
-		
-		/* Both end points repeated; straight line */
-		if (x(p0) == x(p1) && x(p2) == x(p3)) {
-			k1 = k2 = (y(p2) - y(p1)) / (x(p2) - x(p1));
-		}
-		/* p0 and p1 equal; use f''(x1) = 0 */
-		else if (x(p0) == x(p1)) {
-			k2 = (y(p3) - y(p1)) / (x(p3) - x(p1));
-			k1 = (3 * (y(p2) - y(p1)) / (x(p2) - x(p1)) - k2) / 2;
-		}
-		/* p2 and p3 equal; use f''(x2) = 0 */
-		else if (x(p2) == x(p3)) {
-			k1 = (y(p2) - y(p0)) / (x(p2) - x(p0));
-			k2 = (3 * (y(p2) - y(p1)) / (x(p2) - x(p1)) - k1) / 2;
-		}
-		/* Normal curve */
-		else {
-			k1 = (y(p2) - y(p0)) / (x(p2) - x(p0));
-			k2 = (y(p3) - y(p1)) / (x(p3) - x(p1));
+
+		if (p0->x == p1->x && p2->x == p3->x) {
+			k1 = k2 = (p2->y - p1->y) / (p2->x - p1->x);
+		} else if (p0->x == p1->x) {
+			k2 = (p3->y - p1->y) / (p3->x - p1->x);
+			k1 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k2) / 2;
+		} else if (p2->x == p3->x) {
+			k1 = (p2->y - p0->y) / (p2->x - p0->x);
+			k2 = (3 * (p2->y - p1->y) / (p2->x - p1->x) - k1) / 2;
+		} else {
+			k1 = (p2->y - p0->y) / (p2->x - p0->x);
+			k2 = (p3->y - p1->y) / (p3->x - p1->x);
 		}
 
-		xs_cubic_coeff(x(p1), y(p1), x(p2), y(p2), k1, k2, &a, &b, &c, &d);
-		
-		fprintf(stderr, "--seg[%1.3f, %1.3f]=>[%1.3f, %1.3f]--\n",
-			x(p1), y(p1), x(p2), y(p2));
-		
-		for (x = x(p1); x <= x(p2); x += res) {
+		xs_cubic_coeff(p1->x, p1->y, p2->x, p2->y, k1, k2, &a, &b, &c, &d);
+		fprintf(stderr, "--seg[%1.3f, %1.3f]=>[%1.3f, %1.3f]--\n", p1->x, p1->y, p2->x, p2->y);
+		for (x = p1->x; x <= p2->x; x += res) {
 			gfloat y = ((a * x + b) * x + c) * x + d;
 			gint qx, qy;
 			qx = RADIUS + xs_project(x, curve->min_x, curve->max_x, width);
 			qy = RADIUS + xs_project(y, curve->min_y, curve->max_y, height);
-
 			fprintf(stderr, "[%1.3f, %1.3f] -> %d, %d\n", x, y, qx, qy);
-			
 			gdk_draw_point(curve->pixmap, style->fg_gc[state],
 				RADIUS + xs_project(x, curve->min_x, curve->max_x, width),
-				RADIUS + xs_project(y, curve->min_y, curve->max_y, height)
-				);
+				RADIUS + xs_project(y, curve->min_y, curve->max_y, height));
 
 		}
-		
 		fprintf(stderr, "-------\n");
 	}
 	
@@ -304,9 +287,6 @@
 			height + RADIUS2);
 }
 
-#undef x
-#undef y
-
 
 static gint xs_curve_graph_events(GtkWidget *widget, GdkEvent *event, XSCurve *curve)
 {