diff options
author | joye <joye> | 2014-05-06 19:17:43 (GMT) |
---|---|---|
committer | joye <joye> | 2014-05-06 19:17:43 (GMT) |
commit | b1eecfc9f2e6f937046026e9dc28f0cc89540d29 (patch) | |
tree | 1c24af1d71208efd0b3709bd832aade957c4d7ba | |
parent | 1360c7c2d78abaee4185a2d4a9a5fabf36a42c70 (diff) | |
download | blt-b1eecfc9f2e6f937046026e9dc28f0cc89540d29.zip blt-b1eecfc9f2e6f937046026e9dc28f0cc89540d29.tar.gz blt-b1eecfc9f2e6f937046026e9dc28f0cc89540d29.tar.bz2 |
*** empty log message ***
-rw-r--r-- | src/bltGrAxis.C | 37 | ||||
-rw-r--r-- | src/bltGraphOp.C | 13 | ||||
-rw-r--r-- | src/bltGraphSup.C | 8 |
3 files changed, 24 insertions, 34 deletions
diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index aae48bb..bf58a91 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -49,10 +49,6 @@ using namespace Blt; #define AXIS_PAD_TITLE 2 #define EXP10(x) (pow(10.0,(x))) -#define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5))) -#define UROUND(x,u) (Round((x)/(u))*(u)) -#define UCEIL(x,u) (ceil((x)/(u))*(u)) -#define UFLOOR(x,u) (floor((x)/(u))*(u)) AxisName axisNames[] = { { "x", CID_AXIS_X, MARGIN_BOTTOM, MARGIN_LEFT }, @@ -64,10 +60,6 @@ AxisName axisNames[] = { // Defs extern double AdjustViewport(double offset, double windowSize); -static int Round(double x) -{ - return (int) (x + ((x < 0.0) ? -0.5 : 0.5)); -} static Tk_OptionSpec optionSpecs[] = { {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "ActiveForeground", @@ -747,23 +739,24 @@ void Axis::logScale(double min, double max) range = tickMax - tickMin; if (range > 10) { - /* There are too many decades to display a major tick at every - * decade. Instead, treat the axis as a linear scale. */ + // There are too many decades to display a major tick at every + // decade. Instead, treat the axis as a linear scale range = niceNum(range, 0); majorStep = niceNum(range / ops->reqNumMajorTicks, 1); - tickMin = UFLOOR(tickMin, majorStep); - tickMax = UCEIL(tickMax, majorStep); + tickMin = floor(tickMin/majorStep)*majorStep; + tickMax = ceil(tickMax/majorStep)*majorStep; nMajor = (int)((tickMax - tickMin) / majorStep) + 1; minorStep = EXP10(floor(log10(majorStep))); if (minorStep == majorStep) { - nMinor = 4, minorStep = 0.2; - } else { - nMinor = ROUND(majorStep / minorStep) - 1; + nMinor = 4; + minorStep = 0.2; } - } else { - if (tickMin == tickMax) { + else + nMinor = (majorStep/minorStep) - 1; + } + else { + if (tickMin == tickMax) tickMax++; - } majorStep = 1.0; nMajor = (int)(tickMax - tickMin + 1); /* FIXME: Check this. */ @@ -817,7 +810,7 @@ void Axis::linearScale(double min, double max) axisMin = tickMin = floor(min / step) * step + 0.0; axisMax = tickMax = ceil(max / step) * step + 0.0; - nTicks = ROUND((tickMax - tickMin) / step) + 1; + nTicks = ((tickMax-tickMin) / step) + 1; } majorSweep_.step = step; majorSweep_.initial = tickMin; @@ -940,7 +933,7 @@ void Axis::fixRange() max = min_ + ops->windowSize; if (max_ >= max) { if (ops->shiftBy > 0.0) - max = UCEIL(max_, ops->shiftBy); + max = ceil(max_/ops->shiftBy)*ops->shiftBy; min_ = max - ops->windowSize; } max_ = max; @@ -1026,7 +1019,7 @@ TickLabel* Axis::makeLabel(double value) char string[TICK_LABEL_SIZE + 1]; if (ops->logScale) - snprintf(string, TICK_LABEL_SIZE, "1E%d", ROUND(value)); + snprintf(string, TICK_LABEL_SIZE, "1E%d", int(value)); else snprintf(string, TICK_LABEL_SIZE, "%.*G", 15, value); @@ -1641,7 +1634,7 @@ Ticks* Axis::generateTicks(TickSweep *sweepPtr) else { double value = sweepPtr->initial; /* Start from smallest axis tick */ for (int ii=0; ii<sweepPtr->nSteps; ii++) { - value = UROUND(value, sweepPtr->step); + value = (value/sweepPtr->step)*sweepPtr->step; ticksPtr->values[ii] = value; value += sweepPtr->step; } diff --git a/src/bltGraphOp.C b/src/bltGraphOp.C index 3e4def5..0edbc81 100644 --- a/src/bltGraphOp.C +++ b/src/bltGraphOp.C @@ -61,7 +61,6 @@ static Tcl_ObjCmdProc GraphObjCmd; static Axis* GetFirstAxis(Blt_Chain chain); -#define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5))) #define PointInRegion(e,x,y) \ (((x) <= (e)->right) && ((x) >= (e)->left) && \ ((y) <= (e)->bottom) && ((y) >= (e)->top)) @@ -293,19 +292,17 @@ static int TransformOp(ClientData clientData, Tcl_Interp* interp, int objc, if (graphPtr->flags & RESET_AXES) graphPtr->resetAxes(); - /* - * Perform the transformation from window to graph coordinates. Note that - * the points are always mapped onto the bottom and left axes (which may - * not be the what the user wants). - */ + // Perform the transformation from window to graph coordinates. Note that + // the points are always mapped onto the bottom and left axes (which may + // not be the what the user wants Axis* xAxis = GetFirstAxis(graphPtr->axisChain_[0]); Axis* yAxis = GetFirstAxis(graphPtr->axisChain_[1]); Point2d point = graphPtr->map2D(x, y, xAxis, yAxis); Tcl_Obj* listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewIntObj(ROUND(point.x))); - Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewIntObj(ROUND(point.y))); + Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewIntObj(point.x)); + Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewIntObj(point.y)); Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; diff --git a/src/bltGraphSup.C b/src/bltGraphSup.C index 3ac2b6c..34bc4ad 100644 --- a/src/bltGraphSup.C +++ b/src/bltGraphSup.C @@ -39,7 +39,6 @@ using namespace Blt; -#define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5))) #define AXIS_PAD_TITLE 2 #define ROTATE_0 0 #define ROTATE_90 1 @@ -538,7 +537,8 @@ void Graph::getAxisGeometry(Axis *axisPtr) // Rotated label width and height double rlw, rlh; getBoundingBox(lw, lh, aops->tickAngle, &rlw, &rlh, NULL); - lw = ROUND(rlw), lh = ROUND(rlh); + lw = rlw; + lh = rlh; } if (axisPtr->maxTickWidth_ < int(lw)) axisPtr->maxTickWidth_ = lw; @@ -549,8 +549,8 @@ void Graph::getAxisGeometry(Axis *axisPtr) unsigned int pad =0; if (aops->exterior) { - /* Because the axis cap style is "CapProjecting", we need to - * account for an extra 1.5 linewidth at the end of each line. */ + // Because the axis cap style is "CapProjecting", we need to + // account for an extra 1.5 linewidth at the end of each line pad = ((aops->lineWidth * 12) / 8); } if (axisPtr->isHorizontal()) |