Beispiel #1
0
// This function expects an integer width, not a meters width
void Template::addVerticalLine( int fromX, int fromY, 
                                int destX, int destY, int width )
{
   int ySign;
   int x = fromX, y = fromY;

   if( destY > fromY )
      ySign = 1;
   else
      ySign = -1;

   while( ySign*y <= destY )
   {
      if( x > 0 && x < mnXSize && y > 0 && y < mnYSize )
      {
         // the slope is 2 so that it will be considered more
         // vertical than horizontal.
         addWidth( x, y, width, 2 );
      }
      y += ySign;
   }

   if( destX > 0 && destX < mnXSize && destY > 0 && destY < mnYSize )
   {
      addWidth( destX, destY, width, 2 );
   }

   return;
} // End Function addVerticalLine
TCHAR *StreamParameters::addPrefix(TCHAR *dst, bool withPrecision) const {
  *(dst++) = _T('%');
  dst = addModifier(dst);
  dst = addWidth(dst);
  if(withPrecision) {
    dst = addPrecision(dst);
  }
  return dst;
}
Beispiel #3
0
// Expects a width in meters
void Template::addSegment( const OGRPoint &from, const OGRPoint &dest, 
                           double width )
{
   int fromX, fromY, destX, destY;  // begin and end coordinates
   int x, y;                        // iterators
   int xSign, ySign, slopeSign;     // keep direction information
   double slopeCount;               // ghetto slope counter
   double slope;
   int iWidth = static_cast<int>( width * PIX_PER_METER );

   // Determine what direction the line is going.
   if( dest.getY() > from.getY() )
      ySign = 1;
   else
      ySign = -1;

   if( dest.getX() > from.getX() )
      xSign = 1;
   else
      xSign = -1;


   // Get starting and ending points in the raster coordinates.
   fromX = static_cast<int>(from.getX() - mdXTrans);
   fromY = static_cast<int>(from.getY() - mdYTrans);
   destX = static_cast<int>(dest.getX() - mdXTrans);
   destY = static_cast<int>(dest.getY() - mdYTrans);


   // Calculate the slope.  If the line is vertical then its 
   // slope is undefined so I need a different method.  For
   // that case I use the addVerticalLine function.
   if( dest.getX() - from.getX() != 0 )
   {
      slope = (dest.getY() - from.getY()) / 
              (dest.getX() - from.getX());
      if( slope >= 0 )
         slopeSign = 1;
      else
         slopeSign = -1;
   }
   else
   {
      addVerticalLine( fromX, fromY, destX, destY, iWidth );
      return;
   }


   // Start plotting the line
   x = fromX;
   y = fromY;
   if( x < mnXSize && x >= 0 && y < mnYSize && y >= 0 )
   {
      addWidth( x, y, iWidth, slope );
   }

   // Plot the line, basically this just counts out rise over
   // run like a fifth grader with some graph paper.
   slopeCount = 0;
   while( x != destX && y != destY )
   {
      if( slopeCount*slopeSign >= 1 )
      {
         y += ySign;
         if( x < mnXSize && y < mnYSize )
         {
            addWidth( x, y, iWidth, slope );
         }
         slopeCount -= slopeSign;
      }
      else
      {
         x += xSign;
         if( x < mnXSize && x >= 0 && y < mnYSize && y >= 0 )
         {
            addWidth( x, y, iWidth, slope );
         }
         slopeCount += slope;
      }
   }

   // make sure the end point didn't get skipped over
   if( destX < mnXSize && destX >= 0 && destY < mnYSize && destY >= 0 )
   {
      addWidth( destX, destY, iWidth, slope );
   }

   return;
} // End Function addSegment