diff options
author | joye <joye> | 2015-06-24 21:04:55 (GMT) |
---|---|---|
committer | joye <joye> | 2015-06-24 21:04:55 (GMT) |
commit | 1532d0ed55d2c814c83bb5798eeb34cc25869304 (patch) | |
tree | 0aafca012f06dcd017d768b585fd026da983d81c | |
parent | 821e38f363b36d8ce19b6af6f5940db4f2adbadd (diff) | |
download | blt-1532d0ed55d2c814c83bb5798eeb34cc25869304.zip blt-1532d0ed55d2c814c83bb5798eeb34cc25869304.tar.gz blt-1532d0ed55d2c814c83bb5798eeb34cc25869304.tar.bz2 |
*** empty log message ***
-rw-r--r-- | src/bltGrElemLine.C | 153 | ||||
-rw-r--r-- | src/bltGrElemOp.C | 8 | ||||
-rw-r--r-- | src/bltGrElemOption.C | 5 | ||||
-rw-r--r-- | src/bltGrMarker.C | 12 | ||||
-rw-r--r-- | src/bltGrMarkerLine.C | 10 | ||||
-rw-r--r-- | src/bltGrMarkerPolygon.C | 9 | ||||
-rw-r--r-- | src/bltGrMisc.C | 37 | ||||
-rw-r--r-- | src/bltGrPSOutput.C | 7 | ||||
-rw-r--r-- | src/bltGraphBar.C | 14 | ||||
-rw-r--r-- | src/bltGraphSup.C | 2 | ||||
-rw-r--r-- | src/bltOp.C | 17 | ||||
-rw-r--r-- | src/bltSwitch.C | 34 | ||||
-rw-r--r-- | src/bltVecCmd.C | 37 | ||||
-rw-r--r-- | src/bltVecMath.C | 143 |
14 files changed, 197 insertions, 291 deletions
diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index af33208..6d7b27e 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -524,9 +524,7 @@ void LineElement::draw(Drawable drawable) XPoint*points = new XPoint[nFillPts_]; unsigned int count =0; - Point2d *endp, *pp; - for (pp = fillPts_, endp = pp + nFillPts_; - pp < endp; pp++) { + for (Point2d *pp = fillPts_, *endp = pp + nFillPts_; pp < endp; pp++) { points[count].x = pp->x; points[count].y = pp->y; count++; @@ -959,21 +957,21 @@ void LineElement::getScreenPoints(MapInfo* mapPtr) int count = 0; if (gops->inverted) { - for (int i = 0; i < np; i++) { - if ((isfinite(x[i])) && (isfinite(y[i]))) { - points[count].x = ops->yAxis->hMap(y[i]); - points[count].y = ops->xAxis->vMap(x[i]); - map[count] = i; + for (int ii=0; ii<np; ii++) { + if ((isfinite(x[ii])) && (isfinite(y[ii]))) { + points[count].x = ops->yAxis->hMap(y[ii]); + points[count].y = ops->xAxis->vMap(x[ii]); + map[count] = ii; count++; } } } else { - for (int i = 0; i < np; i++) { - if ((isfinite(x[i])) && (isfinite(y[i]))) { - points[count].x = ops->xAxis->hMap(x[i]); - points[count].y = ops->yAxis->vMap(y[i]); - map[count] = i; + for (int ii=0; ii< np; ii++) { + if ((isfinite(x[ii])) && (isfinite(y[ii]))) { + points[count].x = ops->xAxis->hMap(x[ii]); + points[count].y = ops->yAxis->vMap(y[ii]); + map[count] = ii; count++; } } @@ -1038,21 +1036,21 @@ double LineElement::findSplit(Point2d *points, int i, int j, int *split) { double maxDist2 = -1.0; if ((i + 1) < j) { - int k; double a = points[i].y - points[j].y; double b = points[j].x - points[i].x; double c = (points[i].x * points[j].y) - (points[i].y * points[j].x); - for (k = (i + 1); k < j; k++) { - double dist2 = (points[k].x * a) + (points[k].y * b) + c; + for (int kk = (i + 1); kk < j; kk++) { + double dist2 = (points[kk].x * a) + (points[kk].y * b) + c; if (dist2 < 0.0) dist2 = -dist2; + // Track the maximum. if (dist2 > maxDist2) { - maxDist2 = dist2; /* Track the maximum. */ - *split = k; + maxDist2 = dist2; + *split = kk; } } - /* Correction for segment length---should be redone if can == 0 */ + // Correction for segment length---should be redone if can == 0 maxDist2 *= maxDist2 / (a * a + b * b); } return maxDist2; @@ -1173,14 +1171,8 @@ void LineElement::generateSpline(MapInfo *mapPtr) void LineElement::generateParametricSpline(MapInfo *mapPtr) { - Point2d *origPts, *iPts; - int *map; - int niPts, nOrigPts; - int result; - int i, j; - - nOrigPts = mapPtr->nScreenPts; - origPts = mapPtr->screenPts; + int nOrigPts = mapPtr->nScreenPts; + Point2d *origPts = mapPtr->screenPts; Region2d exts; graphPtr_->extents(&exts); @@ -1190,19 +1182,16 @@ void LineElement::generateParametricSpline(MapInfo *mapPtr) * X-coordinates for each horizontal pixel that the line segment contains. */ int count = 1; - for (i = 0, j = 1; j < nOrigPts; i++, j++) { - Point2d p, q; - - p = origPts[i]; - q = origPts[j]; + for (int i = 0, j = 1; j < nOrigPts; i++, j++) { + Point2d p = origPts[i]; + Point2d q = origPts[j]; count++; - if (lineRectClip(&exts, &p, &q)) { + if (lineRectClip(&exts, &p, &q)) count += (int)(hypot(q.x - p.x, q.y - p.y) * 0.5); - } } - niPts = count; - iPts = new Point2d[niPts]; - map = new int[niPts]; + int niPts = count; + Point2d *iPts = new Point2d[niPts]; + int* map = new int[niPts]; /* * FIXME: This is just plain wrong. The spline should be computed @@ -1215,14 +1204,12 @@ void LineElement::generateParametricSpline(MapInfo *mapPtr) * line segments should be clipped, not the original segments. */ count = 0; + int i,j; for (i = 0, j = 1; j < nOrigPts; i++, j++) { - Point2d p, q; - double d; - - p = origPts[i]; - q = origPts[j]; + Point2d p = origPts[i]; + Point2d q = origPts[j]; - d = hypot(q.x - p.x, q.y - p.y); + double d = hypot(q.x - p.x, q.y - p.y); /* Add the original x-coordinate */ iPts[count].x = (double)i; iPts[count].y = 0.0; @@ -1257,7 +1244,7 @@ void LineElement::generateParametricSpline(MapInfo *mapPtr) map[count] = mapPtr->map[i]; count++; niPts = count; - result = 0; + int result = 0; if (smooth_ == CUBIC) result = naturalParametricSpline(origPts, nOrigPts, &exts, 0, iPts, niPts); else if (smooth_ == CATROM) @@ -1281,17 +1268,16 @@ void LineElement::generateParametricSpline(MapInfo *mapPtr) void LineElement::mapSymbols(MapInfo *mapPtr) { - Point2d *pp; - int i; - Point2d* points = new Point2d[mapPtr->nScreenPts]; int *map = new int[mapPtr->nScreenPts]; Region2d exts; graphPtr_->extents(&exts); + Point2d *pp; int count = 0; - for (pp = mapPtr->screenPts, i = 0; i < mapPtr->nScreenPts; i++, pp++) { + int i; + for (pp=mapPtr->screenPts, i=0; i<mapPtr->nScreenPts; i++, pp++) { if (PointInRegion(&exts, pp->x, pp->y)) { points[count].x = pp->x; points[count].y = pp->y; @@ -1875,23 +1861,18 @@ int LineElement::closestTrace() GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; ClosestSearch* searchPtr = &gops->search; - ChainLink* link; Point2d closest; - double dMin; - int iClose; - iClose = -1; - dMin = searchPtr->dist; + int iClose = -1; + double dMin = searchPtr->dist; closest.x = closest.y = 0; - for (link = Chain_FirstLink(traces_); link; link = Chain_NextLink(link)) { - Point2d *p, *pend; - + for (ChainLink *link=Chain_FirstLink(traces_); link; + link = Chain_NextLink(link)) { bltTrace *tracePtr = (bltTrace*)Chain_GetValue(link); - for (p = tracePtr->screenPts.points, - pend = p + (tracePtr->screenPts.length - 1); p < pend; p++) { + for (Point2d *p=tracePtr->screenPts.points, + *pend=p + (tracePtr->screenPts.length - 1); p<pend; p++) { Point2d b; double d; - if (searchPtr->along == SEARCH_X) d = distanceToX(searchPtr->x, searchPtr->y, p, p + 1, &b); else if (searchPtr->along == SEARCH_Y) @@ -1929,10 +1910,9 @@ void LineElement::closestPoint(ClosestSearch *searchPtr) // array of mapped screen coordinates. The advantages are // 1) only examine points that are visible (unclipped), and // 2) the computed distance is already in screen coordinates. - int count; - Point2d *pp; - for (pp = symbolPts_.points, count = 0; - count < symbolPts_.length; count++, pp++) { + int count =0; + for (Point2d *pp = symbolPts_.points; count < symbolPts_.length; + count++, pp++) { double dx = (double)(searchPtr->x - pp->x); double dy = (double)(searchPtr->y - pp->y); double d; @@ -1968,9 +1948,8 @@ void LineElement::drawCircle(Display *display, Drawable drawable, int count = 0; int s = radius + radius; XArc* arcs = new XArc[nSymbolPts]; - XArc *ap, *aend; - Point2d *pp, *pend; - for (ap=arcs, pp=symbolPts, pend=pp+nSymbolPts; pp<pend; pp++) { + XArc *ap = arcs; + for (Point2d *pp=symbolPts, *pend=pp+nSymbolPts; pp<pend; pp++) { if (DRAW_SYMBOL()) { ap->x = pp->x - radius; ap->y = pp->y - radius; @@ -1984,7 +1963,7 @@ void LineElement::drawCircle(Display *display, Drawable drawable, symbolCounter_++; } - for (ap=arcs, aend=ap+count; ap<aend; ap++) { + for (XArc *ap=arcs, *aend=ap+count; ap<aend; ap++) { if (penOps->symbol.fillGC) XFillArc(display, drawable, penOps->symbol.fillGC, ap->x, ap->y, ap->width, ap->height, ap->angle1, ap->angle2); @@ -2003,12 +1982,11 @@ void LineElement::drawSquare(Display *display, Drawable drawable, { LinePenOptions* penOps = (LinePenOptions*)penPtr->ops(); - int count =0; int s = r + r; + int count =0; XRectangle* rectangles = new XRectangle[nSymbolPts]; - XRectangle *rp, *rend; - Point2d *pp, *pend; - for (rp=rectangles, pp=symbolPts, pend=pp+nSymbolPts; pp<pend; pp++) { + XRectangle* rp=rectangles; + for (Point2d *pp=symbolPts, *pend=pp+nSymbolPts; pp<pend; pp++) { if (DRAW_SYMBOL()) { rp->x = pp->x - r; rp->y = pp->y - r; @@ -2020,7 +1998,7 @@ void LineElement::drawSquare(Display *display, Drawable drawable, symbolCounter_++; } - for (rp=rectangles, rend=rp+count; rp<rend; rp ++) { + for (XRectangle *rp=rectangles, *rend=rp+count; rp<rend; rp ++) { if (penOps->symbol.fillGC) XFillRectangle(display, drawable, penOps->symbol.fillGC, rp->x, rp->y, rp->width, rp->height); @@ -2106,8 +2084,7 @@ void LineElement::drawCross(Display *display, Drawable drawable, int count = 0; XPoint* polygon = new XPoint[nSymbolPts*13]; XPoint* xpp = polygon; - Point2d *pp, *endp; - for (pp = symbolPts, endp = pp + nSymbolPts; pp < endp; pp++) { + for (Point2d *pp = symbolPts, *endp = pp + nSymbolPts; pp < endp; pp++) { if (DRAW_SYMBOL()) { int rndx = pp->x; int rndy = pp->y; @@ -2162,8 +2139,7 @@ void LineElement::drawDiamond(Display *display, Drawable drawable, int count = 0; XPoint* polygon = new XPoint[nSymbolPts*5]; XPoint* xpp = polygon; - Point2d *pp, *endp; - for (pp = symbolPts, endp = pp + nSymbolPts; pp < endp; pp++) { + for (Point2d *pp = symbolPts, *endp = pp + nSymbolPts; pp < endp; pp++) { if (DRAW_SYMBOL()) { int rndx = pp->x; int rndy = pp->y; @@ -2234,8 +2210,7 @@ void LineElement::drawArrow(Display *display, Drawable drawable, int count = 0; XPoint* polygon = new XPoint[nSymbolPts*4]; XPoint* xpp = polygon; - Point2d *pp, *endp; - for (pp = symbolPts, endp = pp + nSymbolPts; pp < endp; pp++) { + for (Point2d *pp = symbolPts, *endp = pp + nSymbolPts; pp < endp; pp++) { if (DRAW_SYMBOL()) { int rndx = pp->x; int rndy = pp->y; @@ -2319,9 +2294,8 @@ void LineElement::drawTraces(Drawable drawable, LinePen* penPtr) int count = tracePtr->screenPts.length; XPoint* points = new XPoint[count]; - XPoint*xpp; - int ii; - for (ii=0, xpp=points; ii<count; ii++, xpp++) { + XPoint*xpp = points; + for (int ii=0; ii<count; ii++, xpp++) { xpp->x = tracePtr->screenPts.points[ii].x; xpp->y = tracePtr->screenPts.points[ii].y; } @@ -2337,20 +2311,17 @@ void LineElement::drawValues(Drawable drawable, LinePen* penPtr, LineElementOptions* ops = (LineElementOptions*)ops_; LinePenOptions* pops = (LinePenOptions*)penPtr->ops(); - Point2d *pp, *endp; - double *xval, *yval; - const char* fmt; char string[TCL_DOUBLE_SPACE * 2 + 2]; - - fmt = pops->valueFormat; + const char* fmt = pops->valueFormat; if (fmt == NULL) fmt = "%g"; TextStyle ts(graphPtr_, &pops->valueStyle); + double* xval = ops->coords.x->values_; + double* yval = ops->coords.y->values_; int count = 0; - xval = ops->coords.x->values_, yval = ops->coords.y->values_; - for (pp = points, endp = points + length; pp < endp; pp++) { + for (Point2d *pp = points, *endp = points + length; pp < endp; pp++) { double x = xval[map[count]]; double y = yval[map[count]]; count++; @@ -2434,8 +2405,7 @@ void LineElement::printSymbols(PSOutput* psPtr, LinePen* penPtr, int size, } int count =0; - Point2d *pp, *endp; - for (pp = symbolPts, endp = symbolPts + nSymbolPts; pp < endp; pp++) { + for (Point2d *pp=symbolPts, *endp=symbolPts + nSymbolPts; pp < endp; pp++) { if (DRAW_SYMBOL()) { psPtr->format("%g %g %g %s\n", pp->x, pp->y, symbolSize, symbolMacros[pops->symbol.type]); @@ -2492,8 +2462,7 @@ void LineElement::printValues(PSOutput* psPtr, LinePen* penPtr, TextStyle ts(graphPtr_, &pops->valueStyle); int count = 0; - Point2d *pp, *endp; - for (pp = symbolPts, endp = symbolPts + nSymbolPts; pp < endp; pp++) { + for (Point2d *pp=symbolPts, *endp=symbolPts + nSymbolPts; pp < endp; pp++) { double x = ops->coords.x->values_[pointToData[count]]; double y = ops->coords.y->values_[pointToData[count]]; count++; diff --git a/src/bltGrElemOp.C b/src/bltGrElemOp.C index f4b389f..4fe6047 100644 --- a/src/bltGrElemOp.C +++ b/src/bltGrElemOp.C @@ -370,8 +370,8 @@ static int LowerOp(ClientData clientData, Tcl_Interp* interp, } // Append the links to end of the display list - ChainLink *link, *next; - for (link = Chain_FirstLink(chain); link; link = next) { + ChainLink *next; + for (ChainLink *link = Chain_FirstLink(chain); link; link = next) { next = Chain_NextLink(link); chain->unlinkLink(link); graphPtr->elements_.displayList->linkAfter(link, NULL); @@ -435,8 +435,8 @@ static int RaiseOp(ClientData clientData, Tcl_Interp* interp, } // Prepend the links to beginning of the display list in reverse order - ChainLink *link, *prev; - for (link = Chain_LastLink(chain); link; link = prev) { + ChainLink *prev; + for (ChainLink *link = Chain_LastLink(chain); link; link = prev) { prev = Chain_PrevLink(link); chain->unlinkLink(link); graphPtr->elements_.displayList->linkBefore(link, NULL); diff --git a/src/bltGrElemOption.C b/src/bltGrElemOption.C index 8fdad62..57c7d41 100644 --- a/src/bltGrElemOption.C +++ b/src/bltGrElemOption.C @@ -383,9 +383,8 @@ static int ParseValues(Tcl_Interp* interp, Tcl_Obj *objPtr, int *nValuesPtr, return TCL_ERROR; } - double *p; - int i; - for (p = array, i = 0; i < objc; i++, p++) { + int i=0; + for (double* p = array; i < objc; i++, p++) { if (Tcl_GetDoubleFromObj(interp, objv[i], p) != TCL_OK) { delete [] array; return TCL_ERROR; diff --git a/src/bltGrMarker.C b/src/bltGrMarker.C index 6195a0c..8b4f4c0 100644 --- a/src/bltGrMarker.C +++ b/src/bltGrMarker.C @@ -146,8 +146,7 @@ int Marker::regionInPolygon(Region2d *regionPtr, Point2d *points, int nPoints, { if (enclosed) { // All points of the polygon must be inside the rectangle. - Point2d *pp, *pend; - for (pp = points, pend = pp + nPoints; pp < pend; pp++) { + for (Point2d *pp = points, *pend = pp + nPoints; pp < pend; pp++) { if ((pp->x < regionPtr->left) || (pp->x > regionPtr->right) || (pp->y < regionPtr->top) || (pp->y > regionPtr->bottom)) { return 0; /* One point is exterior. */ @@ -159,12 +158,9 @@ int Marker::regionInPolygon(Region2d *regionPtr, Point2d *points, int nPoints, // If any segment of the polygon clips the bounding region, the // polygon overlaps the rectangle. points[nPoints] = points[0]; - Point2d *pp, *pend; - for (pp = points, pend = pp + nPoints; pp < pend; pp++) { - Point2d p, q; - - p = *pp; - q = *(pp + 1); + for (Point2d *pp = points, *pend = pp + nPoints; pp < pend; pp++) { + Point2d p = *pp; + Point2d q = *(pp + 1); if (lineRectClip(regionPtr, &p, &q)) return 1; } diff --git a/src/bltGrMarkerLine.C b/src/bltGrMarkerLine.C index 940c692..f5ca90c 100644 --- a/src/bltGrMarkerLine.C +++ b/src/bltGrMarkerLine.C @@ -203,8 +203,7 @@ int LineMarker::pointInSegments(Point2d* samplePtr, Segment2d* segments, int nSegments, double halo) { double minDist = DBL_MAX; - Segment2d *sp, *send; - for (sp = segments, send = sp + nSegments; sp < send; sp++) { + for (Segment2d *sp = segments, *send = sp + nSegments; sp < send; sp++) { Point2d t = getProjection((int)samplePtr->x, (int)samplePtr->y, &sp->p, &sp->q); double right; @@ -249,9 +248,7 @@ int LineMarker::regionIn(Region2d *extsPtr, int enclosed) return 0; if (enclosed) { - Point2d *pp, *pend; - - for (pp = ops->worldPts->points, pend = pp + ops->worldPts->num; + for (Point2d *pp = ops->worldPts->points, *pend = pp + ops->worldPts->num; pp < pend; pp++) { Point2d p = mapPoint(pp, ops->xAxis, ops->yAxis); if ((p.x < extsPtr->left) && (p.x > extsPtr->right) && @@ -262,9 +259,8 @@ int LineMarker::regionIn(Region2d *extsPtr, int enclosed) return 1; } else { - Point2d *pp, *pend; int count = 0; - for (pp = ops->worldPts->points, pend = pp + (ops->worldPts->num - 1); + for (Point2d *pp=ops->worldPts->points, *pend=pp+(ops->worldPts->num - 1); pp < pend; pp++) { Point2d p = mapPoint(pp, ops->xAxis, ops->yAxis); Point2d q = mapPoint(pp + 1, ops->xAxis, ops->yAxis); diff --git a/src/bltGrMarkerPolygon.C b/src/bltGrMarkerPolygon.C index 8df2043..7f52245 100644 --- a/src/bltGrMarkerPolygon.C +++ b/src/bltGrMarkerPolygon.C @@ -163,8 +163,7 @@ void PolygonMarker::draw(Drawable drawable) return; XPoint* dp = points; - Point2d *sp, *send; - for (sp = fillPts_, send = sp + nFillPts_; sp < send; sp++) { + for (Point2d *sp = fillPts_, *send = sp + nFillPts_; sp < send; sp++) { dp->x = (short int)sp->x; dp->y = (short int)sp->y; dp++; @@ -211,8 +210,7 @@ void PolygonMarker::map() Point2d* screenPts = new Point2d[nScreenPts + 1]; { Point2d* dp = screenPts; - Point2d *sp, *send; - for (sp = ops->worldPts->points, send = sp + ops->worldPts->num; + for (Point2d *sp = ops->worldPts->points, *send = sp + ops->worldPts->num; sp < send; sp++) { *dp = mapPoint(sp, ops->xAxis, ops->yAxis); dp->x += ops->xOffset; @@ -246,8 +244,7 @@ void PolygonMarker::map() // Note that this assumes that the point array contains an extra point // that closes the polygon. Segment2d* segPtr = outlinePts; - Point2d *sp, *send; - for (sp = screenPts, send = sp + (nScreenPts - 1); sp < send; sp++) { + for (Point2d *sp=screenPts, *send=sp+(nScreenPts - 1); sp < send; sp++) { segPtr->p = sp[0]; segPtr->q = sp[1]; if (lineRectClip(&extents, &segPtr->p, &segPtr->q)) { diff --git a/src/bltGrMisc.C b/src/bltGrMisc.C index 91b9e8d..5a06eb8 100644 --- a/src/bltGrMisc.C +++ b/src/bltGrMisc.C @@ -54,11 +54,8 @@ char* Blt::dupstr(const char* str) int Blt::pointInPolygon(Point2d *s, Point2d *points, int nPoints) { - Point2d *p, *q, *qend; - int count; - - count = 0; - for (p = points, q = p + 1, qend = p + nPoints; q < qend; p++, q++) { + int count = 0; + for (Point2d *p=points, *q=p+1, *qend=p + nPoints; q < qend; p++, q++) { if (((p->y <= s->y) && (s->y < q->y)) || ((q->y <= s->y) && (s->y < p->y))) { double b; @@ -157,17 +154,12 @@ int Blt::lineRectClip(Region2d* regionPtr, Point2d *p, Point2d *q) int Blt::polyRectClip(Region2d *regionPtr, Point2d *points, int nPoints, Point2d *clipPts) { - Point2d *p; /* First vertex of input polygon edge. */ - Point2d *pend; - Point2d *q; /* Last vertex of input polygon edge. */ - Point2d *r; - int count; - - r = clipPts; - count = 0; /* Counts # of vertices in output polygon. */ + Point2d* r = clipPts; + // Counts # of vertices in output polygon. + int count = 0; points[nPoints] = points[0]; - for (p = points, q = p + 1, pend = p + nPoints; p < pend; p++, q++) { + for (Point2d *p=points, *q=p+1, *pend=p+nPoints; p<pend; p++, q++) { double dx, dy; double tin1, tin2, tinx, tiny; double xin, yin, xout, yout; @@ -184,14 +176,16 @@ int Blt::polyRectClip(Region2d *regionPtr, Point2d *points, int nPoints, if (dx > 0.0) { /* Left */ xin = regionPtr->left; xout = regionPtr->right + 1.0; - } else { /* Right */ + } + else { /* Right */ xin = regionPtr->right + 1.0; xout = regionPtr->left; } if (dy > 0.0) { /* Top */ yin = regionPtr->top; yout = regionPtr->bottom + 1.0; - } else { /* Bottom */ + } + else { /* Bottom */ yin = regionPtr->bottom + 1.0; yout = regionPtr->top; } @@ -202,7 +196,8 @@ int Blt::polyRectClip(Region2d *regionPtr, Point2d *points, int nPoints, if (tinx < tiny) { /* Hits x first */ tin1 = tinx; tin2 = tiny; - } else { /* Hits y first */ + } + else { /* Hits y first */ tin1 = tiny; tin2 = tinx; } @@ -212,11 +207,9 @@ int Blt::polyRectClip(Region2d *regionPtr, Point2d *points, int nPoints, AddVertex(xin, yin); } if (tin2 <= 1.0) { - double toutx, touty, tout1; - - toutx = (xout - p->x) / dx; - touty = (yout - p->y) / dy; - tout1 = MIN(toutx, touty); + double toutx = (xout - p->x) / dx; + double touty = (yout - p->y) / dy; + double tout1 = MIN(toutx, touty); if ((tin2 > 0.0) || (tout1 > 0.0)) { if (tin2 <= tout1) { diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C index b93b82d..9261f3a 100644 --- a/src/bltGrPSOutput.C +++ b/src/bltGrPSOutput.C @@ -130,9 +130,7 @@ void PSOutput::printSegments(Segment2d* segments, int nSegments) { append("newpath\n"); - Segment2d* sp; - Segment2d* send; - for (sp = segments, send = sp + nSegments; sp < send; sp++) { + for (Segment2d *sp = segments, *send = sp + nSegments; sp < send; sp++) { format(" %g %g moveto %g %g lineto\n", sp->p.x, sp->p.y, sp->q.x, sp->q.y); append("DashesProc stroke\n"); } @@ -238,8 +236,7 @@ void PSOutput::fillRectangle(double x, double y, int width, int height) void PSOutput::fillRectangles(XRectangle* rectangles, int nRectangles) { - XRectangle *rp, *rend; - for (rp = rectangles, rend = rp + nRectangles; rp < rend; rp++) + for (XRectangle *rp = rectangles, *rend = rp + nRectangles; rp < rend; rp++) fillRectangle((double)rp->x, (double)rp->y, (int)rp->width,(int)rp->height); } diff --git a/src/bltGraphBar.C b/src/bltGraphBar.C index 429187a..ed72e3d 100644 --- a/src/bltGraphBar.C +++ b/src/bltGraphBar.C @@ -349,8 +349,7 @@ void BarGraph::initBarSets() nSegs++; if (ops->coords.x) { int nPoints = ops->coords.x->nValues(); - double *x, *xend; - for (x = ops->coords.x->values_, xend = x + nPoints; x < xend; x++) { + for (double *x=ops->coords.x->values_, *xend=x+nPoints; x<xend; x++) { BarSetKey key; key.value =*x; key.xAxis =ops->xAxis; @@ -455,8 +454,7 @@ void BarGraph::destroyBarSets() void BarGraph::resetBarSets() { - BarGroup *gp, *gend; - for (gp = barGroups_, gend = gp + nBarGroups_; gp < gend; gp++) { + for (BarGroup *gp = barGroups_, *gend = gp + nBarGroups_; gp < gend; gp++) { gp->lastY = 0.0; gp->count = 0; } @@ -470,8 +468,7 @@ void BarGraph::computeBarStacks() return; // Initialize the stack sums to zero - BarGroup *gp, *gend; - for (gp = barGroups_, gend = gp + nBarGroups_; gp < gend; gp++) + for (BarGroup *gp = barGroups_, *gend = gp + nBarGroups_; gp < gend; gp++) gp->sum = 0.0; // Consider each bar x-y coordinate. Add the ordinates of duplicate @@ -485,9 +482,8 @@ void BarGraph::computeBarStacks() continue; if (ops->coords.x && ops->coords.y) { - double *x, *y, *xend; - for (x = ops->coords.x->values_, y = ops->coords.y->values_, - xend = x + ops->coords.x->nValues(); x < xend; x++, y++) { + for (double *x=ops->coords.x->values_, *y=ops->coords.y->values_, + *xend=x+ops->coords.x->nValues(); x<xend; x++, y++) { BarSetKey key; key.value =*x; key.xAxis =ops->xAxis; diff --git a/src/bltGraphSup.C b/src/bltGraphSup.C index 0072f7a..0213fb3 100644 --- a/src/bltGraphSup.C +++ b/src/bltGraphSup.C @@ -480,7 +480,7 @@ void Graph::getTextExtents(Tk_Font font, const char *text, int textLen, int lineLen =0; const char *line =NULL; const char *p, *pend; - for (p = line = text, pend = text + textLen; p < pend; p++) { + for (p =line=text, pend=text+textLen; p<pend; p++) { if (*p == '\n') { if (lineLen > 0) { int lineWidth = Tk_TextWidth(font, line, lineLen); diff --git a/src/bltOp.C b/src/bltOp.C index d52c133..aee1bff 100644 --- a/src/bltOp.C +++ b/src/bltOp.C @@ -71,9 +71,8 @@ static int LinearOpSearch(Blt_OpSpec *specs, int nSpecs, const char *string, char c = string[0]; int nMatches = 0; int last = -1; - int i; - Blt_OpSpec *specPtr; - for (specPtr = specs, i = 0; i < nSpecs; i++, specPtr++) { + int i =0; + for (Blt_OpSpec *specPtr = specs; i<nSpecs; i++, specPtr++) { if ((c == specPtr->name[0]) && (strncmp(string, specPtr->name, length) == 0)) { last = i; @@ -104,11 +103,9 @@ void* Blt::GetOpFromObj(Tcl_Interp* interp, int nSpecs, Blt_OpSpec *specs, usage: Tcl_AppendResult(interp, "should be one of...", (char *)NULL); for (n = 0; n < nSpecs; n++) { - int i; - Tcl_AppendResult(interp, "\n ", (char *)NULL); - for (i = 0; i < operPos; i++) { - Tcl_AppendResult(interp, Tcl_GetString(objv[i]), " ", + for (int ii = 0; ii < operPos; ii++) { + Tcl_AppendResult(interp, Tcl_GetString(objv[ii]), " ", (char *)NULL); } specPtr = specs + n; @@ -120,11 +117,11 @@ void* Blt::GetOpFromObj(Tcl_Interp* interp, int nSpecs, Blt_OpSpec *specs, int length; const char* string = Tcl_GetStringFromObj(objv[operPos], &length); - if (flags & BLT_OP_LINEAR_SEARCH) { + if (flags & BLT_OP_LINEAR_SEARCH) n = LinearOpSearch(specs, nSpecs, string, length); - } else { + else n = BinaryOpSearch(specs, nSpecs, string, length); - } + if (n == -2) { char c; diff --git a/src/bltSwitch.C b/src/bltSwitch.C index 291d232..e0fc3b2 100644 --- a/src/bltSwitch.C +++ b/src/bltSwitch.C @@ -87,11 +87,9 @@ static int Blt_GetCountFromObj(Tcl_Interp* interp, Tcl_Obj *objPtr, int check, static void DoHelp(Tcl_Interp* interp, Blt_SwitchSpec *specs) { Tcl_DString ds; - Blt_SwitchSpec *sp; - Tcl_DStringInit(&ds); Tcl_DStringAppend(&ds, "following switches are available:", -1); - for (sp = specs; sp->type != BLT_SWITCH_END; sp++) { + for (Blt_SwitchSpec *sp = specs; sp->type != BLT_SWITCH_END; sp++) { Tcl_DStringAppend(&ds, "\n ", 4); Tcl_DStringAppend(&ds, sp->switchName, -1); Tcl_DStringAppend(&ds, " ", 1); @@ -105,26 +103,21 @@ static Blt_SwitchSpec *FindSwitchSpec(Tcl_Interp* interp, Blt_SwitchSpec *specs, const char *name, int length, int needFlags, int hateFlags) { - Blt_SwitchSpec *sp; - char c; /* First character of current argument. */ - Blt_SwitchSpec *matchPtr; /* Matching spec, or NULL. */ - - c = name[1]; - matchPtr = NULL; - for (sp = specs; sp->type != BLT_SWITCH_END; sp++) { - if (sp->switchName == NULL) { + char c = name[1]; + Blt_SwitchSpec *matchPtr = NULL; + for (Blt_SwitchSpec *sp = specs; sp->type != BLT_SWITCH_END; sp++) { + if (sp->switchName == NULL) continue; - } - if (((sp->flags & needFlags) != needFlags) || (sp->flags & hateFlags)) { + + if (((sp->flags & needFlags) != needFlags) || (sp->flags & hateFlags)) continue; - } - if ((sp->switchName[1] != c) || - (strncmp(sp->switchName, name, length) != 0)) { + + if ((sp->switchName[1] != c) || (strncmp(sp->switchName,name,length)!=0)) continue; - } - if (sp->switchName[length] == '\0') { + + if (sp->switchName[length] == '\0') return sp; /* Stop on a perfect match. */ - } + if (matchPtr != NULL) { Tcl_AppendResult(interp, "ambiguous switch \"", name, "\"\n", (char *) NULL); @@ -133,16 +126,19 @@ static Blt_SwitchSpec *FindSwitchSpec(Tcl_Interp* interp, Blt_SwitchSpec *specs, } matchPtr = sp; } + if (strcmp(name, "-help") == 0) { DoHelp(interp, specs); return NULL; } + if (matchPtr == NULL) { Tcl_AppendResult(interp, "unknown switch \"", name, "\"\n", (char *)NULL); DoHelp(interp, specs); return NULL; } + return matchPtr; } diff --git a/src/bltVecCmd.C b/src/bltVecCmd.C index c81425a..b5a07ef 100644 --- a/src/bltVecCmd.C +++ b/src/bltVecCmd.C @@ -206,47 +206,38 @@ static int ObjToIndex(ClientData clientData, Tcl_Interp* interp, static Tcl_Obj* GetValues(Vector *vPtr, int first, int last) { - Tcl_Obj *listObjPtr; - double *vp, *vend; - - listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last; vp <= vend; - vp++) { - Tcl_ListObjAppendElement(vPtr->interp, listObjPtr, - Tcl_NewDoubleObj(*vp)); - } + Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); + for (double *vp=vPtr->valueArr+first, *vend=vPtr->valueArr+last; + vp <= vend; vp++) + Tcl_ListObjAppendElement(vPtr->interp, listObjPtr, Tcl_NewDoubleObj(*vp)); return listObjPtr; } static void ReplicateValue(Vector *vPtr, int first, int last, double value) { - double *vp, *vend; - - for (vp = vPtr->valueArr + first, vend = vPtr->valueArr + last; - vp <= vend; vp++) { + for (double *vp=vPtr->valueArr+first, *vend=vPtr->valueArr+last; + vp <= vend; vp++) *vp = value; - } + vPtr->notifyFlags |= UPDATE_RANGE; } static int CopyList(Vector *vPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]) { - int i; - - if (Vec_SetLength(interp, vPtr, objc) != TCL_OK) { + if (Vec_SetLength(interp, vPtr, objc) != TCL_OK) return TCL_ERROR; - } - for (i = 0; i < objc; i++) { - double value; - if (Blt_ExprDoubleFromObj(interp, objv[i], &value) != TCL_OK) { - Vec_SetLength(interp, vPtr, i); + for (int ii = 0; ii < objc; ii++) { + double value; + if (Blt_ExprDoubleFromObj(interp, objv[ii], &value) != TCL_OK) { + Vec_SetLength(interp, vPtr, ii); return TCL_ERROR; } - vPtr->valueArr[i] = value; + vPtr->valueArr[ii] = value; } + return TCL_OK; } diff --git a/src/bltVecMath.C b/src/bltVecMath.C index d978a26..bc2dc59 100644 --- a/src/bltVecMath.C +++ b/src/bltVecMath.C @@ -167,19 +167,15 @@ static int NextValue(Tcl_Interp* interp, ParseInfo *piPtr, int prec, static int Sort(Vector *vPtr) { - size_t *map; - double *values; - int i; + size_t* map = Vec_SortMap(&vPtr, 1); + double* values = (double*)malloc(sizeof(double) * vPtr->length); + for(int ii = vPtr->first; ii <= vPtr->last; ii++) + values[ii] = vPtr->valueArr[map[ii]]; - map = Vec_SortMap(&vPtr, 1); - values = (double*)malloc(sizeof(double) * vPtr->length); - for(i = vPtr->first; i <= vPtr->last; i++) { - values[i] = vPtr->valueArr[map[i]]; - } free(map); - for (i = vPtr->first; i <= vPtr->last; i++) { - vPtr->valueArr[i] = values[i]; - } + for (int ii = vPtr->first; ii <= vPtr->last; ii++) + vPtr->valueArr[ii] = values[ii]; + free(values); return TCL_OK; } @@ -218,38 +214,32 @@ static double Product(Blt_Vector *vectorPtr) static double Sum(Blt_Vector *vectorPtr) { - Vector *vPtr = (Vector *)vectorPtr; - double sum, c; - double *vp, *vend; - - /* Kahan summation algorithm */ + // Kahan summation algorithm - vp = vPtr->valueArr + vPtr->first; - sum = *vp++; - c = 0.0; /* A running compensation for lost + Vector *vPtr = (Vector *)vectorPtr; + double* vp = vPtr->valueArr + vPtr->first; + double sum = *vp++; + double c = 0.0; /* A running compensation for lost * low-order bits.*/ - for (vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { - double y, t; - - y = *vp - c; /* So far, so good: c is zero.*/ - t = sum + y; /* Alas, sum is big, y small, so + for (double* vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { + double y = *vp - c; /* So far, so good: c is zero.*/ + double t = sum + y; /* Alas, sum is big, y small, so * low-order digits of y are lost.*/ c = (t - sum) - y; /* (t - sum) recovers the high-order * part of y; subtracting y recovers * -(low part of y) */ sum = t; } + return sum; } static double Mean(Blt_Vector *vectorPtr) { Vector *vPtr = (Vector *)vectorPtr; - double sum; - int n; + double sum = Sum(vectorPtr); + int n = vPtr->last - vPtr->first + 1; - sum = Sum(vectorPtr); - n = vPtr->last - vPtr->first + 1; return sum / (double)n; } @@ -257,24 +247,19 @@ static double Mean(Blt_Vector *vectorPtr) static double Variance(Blt_Vector *vectorPtr) { Vector *vPtr = (Vector *)vectorPtr; - double var, mean; - double *vp, *vend; - int count; - - mean = Mean(vectorPtr); - var = 0.0; - count = 0; - for(vp = vPtr->valueArr + vPtr->first, - vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { - double dx; - - dx = *vp - mean; + double mean = Mean(vectorPtr); + double var = 0.0; + int count = 0; + for(double *vp=vPtr->valueArr+vPtr->first, *vend=vPtr->valueArr+vPtr->last; + vp <= vend; vp++) { + double dx = *vp - mean; var += dx * dx; count++; } - if (count < 2) { + + if (count < 2) return 0.0; - } + var /= (double)(count - 1); return var; } @@ -283,25 +268,23 @@ static double Variance(Blt_Vector *vectorPtr) static double Skew(Blt_Vector *vectorPtr) { Vector *vPtr = (Vector *)vectorPtr; - double diff, var, skew, mean, diffsq; - double *vp, *vend; - int count; - - mean = Mean(vectorPtr); - var = skew = 0.0; - count = 0; - for(vp = vPtr->valueArr + vPtr->first, - vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { - diff = *vp - mean; + double mean = Mean(vectorPtr); + double var = 0; + double skew = 0; + int count = 0; + for(double *vp=vPtr->valueArr+vPtr->first, *vend=vPtr->valueArr+vPtr->last; + vp <= vend; vp++) { + double diff = *vp - mean; diff = fabs(diff); - diffsq = diff * diff; + double diffsq = diff * diff; var += diffsq; skew += diffsq * diff; count++; } - if (count < 2) { + + if (count < 2) return 0.0; - } + var /= (double)(count - 1); skew /= count * var * sqrt(var); return skew; @@ -321,22 +304,19 @@ static double StdDeviation(Blt_Vector *vectorPtr) static double AvgDeviation(Blt_Vector *vectorPtr) { Vector *vPtr = (Vector *)vectorPtr; - double diff, avg, mean; - double *vp, *vend; - int count; - - mean = Mean(vectorPtr); - avg = 0.0; - count = 0; - for(vp = vPtr->valueArr + vPtr->first, - vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { - diff = *vp - mean; + double mean = Mean(vectorPtr); + double avg = 0.0; + int count = 0; + for(double *vp=vPtr->valueArr+vPtr->first, *vend=vPtr->valueArr+vPtr->last; + vp <= vend; vp++) { + double diff = *vp - mean; avg += fabs(diff); count++; } - if (count < 2) { + + if (count < 2) return 0.0; - } + avg /= (double)count; return avg; } @@ -344,28 +324,27 @@ static double AvgDeviation(Blt_Vector *vectorPtr) static double Kurtosis(Blt_Vector *vectorPtr) { Vector *vPtr = (Vector *)vectorPtr; - double diff, diffsq, kurt, var, mean; - double *vp, *vend; - int count; - - mean = Mean(vectorPtr); - var = kurt = 0.0; - count = 0; - for(vp = vPtr->valueArr + vPtr->first, - vend = vPtr->valueArr + vPtr->last; vp <= vend; vp++) { - diff = *vp - mean; - diffsq = diff * diff; + double mean = Mean(vectorPtr); + double var = 0; + double kurt = 0; + int count = 0; + for(double *vp=vPtr->valueArr+vPtr->first, *vend=vPtr->valueArr+vPtr->last; + vp <= vend; vp++) { + double diff = *vp - mean; + double diffsq = diff * diff; var += diffsq; kurt += diffsq * diffsq; count++; } - if (count < 2) { + + if (count < 2) return 0.0; - } + var /= (double)(count - 1); - if (var == 0.0) { + + if (var == 0.0) return 0.0; - } + kurt /= (count * var * var); return kurt - 3.0; /* Fisher Kurtosis */ } |