bool ViewportParams::resolves ( const GeoDataCoordinates &coord1, const GeoDataCoordinates &coord2 ) const { qreal lon1, lat1; coord1.geoCoordinates( lon1, lat1 ); qreal lon2, lat2; coord2.geoCoordinates( lon2, lat2 ); // We take the manhattan length as an approximation for the distance return ( fabs( lon2 - lon1 ) + fabs( lat2 - lat1 ) < angularResolution() ); }
bool EquirectProjection::screenCoordinates( const GeoDataCoordinates &geopoint, const ViewportParams *viewport, qreal &x, qreal &y, bool &globeHidesPoint ) const { globeHidesPoint = false; // Convenience variables int radius = viewport->radius(); int width = viewport->width(); int height = viewport->height(); qreal lon; qreal lat; qreal rad2Pixel = 2.0 * viewport->radius() / M_PI; const qreal centerLon = viewport->centerLongitude(); const qreal centerLat = viewport->centerLatitude(); geopoint.geoCoordinates( lon, lat ); // Let (x, y) be the position on the screen of the geopoint. x = ((qreal)(viewport->width()) / 2.0 + rad2Pixel * (lon - centerLon)); y = ((qreal)(viewport->height()) / 2.0 - rad2Pixel * (lat - centerLat)); // Return true if the calculated point is inside the screen area, // otherwise return false. return ( ( 0 <= y && y < height ) && ( ( 0 <= x && x < width ) || ( 0 <= x - 4 * radius && x - 4 * radius < width ) || ( 0 <= x + 4 * radius && x + 4 * radius < width ) ) ); }
bool EquirectProjection::screenCoordinates( const GeoDataCoordinates &geopoint, const ViewportParams *viewport, qreal *x, qreal &y, int &pointRepeatNum, const QSizeF& size, bool &globeHidesPoint ) const { pointRepeatNum = 0; // On flat projections the observer's view onto the point won't be // obscured by the target planet itself. globeHidesPoint = false; // Convenience variables int radius = viewport->radius(); qreal width = (qreal)(viewport->width()); qreal height = (qreal)(viewport->height()); qreal lon; qreal lat; qreal rad2Pixel = 2.0 * radius / M_PI; const qreal centerLon = viewport->centerLongitude(); const qreal centerLat = viewport->centerLatitude(); geopoint.geoCoordinates( lon, lat ); // Let (itX, y) be the first guess for one possible position on screen. qreal itX = ( width / 2.0 + rad2Pixel * ( lon - centerLon ) ); y = ( height / 2.0 - rad2Pixel * ( lat - centerLat ) ); // Make sure that the requested point is within the visible y range: if ( 0 <= y + size.height() / 2.0 && y < height + size.height() / 2.0 ) { // First we deal with the case where the repetition doesn't happen if ( !repeatX() ) { *x = itX; if ( 0 < itX + size.width() / 2.0 && itX < width + size.width() / 2.0 ) { return true; } else { // the requested point is out of the visible x range: return false; } } // For the repetition case the same geopoint gets displayed on // the map many times.across the longitude. int xRepeatDistance = 4 * radius; // Finding the leftmost positive x value if ( itX + size.width() > xRepeatDistance ) { const int repeatNum = (int)( ( itX + size.width() ) / xRepeatDistance ); itX = itX - repeatNum * xRepeatDistance; } if ( itX + size.width() / 2.0 < 0 ) { itX += xRepeatDistance; } // The requested point is out of the visible x range: if ( itX > width + size.width() / 2.0 ) { return false; } // Now iterate through all visible x screen coordinates for the point // from left to right. int itNum = 0; while ( itX - size.width() / 2.0 < width ) { *x = itX; ++x; ++itNum; itX += xRepeatDistance; } pointRepeatNum = itNum; return true; } // The requested point is out of the visible y range. return false; }