X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=graph.c;fp=graph.c;h=1af3cb8d5276e0c71be6cf7f1027cfddc2e2d0df;hb=f3ddf2cd811f53afd0edaa3b1263035d9faab318;hp=423ff84a121674d30d1f7cb60604b278b0b458df;hpb=2329e96577a27c47e5287118d8808542fbed12ec;p=scdataviz diff --git a/graph.c b/graph.c index 423ff84..1af3cb8 100644 --- a/graph.c +++ b/graph.c @@ -81,13 +81,33 @@ int graph_add_point(Graph* graph, double x, double y, const GString *label) { return 0; } +int graph_add_graph_line(Graph* graph, struct graph_line *l) { + if(graph->lines == NULL) { + if((graph->lines = g_ptr_array_new()) == NULL) return 1; + } + g_ptr_array_add(graph->lines, l); + if((graph->points->len == 0) && + (graph->lines->len == 1)) { + graph->maxx = graph->minx = l->p0_x; + graph->maxy = graph->miny = l->p0_y; + }else{ + if(l->p0_x > graph->maxx) graph->maxx = l->p0_x; + if(l->p0_x < graph->minx) graph->minx = l->p0_x; + if(l->p0_y > graph->maxy) graph->maxy = l->p0_y; + if(l->p0_y < graph->miny) graph->miny = l->p0_y; + } + if(l->p3_x > graph->maxx) graph->maxx = l->p3_x; + if(l->p3_x < graph->minx) graph->minx = l->p3_x; + if(l->p3_y > graph->maxy) graph->maxy = l->p3_y; + if(l->p3_y < graph->miny) graph->miny = l->p3_y; + return 0; +} + + 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) { #ifdef DEBUG fprintf(stderr, "graph_add_line(%d, 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", (unsigned int) graph, p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y); #endif - if(graph->lines == NULL) { - if((graph->lines = g_ptr_array_new()) == NULL) return 1; - } struct graph_line *l; if((l=(struct graph_line*)malloc(sizeof(struct graph_line))) == NULL) return 2; l->p0_x=p0_x; @@ -98,22 +118,7 @@ int graph_add_line(Graph* graph, double p0_x, double p0_y, double p1_x, double p l->p2_y=p2_y; l->p3_x=p3_x; l->p3_y=p3_y; - g_ptr_array_add(graph->lines, l); - if((graph->points->len == 0) && - (graph->lines->len == 1)) { - graph->maxx = graph->minx = p0_x; - graph->maxy = graph->miny = p0_y; - }else{ - if(p0_x > graph->maxx) graph->maxx = p0_x; - if(p0_x < graph->minx) graph->minx = p0_x; - if(p0_y > graph->maxy) graph->maxy = p0_y; - if(p0_y < graph->miny) graph->miny = p0_y; - } - if(p3_x > graph->maxx) graph->maxx = p3_x; - if(p3_x < graph->minx) graph->minx = p3_x; - if(p3_y > graph->maxy) graph->maxy = p3_y; - if(p3_y < graph->miny) graph->miny = p3_y; - return 0; + return graph_add_graph_line(graph, l); } struct cxt { @@ -146,7 +151,11 @@ void graph_bezier_linear_to_cubic(double x0, double x3, double *x1, double *x2) *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; +void graph_bezier_linear_to_quadratic(double x0, double x3, double *x1) { + *x1 = (x3 + x0)/2.0; +} + +void graph_bezier_quadratic_to_cubic(double x0, double x3, double *x1, double *x2) { + *x2 = (x3-2.0*(*x1))/3.0; + *x1 = (x0-2.0*(*x1))/3.0; }