/** Convert a string to a double with a given unit @return 1 on success, 0 on failure **/ extern "C" int convert_unit_double(char *buffer,char *unit, double *data) { char *from = strchr(buffer,' '); *data = atof(buffer); if (from==NULL) return 1; /* no conversion needed */ /* skip white space in from of unit */ while (isspace(*from)) from++; return unit_convert(from,unit,data); }
void CostCalculator::addObstacleCostPenalty( LabelPosition* lp, PointSet* feat ) { int n = 0; double dist; double distlabel = lp->feature->getLabelDistance(); #if 0 unit_convert( double( lp->feature->distlabel ), pal::PIXEL, pal->map_unit, pal->dpi, scale, 1 ); #endif switch ( feat->getGeosType() ) { case GEOS_POINT: dist = lp->getDistanceToPoint( feat->x[0], feat->y[0] ); if ( dist < 0 ) n = 2; else if ( dist < distlabel ) n = 1; else n = 0; break; case GEOS_LINESTRING: // Is one of label's borders crossing the line ? n = ( lp->isBorderCrossingLine( feat ) ? 1 : 0 ); break; case GEOS_POLYGON: n = lp->getNumPointsInPolygon( feat->getNumPoints(), feat->x, feat->y ); break; } // label cost is penalized lp->setCost( lp->getCost() + double( n ) ); }
double operator()(const double value) const { return unit_convert (from, to, value); }