void cp_implode(struct curve_points *cp) { int first_point, num_points; int i, j, k; double x = 0., y = 0., sux = 0., slx = 0., suy = 0., sly = 0.; double weight; /* used for acsplines */ TBOOLEAN all_inrange = FALSE; x_axis = cp->x_axis; y_axis = cp->y_axis; j = 0; first_point = 0; while ((num_points = next_curve(cp, &first_point)) > 0) { k = 0; for (i = first_point; i < first_point + num_points; i++) { /* HBB 20020801: don't try to use undefined datapoints */ if (cp->points[i].type == UNDEFINED) continue; if (!k) { x = cp->points[i].x; y = cp->points[i].y; sux = cp->points[i].xhigh; slx = cp->points[i].xlow; suy = cp->points[i].yhigh; sly = cp->points[i].ylow; weight = cp->points[i].z; all_inrange = (cp->points[i].type == INRANGE); k = 1; } else if (cp->points[i].x == x) { y += cp->points[i].y; sux += cp->points[i].xhigh; slx += cp->points[i].xlow; suy += cp->points[i].yhigh; sly += cp->points[i].ylow; weight += cp->points[i].z; if (cp->points[i].type != INRANGE) all_inrange = FALSE; k++; } else { cp->points[j].x = x; if ( cp->plot_smooth == SMOOTH_FREQUENCY || cp->plot_smooth == SMOOTH_CUMULATIVE || cp->plot_smooth == SMOOTH_CUMULATIVE_NORMALISED ) k = 1; cp->points[j].y = y /= (double) k; cp->points[j].xhigh = sux / (double) k; cp->points[j].xlow = slx / (double) k; cp->points[j].yhigh = suy / (double) k; cp->points[j].ylow = sly / (double) k; cp->points[j].z = weight / (double) k; /* HBB 20000405: I wanted to use STORE_AND_FIXUP_RANGE * here, but won't: it assumes we want to modify the * range, and that the range is given in 'input' * coordinates. For logarithmic axes, the overhead * would be larger than the possible gain, so write it * out explicitly, instead: * */ cp->points[j].type = INRANGE; if (! all_inrange) { if (X_AXIS.log) { if (x <= -VERYLARGE) { cp->points[j].type = OUTRANGE; goto is_outrange; } x = AXIS_UNDO_LOG(x_axis, x); } if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN)) || ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) { cp->points[j].type = OUTRANGE; goto is_outrange; } if (Y_AXIS.log) { if (y <= -VERYLARGE) { cp->points[j].type = OUTRANGE; goto is_outrange; } y = AXIS_UNDO_LOG(y_axis, y); } if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN)) || ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX))) cp->points[j].type = OUTRANGE; is_outrange: ; } /* if(! all inrange) */ j++; /* next valid entry */ k = 0; /* to read */ i--; /* from this (-> last after for(;;)) entry */ } /* else (same x position) */ } /* for(points in curve) */ if (k) { cp->points[j].x = x; if ( cp->plot_smooth == SMOOTH_FREQUENCY || cp->plot_smooth == SMOOTH_CUMULATIVE || cp->plot_smooth == SMOOTH_CUMULATIVE) k = 1; cp->points[j].y = y /= (double) k; cp->points[j].xhigh = sux / (double) k; cp->points[j].xlow = slx / (double) k; cp->points[j].yhigh = suy / (double) k; cp->points[j].ylow = sly / (double) k; cp->points[j].z = weight / (double) k; cp->points[j].type = INRANGE; if (! all_inrange) { if (X_AXIS.log) { if (x <= -VERYLARGE) { cp->points[j].type = OUTRANGE; goto is_outrange2; } x = AXIS_UNDO_LOG(x_axis, x); } if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN)) || ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) { cp->points[j].type = OUTRANGE; goto is_outrange2; } if (Y_AXIS.log) { if (y <= -VERYLARGE) { cp->points[j].type = OUTRANGE; goto is_outrange2; } y = AXIS_UNDO_LOG(y_axis, y); } if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN)) || ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX))) cp->points[j].type = OUTRANGE; is_outrange2: ; } j++; /* next valid entry */ } /* insert invalid point to separate curves */ if (j < cp->p_count) { cp->points[j].type = UNDEFINED; j++; } first_point += num_points; } /* end while */ cp->p_count = j; cp_extend(cp, j); }
void cp_implode(struct curve_points *cp) { int first_point, num_points; int i, j, k; double x = 0., y = 0., sux = 0., slx = 0., suy = 0., sly = 0.; double weight; /* used for acsplines */ TBOOLEAN all_inrange = FALSE; x_axis = cp->x_axis; y_axis = cp->y_axis; j = 0; first_point = 0; while ((num_points = next_curve(cp, &first_point)) > 0) { k = 0; for (i = first_point; i < first_point + num_points; i++) { /* HBB 20020801: don't try to use undefined datapoints */ if (cp->points[i].type == UNDEFINED) continue; if (!k) { x = cp->points[i].x; y = cp->points[i].y; sux = cp->points[i].xhigh; slx = cp->points[i].xlow; suy = cp->points[i].yhigh; sly = cp->points[i].ylow; weight = cp->points[i].z; all_inrange = (cp->points[i].type == INRANGE); k = 1; } else if (cp->points[i].x == x) { y += cp->points[i].y; sux += cp->points[i].xhigh; slx += cp->points[i].xlow; suy += cp->points[i].yhigh; sly += cp->points[i].ylow; weight += cp->points[i].z; if (cp->points[i].type != INRANGE) all_inrange = FALSE; k++; } else { cp->points[j].x = x; if ( cp->plot_smooth == SMOOTH_FREQUENCY || cp->plot_smooth == SMOOTH_FREQUENCY_NORMALISED || cp->plot_smooth == SMOOTH_CUMULATIVE || cp->plot_smooth == SMOOTH_CUMULATIVE_NORMALISED ) k = 1; cp->points[j].y = y /= (double) k; cp->points[j].xhigh = sux / (double) k; cp->points[j].xlow = slx / (double) k; cp->points[j].yhigh = suy / (double) k; cp->points[j].ylow = sly / (double) k; cp->points[j].z = weight / (double) k; /* HBB 20000405: I wanted to use STORE_AND_FIXUP_RANGE here, * but won't: it assumes we want to modify the range, and * that the range is given in 'input' coordinates. */ cp->points[j].type = INRANGE; if (! all_inrange) { if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN)) || ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) { cp->points[j].type = OUTRANGE; goto is_outrange; } if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN)) || ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX))) cp->points[j].type = OUTRANGE; is_outrange: ; } /* if (! all inrange) */ j++; /* next valid entry */ k = 0; /* to read */ i--; /* from this (-> last after for(;;)) entry */ } /* else (same x position) */ } /* for(points in curve) */ if (k) { cp->points[j].x = x; if ( cp->plot_smooth == SMOOTH_FREQUENCY || cp->plot_smooth == SMOOTH_FREQUENCY_NORMALISED || cp->plot_smooth == SMOOTH_CUMULATIVE || cp->plot_smooth == SMOOTH_CUMULATIVE_NORMALISED) k = 1; cp->points[j].y = y /= (double) k; cp->points[j].xhigh = sux / (double) k; cp->points[j].xlow = slx / (double) k; cp->points[j].yhigh = suy / (double) k; cp->points[j].ylow = sly / (double) k; cp->points[j].z = weight / (double) k; cp->points[j].type = INRANGE; if (! all_inrange) { if (((x < X_AXIS.min) && !(X_AXIS.autoscale & AUTOSCALE_MIN)) || ((x > X_AXIS.max) && !(X_AXIS.autoscale & AUTOSCALE_MAX))) { cp->points[j].type = OUTRANGE; goto is_outrange2; } if (((y < Y_AXIS.min) && !(Y_AXIS.autoscale & AUTOSCALE_MIN)) || ((y > Y_AXIS.max) && !(Y_AXIS.autoscale & AUTOSCALE_MAX))) cp->points[j].type = OUTRANGE; is_outrange2: ; } j++; /* next valid entry */ } /* FIXME: Monotonic cubic splines support only a single curve per data set */ if (j < cp->p_count && cp->plot_smooth == SMOOTH_MONOTONE_CSPLINE) { break; } /* insert invalid point to separate curves */ if (j < cp->p_count) { cp->points[j].type = UNDEFINED; j++; } first_point += num_points; } /* end while */ cp->p_count = j; cp_extend(cp, j); }