void CoordsArg::addCoord( int32 lat, int32 lon, TileMap& tileMap ) { if ( m_startCoordIdx == MAX_UINT32 ) { m_allCoords = &tileMap.coordsRef(); m_startCoordIdx = m_allCoords->size(); m_endCoordIdx = m_allCoords->size(); } TileMapCoord coord( lat, lon ); // Snap the coordinate to a pixel in the tile map. tileMap.snapCoordToPixel( coord ); // Check that we're not adding duplicate coordinates. if ( size() > 0 ) { const TileMapCoord& lastCoord = back(); if ( lastCoord != coord ) { // Not duplicated. Add. push_back( coord ); } } else { // First coordinate. Add. push_back( coord ); } }
bool CoordsArg::load( BitBuffer& buf, TileMap& tileMap, const TileFeatureArg* prevArg ) { const TileMapCoord* referenceCoord = &(tileMap.getReferenceCoord()); // Check if the previous coords last coordinate can be used as // reference. if ( prevArg != NULL ) { // Use previous feature's last coordinate as reference. const CoordsArg* prevCoordsArg = static_cast<const CoordsArg*> ( prevArg ); MC2_ASSERT( prevCoordsArg->size() > 0 ); #ifndef SLIM_TILE_COORDS referenceCoord = &(prevCoordsArg->back()); #else referenceCoord = &(prevCoordsArg->back(tileMap)); #endif } // Write the number of coordinates. int nbrBitsCoordSize = buf.readNextBits( 4 ); uint16 nbrCoords = buf.readNextBits( nbrBitsCoordSize ); if ( nbrCoords == 0 ) { return true; } mc2dbg8 << "CoordsArg::load" << endl; mc2dbg8 << "referenceCoord = " << referenceCoord->getLon() << ", " << referenceCoord->getLat() << ", mc2scale = " << tileMap.getMC2Scale() << endl; // Nbr bits needed for start diff. int nbrStartDiffBits = buf.readNextBits( 4 ); // Read startLatDiff. int16 startLatDiff = buf.readNextSignedBits( nbrStartDiffBits ); // Read startLonDiff. int16 startLonDiff = buf.readNextSignedBits( nbrStartDiffBits ); mc2dbg8 << "nbrStartDiffBits = " << nbrStartDiffBits << endl; mc2dbg8 << " startLatDiff = " << startLatDiff << ", startLonDiff = " << startLonDiff << endl; // Read bitsPerLatDiff. int bitsPerLatDiff = buf.readNextBits( 4 ); // Read bitsPerLonDiff. int bitsPerLonDiff = buf.readNextBits( 4 ); // Set the coordinates TileMapCoords* allCoords = &(tileMap.coordsRef()); m_startCoordIdx = allCoords->size(); m_endCoordIdx = allCoords->size() + nbrCoords; // Calculate the starting coordinate. int32 prevLat = startLatDiff * tileMap.getMC2Scale() + referenceCoord->getLat(); int32 prevLon = startLonDiff * tileMap.getMC2Scale() + referenceCoord->getLon(); allCoords->push_back( TileMapCoord( prevLat, prevLon ) ); // Read the rest of the coords. for ( int i = 1; i < nbrCoords; ++i ) { // Lat int16 latDiff = buf.readNextSignedBits( bitsPerLatDiff ); int32 curLat = latDiff * tileMap.getMC2Scale() + prevLat; // Lon int16 lonDiff = buf.readNextSignedBits( bitsPerLonDiff ); int32 curLon = lonDiff * tileMap.getMC2Scale() + prevLon; mc2dbg8 << "diff " << latDiff << ", " << lonDiff << endl; mc2dbg8 << "coord " << curLat << ", " << curLon << endl; // Update prev coordinates. prevLat = curLat; prevLon = curLon; // Set the coord. allCoords->push_back( TileMapCoord( curLat, curLon ) ); } // Oopendate de bundingboex. for( uint32 h = m_startCoordIdx; h < m_endCoordIdx; ++h ) { m_bbox.update( (*allCoords)[h].getLat(), (*allCoords)[h].getLon(), false ); } #ifndef SLIM_TILE_COORDS m_allCoords = allCoords; #endif return true; }
TileMapCoords::const_iterator CoordsArg::end( TileMap& tileMap ) const { return tileMap.coordsRef().begin() + m_endCoordIdx; }
TileMapCoords::iterator CoordsArg::begin( TileMap& tileMap ) { return tileMap.coordsRef().begin() + m_startCoordIdx; }