* Ready to do the bowing.
struct cxt *cxt = user_data;
struct graph_point *p3 = data;
if(cxt->p0 != NULL) {
- double p1_x = (p3->x - cxt->p0->x)/3.0;
- double p1_y = (p3->y - cxt->p0->y)/3.0;
- double p2_x = (p3->x + 2*cxt->p0->x)/3.0;
- double p2_y = (p3->y + 2*cxt->p0->y)/3.0;
+ double p1_x = (p3->x + 2*cxt->p0->x)/3.0;
+ double p1_y = (p3->y + 2*cxt->p0->y)/3.0;
+ double p2_x = (2*p3->x + cxt->p0->x)/3.0;
+ double p2_y = (2*p3->y + cxt->p0->y)/3.0;
graph_add_line(cxt->graph, cxt->p0->x, cxt->p0->y, p1_x, p1_y, p2_x, p2_y, p3->x, p3->y);
}
cxt->p0 = p3;
cxt.p0 = NULL;
g_ptr_array_foreach(graph->points, &linear_interpolate, &cxt);
}
+
+void graph_bezier_linear_to_cubic(double x0, double x3, double *x1, double *x2) {
+ *x1 = (x3 + 2.0*x0)/3.0;
+ *x2 = (2.0*x3 + x0)/3.0;
+}
+
+void graph_bezier_qudratic_to_cubic(double x0, double x3, double *x1, double *x2) {
+ *x2 = (x3 - x0)/3.0 + (*x1);
+ *x1 = (x0 - 3.0*(*x1))/2.0;
+}
int graph_add_graph_point(Graph* graph, struct graph_point *pt);
int graph_add_line(Graph* graph, double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y);
void graph_add_linear_connectors(Graph* graph);
+/*Provide x0, x3; x1 and x2 will be set*/
+void graph_bezier_linear_to_cubic(double x0, double x3, double *x1, double *x2);
+/*Provide x0, x1, x2. x1 and x2 will be set appropriately.*/
+void graph_bezier_qudratic_to_cubic(double x0, double x3, double *x1, double *x2);
+
+
#endif /* !GRAPHCLASS_H_ */
double p2_y = (l->p2_y + cxt->yoffset)*cxt->yscaling;
double p3_x = (l->p3_x + cxt->xoffset)*cxt->xscaling;
double p3_y = (l->p3_y + cxt->yoffset)*cxt->yscaling;
+ #ifdef DEBUG
+ fprintf(stderr, "draw_lines: p0_x=%g, p0_y=%g, p1_x=%g, p1_y=%g, p2_x=%g, p2_y=%g, p3_x=%g, p3_y=%g\n", p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y);
+ #endif
cairo_move_to(cxt->cr, p0_x, p0_y);
cairo_curve_to(cxt->cr, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y);
}
cairo_select_font_face (cr, "Georgia",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 0.05);
- g_ptr_array_foreach(gw->graph->points, &draw_point, (gpointer)&cxt);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_fill_preserve(cr);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_stroke(cr);
+ g_ptr_array_foreach(gw->graph->points, &draw_point, (gpointer)&cxt);
+ if(gw->graph->lines != NULL) {
+ g_ptr_array_foreach(gw->graph->lines, &draw_lines, (gpointer)&cxt);
+ cairo_stroke(cr);
+ }
cairo_restore(cr);
}