X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fezplot.cpp;fp=libctgraphics%2Fezplot.cpp;h=c00953554e2c087436a2e4092c0ef0df7885280c;hp=5a2ec69a34a2700a309722310ee61cc19bfb4e0c;hb=2a3686d3bd1f690d318b81766c261da785cf9b57;hpb=c551b53b39a7571cf52831f5e117be1cca95c420 diff --git a/libctgraphics/ezplot.cpp b/libctgraphics/ezplot.cpp index 5a2ec69..c009535 100644 --- a/libctgraphics/ezplot.cpp +++ b/libctgraphics/ezplot.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.cpp,v 1.20 2000/12/20 20:08:48 kevin Exp $ +** $Id: ezplot.cpp,v 1.21 2000/12/23 18:12:35 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -36,15 +36,15 @@ static const int DEF_CURVE_CLR = C_RED; EZPlotCurve::EZPlotCurve (const double* xData, const double* yData, int n, int color, int linestyle, int symbol, int symfreq, const std::string& legend) - : x(NULL), y(NULL), m_sLegend (legend) +: x(NULL), y(NULL), m_sLegend (legend) { x = new double [n]; y = new double [n]; - + int copyCount = n * sizeof(double); memcpy (x, xData, copyCount); memcpy (y, yData, copyCount); - + m_iPointCount = n; m_iColor = color; m_iLineStyle = linestyle; @@ -63,10 +63,10 @@ void EZPlot::addCurve (const double *y, int n) { double* x = new double [n]; - + for (int i = 0; i < n; i++) x[i] = i; - + addCurve (x, y, n); delete x; } @@ -76,10 +76,10 @@ void EZPlot::addCurve (const float *y, int n) { double* yDouble = new double [n]; - + for (int i = 0; i < n; i++) yDouble[i] = y[i]; - + addCurve (yDouble, n); delete yDouble; } @@ -89,10 +89,10 @@ void EZPlot::addCurve (const float x[], const double y[], int num) { double* dx = new double [num]; - + for (int i = 0; i < num; i++) dx[i] = x[i]; - + addCurve (dx, y, num); delete dx; } @@ -101,12 +101,12 @@ void EZPlot::addCurve (const double x[], const float y[], int num) { double* dy = new double [num]; - + for (int i = 0; i < num; i++) dy[i] = y[i]; - + addCurve (x, dy, num); - + delete dy; } @@ -116,7 +116,7 @@ EZPlot::addCurve (const double x[], const double y[], int num) { if (num < 1) return; - + EZPlotCurve* pCurve = new EZPlotCurve (x, y, num, o_color, o_linestyle, o_symbol, o_symfreq, c_legend); m_vecCurves.push_back (pCurve); } @@ -139,9 +139,9 @@ EZPlot::clearCurves () EZPlot::EZPlot (SGP& sgp) - : rSGP (sgp) +: rSGP (sgp) { - initPlotSettings(); + initPlotSettings(); } void @@ -149,7 +149,7 @@ EZPlot::initPlotSettings () { charheight = rSGP.getCharHeight(); charwidth = rSGP.getCharWidth(); - + c_xlabel = ""; c_ylabel = ""; c_title = ""; @@ -204,26 +204,30 @@ EZPlot::initPlotSettings () /* NAME - * plot Plots all curves collected by addCurves () - * - * SYNOPSIS - * plot() - * - * DESCRIPTION - * This routine plots the curves that have stored by addCurves(). - * - * CALLS - * drawAxes() & make_numfmt() - */ +* plot Plots all curves collected by addCurves () +* +* SYNOPSIS +* plot() +* +* DESCRIPTION +* This routine plots the curves that have stored by addCurves(). +* +* CALLS +* drawAxes() & make_numfmt() +*/ void EZPlot::plot () -{ +{ +#if 0 + wxFont* myFont = new wxFont (12, wxMODERN, wxNORMAL, wxNORMAL); + rSGP.getDriver().idWX()->SetFont (*myFont); +#endif if (m_vecCurves.size() <= 0) return; - + rSGP.setWindow (0., 0., 1., 1.); - + if (s_textsize == TRUE) { charheight = v_textsize; charwidth = rSGP.getCharWidth(); @@ -243,13 +247,13 @@ EZPlot::plot () for (int ip = 0; ip < curve.m_iPointCount; ip++) { if (curve.x[ip] > xmax) - xmax = curve.x[ip]; + xmax = curve.x[ip]; else if (curve.x[ip] < xmin) - xmin = curve.x[ip]; + xmin = curve.x[ip]; if (curve.y[ip] > ymax) - ymax = curve.y[ip]; + ymax = curve.y[ip]; else if (curve.y[ip] < ymin) - ymin = curve.y[ip]; + ymin = curve.y[ip]; } } @@ -260,18 +264,18 @@ EZPlot::plot () else if (v_xcross > xmax) xmax = v_xcross; } - + if (s_ycross == TRUE) { if (v_ycross < ymin) ymin = v_ycross; else if (v_ycross > ymax) ymax = v_ycross; } - + // find nice endpoints for axes if (! axis_scale (xmin, xmax, o_xmajortick - 1, &xgw_min, &xgw_max, &x_nint) || ! axis_scale (ymin, ymax, o_ymajortick - 1, &ygw_min, &ygw_max, &y_nint)) return; - + // check if user set x-axis extents if (s_xmin == TRUE) { xgw_min = v_xmin; @@ -291,11 +295,11 @@ EZPlot::plot () ygw_max = v_ymax; y_nint = o_ymajortick - 1; } - + // calculate increment between major axis in world coordinates xw_tickinc = (xgw_max - xgw_min) / x_nint; yw_tickinc = (ygw_max - ygw_min) / y_nint; - + // we have now calcuated xgw_min, xyw_max, ygw_min, & ygw_max // set the number of decimal point to users' setting or default @@ -304,25 +308,25 @@ EZPlot::plot () x_frac = v_lxfrac; else x_frac = -1; - + if (s_lyfrac == TRUE) y_frac = v_lyfrac; else y_frac = -1; - + make_numfmt (x_numfmt, &x_fldwid, &x_frac, xgw_min, xgw_max, x_nint); make_numfmt (y_numfmt, &y_fldwid, &y_frac, ygw_min, ygw_max, y_nint); - + xtl_wid = x_fldwid * charwidth; // calc size of tick labels ytl_wid = y_fldwid * charwidth; tl_height = charheight; - + // calculate the extent of the plot frame xp_min = o_xporigin; yp_min = o_yporigin; xp_max = xp_min + o_xlength; yp_max = yp_min + o_ylength; - + xp_min = clamp (xp_min, 0., 1.); xp_max = clamp (xp_max, 0., 1.); yp_min = clamp (yp_min, 0., 1.); @@ -332,12 +336,12 @@ EZPlot::plot () xa_max = xp_max; ya_min = yp_min; ya_max = yp_max; - + // adjust frame for title if (c_title.length() > 0) ya_max -= 2 * charheight; title_row = ya_max + 2 * charheight; - + // calculate legend box boundaries int max_leg = 0; // longest legend in characters int num_leg = 0; // number of legend titles @@ -347,10 +351,10 @@ EZPlot::plot () if (nLegend > 0) { ++num_leg; if (nLegend > max_leg) - nLegend = max_leg; + nLegend = max_leg; } } - + if (num_leg > 0 && o_legendbox != NOLEGEND) { double leg_width = (max_leg + 2) * charwidth; // size of legend box double leg_height = num_leg * 3 * charheight; @@ -360,7 +364,7 @@ EZPlot::plot () else { xl_max = xa_max; if (o_legendbox == OUTSIDE) - xa_max -= (leg_width + 0.5 * charwidth); + xa_max -= (leg_width + 0.5 * charwidth); } xl_min = xl_max - leg_width; @@ -370,43 +374,43 @@ EZPlot::plot () yl_max = ya_max; yl_min = yl_max - leg_height; - + rSGP.setColor (clr_legend); rSGP.drawRect (xl_min, yl_min, xl_max, yl_max); - + int iLegend = 0; // current legend position for (EZPlotCurveIterator iterCurve = m_vecCurves.begin(); iterCurve != m_vecCurves.end(); iterCurve++) { - const EZPlotCurve& curve = **iterCurve; - - if (curve.m_sLegend.length() == 0) - continue; - - double xmin = xl_min + 1.0 * charwidth; - double xmax = xl_max - 1.0 * charwidth; - double y = yl_max - (2.0 + iLegend * 3) * charheight; - - rSGP.moveAbs (xmin, y + 0.5 * charheight); - rSGP.drawText (curve.m_sLegend); - rSGP.setColor (curve.m_iColor); - if (curve.m_iLineStyle != SGP::LS_NOLINE) { - rSGP.setLineStyle (curve.m_iLineStyle); - rSGP.moveAbs (xmin, y); - rSGP.lineAbs (xmax, y); - } - if (curve.m_iSymbol > 0) { - double xinc = (xmax - xmin) / (5 - 1); - rSGP.setLineStyle (SGP::LS_SOLID); - for (int j = 0; j < 5; j++) { - rSGP.moveAbs (xmin + j * xinc, y); - symbol(curve.m_iSymbol, 0.5 * charwidth, 0.5 * charheight); - } - } - ++iLegend; // move to next legend position + const EZPlotCurve& curve = **iterCurve; + + if (curve.m_sLegend.length() == 0) + continue; + + double xmin = xl_min + 1.0 * charwidth; + double xmax = xl_max - 1.0 * charwidth; + double y = yl_max - (2.0 + iLegend * 3) * charheight; + + rSGP.moveAbs (xmin, y + 0.5 * charheight); + rSGP.drawText (curve.m_sLegend); + rSGP.setColor (curve.m_iColor); + if (curve.m_iLineStyle != SGP::LS_NOLINE) { + rSGP.setLineStyle (curve.m_iLineStyle); + rSGP.moveAbs (xmin, y); + rSGP.lineAbs (xmax, y); + } + if (curve.m_iSymbol > 0) { + double xinc = (xmax - xmin) / (5 - 1); + rSGP.setLineStyle (SGP::LS_SOLID); + for (int j = 0; j < 5; j++) { + rSGP.moveAbs (xmin + j * xinc, y); + symbol(curve.m_iSymbol, 0.5 * charwidth, 0.5 * charheight); + } + } + ++iLegend; // move to next legend position } } // end legend printing - + // calculate the extent of the axes - + /*-------------------------*/ /* adjust frame for labels */ /*-------------------------*/ @@ -415,16 +419,16 @@ EZPlot::plot () if (c_xlabel.length() > 0) ya_min += 3.0 * charheight; xlbl_row = xp_min; // put x-label on bottom of plot frame - + // Y-Label if (c_ylabel.length() > 0) xa_min += 3.0 * charwidth; // reverse rSGP.setTextSize because writing text sideways ylbl_col = xp_min + 2 * charwidth; - + /*------------------------------*/ /* adjust frame for tick labels */ /*------------------------------*/ - + // Calc offset of tick labels from axes if (o_xaxis == NOAXIS || o_xtlabel == FALSE) xtl_ofs = 0.0; @@ -439,12 +443,12 @@ EZPlot::plot () ytl_ofs = -(1 + y_fldwid) * charwidth; else if (o_yticks == RIGHT) ytl_ofs = 1.5 * charwidth; - + xt_min = xa_min; yt_min = ya_min; xt_max = xa_max; yt_max = ya_max; - + // see if need to shrink axis extents and/or tick extents if (xtl_ofs != 0.0 && s_ycross == FALSE) { if (o_xticks == BELOW) { @@ -467,11 +471,11 @@ EZPlot::plot () } } else xt_min = xa_min; - + // decrease size of graph, if necessary, to accommadate space // between axis boundary and boundary of ticks - double x_added_ticks = -1; // number of tick spaces added to axis - double y_added_ticks = -1; + double x_added_ticks = 0; // number of tick spaces added to axis + double y_added_ticks = 0; if (o_xaxis == NOAXIS || o_xtlabel == FALSE) x_added_ticks = 0; if (o_yaxis == NOAXIS || o_ytlabel == FALSE) @@ -510,62 +514,74 @@ EZPlot::plot () xgn_max = xt_max; ygn_min = yt_min; ygn_max = yt_max; - + //------------------------------------------------------------------------ m_xWorldScale = (xgn_max - xgn_min) / (xgw_max - xgw_min); m_yWorldScale = (ygn_max - ygn_min) / (ygw_max - ygw_min); - + // PLOT CURVES rSGP.setLineStyle (SGP::LS_SOLID); drawAxes(); - + // size of symbol in NDC double symwidth = charwidth; double symheight = charheight; - - for (EZPlotCurveIterator iterCurve3 = m_vecCurves.begin(); iterCurve3 != m_vecCurves.end(); iterCurve3++) { - const EZPlotCurve& curve = **iterCurve3; - - rSGP.setColor (curve.m_iColor); + + double clipRect[4]; + clipRect[0] = xgn_min; clipRect[1] = ygn_min; clipRect[2] = xgn_max; clipRect[3] = ygn_max; - if (curve.m_iLineStyle != SGP::LS_NOLINE) { - rSGP.setLineStyle (curve.m_iLineStyle); - double x = convertWorldToNDC_X (curve.x[0]); - double y = convertWorldToNDC_Y (curve.y[0]); - rSGP.moveAbs (x, y); - for (int i = 1; i < curve.m_iPointCount; i++) { - x = convertWorldToNDC_X (curve.x[i]); - y = convertWorldToNDC_Y (curve.y[i]); - rSGP.lineAbs (x, y); - } - } - if (curve.m_iSymbol > 0) { - rSGP.setLineStyle (SGP::LS_SOLID); - double x = convertWorldToNDC_X (curve.x[0]); - double y = convertWorldToNDC_Y (curve.y[0]); - rSGP.moveAbs (x, y); - symbol (curve.m_iSymbol, symwidth, symheight); - for (int i = 1; i < curve.m_iPointCount; i++) - if (i % curve.m_iSymbolFreq == 0 || i == curve.m_iPointCount - 1) { - x = convertWorldToNDC_X (curve.x[i]); - y = convertWorldToNDC_Y (curve.y[i]); - rSGP.moveAbs (x, y); - symbol (curve.m_iSymbol, symwidth, symheight); - } - } + for (EZPlotCurveIterator iterCurve3 = m_vecCurves.begin(); iterCurve3 != m_vecCurves.end(); iterCurve3++) { + const EZPlotCurve& curve = **iterCurve3; + + rSGP.setColor (curve.m_iColor); + + bool bOutside = false; + if (curve.m_iLineStyle != SGP::LS_NOLINE) { + rSGP.setLineStyle (curve.m_iLineStyle); + double x1 = convertWorldToNDC_X (curve.x[0]); + double y1 = convertWorldToNDC_Y (curve.y[0]); + for (int i = 1; i < curve.m_iPointCount; i++) { + double x2 = convertWorldToNDC_X (curve.x[i]); + double y2 = convertWorldToNDC_Y (curve.y[i]); + double x2Clip = x2; + double y2Clip = y2; + if (clip_rect (x1, y1, x2Clip, y2Clip, clipRect)) { + rSGP.moveAbs (x1, y1); + rSGP.lineAbs (x2Clip, y2Clip); + } + x1 = x2; + y1 = y2; + } + } + if (curve.m_iSymbol > 0) { + rSGP.setLineStyle (SGP::LS_SOLID); + double x = convertWorldToNDC_X (curve.x[0]); + double y = convertWorldToNDC_Y (curve.y[0]); + rSGP.moveAbs (x, y); + symbol (curve.m_iSymbol, symwidth, symheight); + for (int i = 1; i < curve.m_iPointCount; i++) + if (i % curve.m_iSymbolFreq == 0 || i == curve.m_iPointCount - 1) { + x = convertWorldToNDC_X (curve.x[i]); + y = convertWorldToNDC_Y (curve.y[i]); + if (y >= ygn_min && y <= ygn_max) { + rSGP.moveAbs (x, y); + symbol (curve.m_iSymbol, symwidth, symheight); + } + } + } } - + } /* NAME - * drawAxes INTERNAL routine to draw axis & label them - * - * SYNOPSIS - * drawAxes() - */ +* drawAxes INTERNAL routine to draw axis & label them +* +* SYNOPSIS +* drawAxes() +*/ void @@ -650,46 +666,46 @@ EZPlot::drawAxes() if (o_grid == TRUE) { rSGP.setColor (clr_grid); for (i = 0; i <= x_nint; i++) { - rSGP.moveAbs (xt_min + xn_tickinc * i, ya_max); - rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min); + rSGP.moveAbs (xt_min + xn_tickinc * i, ya_max); + rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min); } } - rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - c_xlabel.length()*charwidth, xlbl_row); - rSGP.setTextSize (charheight * 2.0); + rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - c_xlabel.length()*charwidth * 1.5, xlbl_row + charheight * 1.5); + rSGP.setTextSize (charheight * 1.5); rSGP.setTextColor (clr_label, -1); rSGP.drawText (c_xlabel); rSGP.setTextSize (charheight); minorinc = xn_tickinc / (o_xminortick + 1); - + for (i = 0; i <= x_nint; i++) { x = xt_min + xn_tickinc * i; rSGP.setColor (clr_axis); rSGP.moveAbs (x, xaxispos); rSGP.lineAbs (x, xaxispos + xticklen); if (i != x_nint) - for (j = 1; j <= o_xminortick; j++) { - x2 = x + minorinc * j; - rSGP.moveAbs (x2, xaxispos); - rSGP.lineAbs (x2, xaxispos + TICKRATIO * xticklen); - } - axis_near = FALSE; - if (xaxispos + xtl_ofs > ya_min && o_yaxis != NOAXIS) { - double xw = xgw_min + i * xw_tickinc; - double x = convertWorldToNDC_X (xw); - double d = x - yaxispos; - if (o_yticks == RIGHT && d >= 0 && d < 0.9 * xn_tickinc) - axis_near = TRUE; - if (o_yticks == LEFT && d <= 0 && d > -0.9 * xn_tickinc) - axis_near = TRUE; - } - - if (o_xtlabel == TRUE && axis_near == FALSE) { - snprintf (str, sizeof(str), x_numfmt, xgw_min + xw_tickinc * i); - numstr = str_skip_head (str, " "); - rSGP.moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs); - rSGP.setTextColor (clr_number, -1); - rSGP.drawText (numstr); - } + for (j = 1; j <= o_xminortick; j++) { + x2 = x + minorinc * j; + rSGP.moveAbs (x2, xaxispos); + rSGP.lineAbs (x2, xaxispos + TICKRATIO * xticklen); + } + axis_near = FALSE; + if (xaxispos + xtl_ofs > ya_min && o_yaxis != NOAXIS) { + double xw = xgw_min + i * xw_tickinc; + double x = convertWorldToNDC_X (xw); + double d = x - yaxispos; + if (o_yticks == RIGHT && d >= 0 && d < 0.9 * xn_tickinc) + axis_near = TRUE; + if (o_yticks == LEFT && d <= 0 && d > -0.9 * xn_tickinc) + axis_near = TRUE; + } + + if (o_xtlabel == TRUE && axis_near == FALSE) { + snprintf (str, sizeof(str), x_numfmt, xgw_min + xw_tickinc * i); + numstr = str_skip_head (str, " "); + rSGP.moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs); + rSGP.setTextColor (clr_number, -1); + rSGP.drawText (numstr); + } } } // X - Axis @@ -715,16 +731,16 @@ EZPlot::drawAxes() if (o_grid == TRUE) { rSGP.setColor (clr_grid); for (i = 0; i <= y_nint; i++) { - y = yt_min + yn_tickinc * i; - rSGP.moveAbs (xa_max, y); - rSGP.lineAbs (xa_min, y); + y = yt_min + yn_tickinc * i; + rSGP.moveAbs (xa_max, y); + rSGP.lineAbs (xa_min, y); } } - rSGP.moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - c_ylabel.length()*charheight); + rSGP.moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - c_ylabel.length()*charheight*1.5); + rSGP.getDriver().idWX()->SetFont(*wxSWISS_FONT); rSGP.setTextAngle (HALFPI); - rSGP.setTextSize (2 * charheight); + rSGP.setTextSize (1.5 * charheight); rSGP.setTextColor (clr_label, -1); - rSGP.drawText (c_ylabel); rSGP.setTextAngle (0.0); rSGP.setTextSize (charheight); minorinc = yn_tickinc / (o_yminortick + 1); @@ -735,27 +751,27 @@ EZPlot::drawAxes() rSGP.moveAbs (yaxispos, y); rSGP.lineAbs (yaxispos + yticklen, y); if (i != y_nint) - for (j = 1; j <= o_yminortick; j++) { - y2 = y + minorinc * j; - rSGP.moveAbs (yaxispos, y2); - rSGP.lineAbs (yaxispos + TICKRATIO * yticklen, y2); - } - axis_near = FALSE; - if (yaxispos + ytl_ofs > xa_min && o_xaxis != NOAXIS) { - double yw = ygw_min + i * yw_tickinc; - double y = convertWorldToNDC_Y (yw); - double d = y - xaxispos; - if (o_xticks == ABOVE && d >= 0 && d < 0.9 * yn_tickinc) - axis_near = TRUE; - if (o_xticks == BELOW && d <= 0 && d > -0.9 * yn_tickinc) - axis_near = TRUE; - } - if (o_ytlabel == TRUE && axis_near == FALSE) { - snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); - rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); - rSGP.setTextColor (clr_number, -1); - rSGP.drawText (str); - } + for (j = 1; j <= o_yminortick; j++) { + y2 = y + minorinc * j; + rSGP.moveAbs (yaxispos, y2); + rSGP.lineAbs (yaxispos + TICKRATIO * yticklen, y2); + } + axis_near = FALSE; + if (yaxispos + ytl_ofs > xa_min && o_xaxis != NOAXIS) { + double yw = ygw_min + i * yw_tickinc; + double y = convertWorldToNDC_Y (yw); + double d = y - xaxispos; + if (o_xticks == ABOVE && d >= 0 && d < 0.9 * yn_tickinc) + axis_near = TRUE; + if (o_xticks == BELOW && d <= 0 && d > -0.9 * yn_tickinc) + axis_near = TRUE; + } + if (o_ytlabel == TRUE && axis_near == FALSE) { + snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); + rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); + rSGP.setTextColor (clr_number, -1); + rSGP.drawText (str); + } } } // Y - Axis } @@ -802,25 +818,25 @@ EZPlot::symbol (int sym, double symwidth, double symheight) /* NAME - * axis_scale calculates graph axis scaling - * - * SYNOPSIS: - * retval = axis_scale (min, max, nint, minp, maxp, nintp, - * rec_total, rec_frac) - * - * INPUT: - * double min Smallest value to plot - * double max Largest value to plot - * int nint Number of intervals desired - * - * OUTPUT: - * int retval FALSE if illegal parameters, else TRUE - * double *minp Minimum graph value - * double *maxp Maximum graph value - * int *nintp Number of intervals for graph - * int *rec_total Recommended field width for printing out the number - * int *rec_frac Recommended number of digits for print fraction - */ +* axis_scale calculates graph axis scaling +* +* SYNOPSIS: +* retval = axis_scale (min, max, nint, minp, maxp, nintp, +* rec_total, rec_frac) +* +* INPUT: +* double min Smallest value to plot +* double max Largest value to plot +* int nint Number of intervals desired +* +* OUTPUT: +* int retval FALSE if illegal parameters, else TRUE +* double *minp Minimum graph value +* double *maxp Maximum graph value +* int *nintp Number of intervals for graph +* int *rec_total Recommended field width for printing out the number +* int *rec_frac Recommended number of digits for print fraction +*/ int EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp) @@ -835,7 +851,7 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp if (fabs(min) < fabs(max)) a = fabs(max); double scale = pow (10.0, floor(log10(a))); - loop: +loop: double mina = min / scale; double maxa = max / scale; double d = (maxa - mina) / nint; @@ -851,17 +867,18 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp v = 5.0; double wdt = v * pow (10.0, e); double g = floor (mina / wdt); - if (fabs(g + 1 - mina / wdt) < j) - g = g + 1; -#if 1 - g++; + if (fabs(g + 1 - mina / wdt) < j) + g = g + 1; +#undef TEST1 +#ifdef TEST1 + g++; #endif *minp = wdt * g; double h = floor (maxa / wdt) + 1.0; if (fabs(maxa / wdt + 1 - h) < j) - h = h - 1; -#if 1 - h--; + h = h - 1; +#ifdef TEST1 + h--; #endif *maxp = wdt * h; *nintp = static_cast(h - g); @@ -878,22 +895,22 @@ EZPlot::axis_scale (double min, double max, int nint, double *minp, double *maxp /* NAME - * make_numfmt Make a numeric format string - * - * SYNOPSIS - * make_numfmt (fmtstr, fldwid, nfrac, min, max, nint) - * char *fmtstr Returned format string for printf() - * int *fldwid Returned field width - * int *nfrac If < 0, then calculate best number of - * fraction places & return that value - * If >= 0, then use that number of places - * double min Minimum value - * double max Maximum value - * int nint Number of intervals between min & max - * - * DESCRIPTION - * This routine is written as an INTERNAL routine for EZPLOT - */ +* make_numfmt Make a numeric format string +* +* SYNOPSIS +* make_numfmt (fmtstr, fldwid, nfrac, min, max, nint) +* char *fmtstr Returned format string for printf() +* int *fldwid Returned field width +* int *nfrac If < 0, then calculate best number of +* fraction places & return that value +* If >= 0, then use that number of places +* double min Minimum value +* double max Maximum value +* int nint Number of intervals between min & max +* +* DESCRIPTION +* This routine is written as an INTERNAL routine for EZPLOT +*/ static inline double trunc (double x) @@ -909,14 +926,14 @@ void EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, double maxval, int nint) { int wid, frac, expon; - + double delta = (maxval - minval) / nint; double absmin = fabs(minval); double absmax = fabs(maxval); if (absmin > absmax) - absmax = absmin; + absmax = absmin; double logt = log10( absmax ); - + if (fabs(logt) >= 6) { // use exponential format if (fabs(logt) > 99) expon = 5; // E+102 @@ -927,7 +944,7 @@ EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, doubl delta /= pow (10., floor(logt)); // scale delta frac = static_cast(fabs(trunc(log10(delta)))) + 1; if (frac < 1) - frac = 1; // to be safe, add decimal pt + frac = 1; // to be safe, add decimal pt } else // use users' frac frac = *nfrac; @@ -944,16 +961,16 @@ EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, doubl if (*nfrac < 0) { // calculate frac if (delta >= 0.999999) - frac = 1; // add a decimal pt to be safe + frac = 1; // add a decimal pt to be safe else - frac = static_cast(fabs(trunc(log10(delta)))) + 1; + frac = static_cast(fabs(trunc(log10(delta)))) + 1; } else // use users' frac frac = *nfrac; wid += 1 + frac; sprintf (fmtstr, "%s%d%s%d%s", "%", wid, ".", frac, "f"); } - + *fldwid = wid; *nfrac = frac; }