[Marble-commits] KDE/kdeedu/marble/src/lib
Bastian Holst
bastianholst at gmx.de
Mon Aug 10 22:12:13 CEST 2009
SVN commit 1009765 by bholst:
* Marbles GeoDataCoordinates now supports normalization of Degrees
* GeoPainterPrivate::createLinearRingFromGeoRect seems to be correct now.
M +7 -4 GeoPainter.cpp
M +75 -51 geodata/data/GeoDataCoordinates.cpp
M +8 -5 geodata/data/GeoDataCoordinates.h
--- trunk/KDE/kdeedu/marble/src/lib/GeoPainter.cpp #1009764:1009765
@@ -145,12 +145,15 @@
qreal altitude = centerCoordinates.altitude();
centerCoordinates.geoCoordinates( lon, lat, GeoDataCoordinates::Degree );
- qreal west = GeoDataCoordinates::normalizeLon( lon - width * 0.5 );
- qreal east = GeoDataCoordinates::normalizeLon( lon + width * 0.5 );
+ lon = GeoDataCoordinates::normalizeLon( lon );
+ lat = GeoDataCoordinates::normalizeLat( lat );
- qreal north = GeoDataCoordinates::normalizeLat( lat + height * 0.5 );
- qreal south = GeoDataCoordinates::normalizeLat( lat - height * 0.5 );
+ qreal west = GeoDataCoordinates::normalizeLon( lon - width * 0.5, GeoDataCoordinates::Degree );
+ qreal east = GeoDataCoordinates::normalizeLon( lon + width * 0.5, GeoDataCoordinates::Degree );
+ qreal north = GeoDataCoordinates::normalizeLat( lat + height * 0.5, GeoDataCoordinates::Degree );
+ qreal south = GeoDataCoordinates::normalizeLat( lat - height * 0.5, GeoDataCoordinates::Degree );
+
GeoDataCoordinates southWest( west, south,
altitude, GeoDataCoordinates::Degree );
GeoDataCoordinates southEast( east, south,
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataCoordinates.cpp #1009764:1009765
@@ -204,52 +204,68 @@
}
//static
-qreal GeoDataCoordinates::normalizeLon( qreal lon )
+qreal GeoDataCoordinates::normalizeLon( qreal lon, GeoDataCoordinates::Unit unit )
{
- if ( lon > +M_PI ) {
- int cycles = (int)( ( lon + M_PI ) / ( 2 * M_PI ) );
- return lon - ( cycles * 2 * M_PI );
+ qreal halfCircle;
+ if ( unit = GeoDataCoordinates::Radian ) {
+ halfCircle = M_PI;
+ }
+ else {
+ halfCircle = 180;
+ }
+
+ if ( lon > +halfCircle ) {
+ int cycles = (int)( ( lon + halfCircle ) / ( 2 * halfCircle ) );
+ return lon - ( cycles * 2 * halfCircle );
}
- if ( lon < -M_PI ) {
- int cycles = (int)( ( lon - M_PI ) / ( 2 * M_PI ) );
- return lon - ( cycles * 2 * M_PI );
+ if ( lon < -halfCircle ) {
+ int cycles = (int)( ( lon - halfCircle ) / ( 2 * halfCircle ) );
+ return lon - ( cycles * 2 * halfCircle );
}
return lon;
}
//static
-qreal GeoDataCoordinates::normalizeLat( qreal lat )
+qreal GeoDataCoordinates::normalizeLat( qreal lat, GeoDataCoordinates::Unit unit )
{
- if ( lat > ( +M_PI / 2.0 ) ) {
- int cycles = (int)( ( lat + M_PI ) / ( 2 * M_PI ) );
+ qreal halfCircle;
+ if ( unit = GeoDataCoordinates::Radian ) {
+ halfCircle = M_PI;
+ }
+ else {
+ halfCircle = 180;
+ }
+
+ if ( lat > ( halfCircle / 2.0 ) ) {
+ int cycles = (int)( ( lat + halfCircle ) / ( 2 * halfCircle ) );
qreal temp;
if( cycles == 0 ) { // pi/2 < lat < pi
- temp = M_PI - lat;
+ temp = halfCircle - lat;
} else {
- temp = lat - ( cycles * 2 * M_PI );
+ temp = lat - ( cycles * 2 * halfCircle );
}
- if ( temp > ( +M_PI / 2.0 ) ) {
- return ( +M_PI - temp );
+ if ( temp > ( halfCircle / 2.0 ) ) {
+ return ( halfCircle - temp );
}
- if ( temp < ( -M_PI / 2.0 ) ) {
- return ( -M_PI - temp );
+ if ( temp < ( -halfCircle / 2.0 ) ) {
+ return ( -halfCircle - temp );
}
return temp;
}
- if ( lat < ( -M_PI / 2.0 ) ) {
- int cycles = (int)( ( lat - M_PI ) / ( 2 * M_PI ) );
+ if ( lat < ( -halfCircle / 2.0 ) ) {
+ int cycles = (int)( ( lat - halfCircle ) / ( 2 * halfCircle ) );
qreal temp;
if( cycles == 0 ) {
- temp = -M_PI - lat;
+ temp = -halfCircle - lat;
} else {
- temp = lat - ( cycles * 2 * M_PI );
+ temp = lat - ( cycles * 2 * halfCircle );
}
- if ( temp > ( +M_PI / 2.0 ) ) {
- return ( +M_PI - temp );
+ if ( temp > ( +halfCircle / 2.0 ) ) {
+ return ( +halfCircle - temp );
}
- if ( temp < ( -M_PI / 2.0 ) ) {
- return ( -M_PI - temp );
+ if ( temp < ( -halfCircle / 2.0 ) ) {
+ return ( -halfCircle - temp );
}
return temp;
}
@@ -257,57 +273,65 @@
}
//static
-void GeoDataCoordinates::normalizeLonLat( qreal &lon, qreal &lat )
+void GeoDataCoordinates::normalizeLonLat( qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit )
{
- if ( lon > +M_PI ) {
- int cycles = (int)( ( lon + M_PI ) / ( 2 * M_PI ) );
- lon = lon - ( cycles * 2 * M_PI );
+ qreal halfCircle;
+ if ( unit = GeoDataCoordinates::Radian ) {
+ halfCircle = M_PI;
+ }
+ else {
+ halfCircle = 180;
+ }
+
+ if ( lon > +halfCircle ) {
+ int cycles = (int)( ( lon + halfCircle ) / ( 2 * halfCircle ) );
+ lon = lon - ( cycles * 2 * halfCircle );
}
- if ( lon < -M_PI ) {
- int cycles = (int)( ( lon - M_PI ) / ( 2 * M_PI ) );
- lon = lon - ( cycles * 2 * M_PI );
+ if ( lon < -halfCircle ) {
+ int cycles = (int)( ( lon - halfCircle ) / ( 2 * halfCircle ) );
+ lon = lon - ( cycles * 2 * halfCircle );
}
- if ( lat > ( +M_PI / 2.0 ) ) {
- int cycles = (int)( ( lat + M_PI ) / ( 2 * M_PI ) );
+ if ( lat > ( +halfCircle / 2.0 ) ) {
+ int cycles = (int)( ( lat + halfCircle ) / ( 2 * halfCircle ) );
qreal temp;
if( cycles == 0 ) { // pi/2 < lat < pi
- temp = M_PI - lat;
+ temp = halfCircle - lat;
} else {
- temp = lat - ( cycles * 2 * M_PI );
+ temp = lat - ( cycles * 2 * halfCircle );
}
- if ( temp > ( +M_PI / 2.0 ) ) {
- lat = +M_PI - temp;
+ if ( temp > ( +halfCircle / 2.0 ) ) {
+ lat = +halfCircle - temp;
}
- if ( temp < ( -M_PI / 2.0 ) ) {
- lat = -M_PI - temp;
+ if ( temp < ( -halfCircle / 2.0 ) ) {
+ lat = -halfCircle - temp;
}
lat = temp;
if( lon > 0 ) {
- lon = -M_PI + lon;
+ lon = -halfCircle + lon;
} else {
- lon = M_PI + lon;
+ lon = halfCircle + lon;
}
}
- if ( lat < ( -M_PI / 2.0 ) ) {
- int cycles = (int)( ( lat - M_PI ) / ( 2 * M_PI ) );
+ if ( lat < ( -halfCircle / 2.0 ) ) {
+ int cycles = (int)( ( lat - halfCircle ) / ( 2 * halfCircle ) );
qreal temp;
if( cycles == 0 ) {
- temp = -M_PI - lat;
+ temp = -halfCircle - lat;
} else {
- temp = lat - ( cycles * 2 * M_PI );
+ temp = lat - ( cycles * 2 * halfCircle );
}
- if ( temp > ( +M_PI / 2.0 ) ) {
- lat = +M_PI - temp;
+ if ( temp > ( +halfCircle / 2.0 ) ) {
+ lat = +halfCircle - temp;
}
- if ( temp < ( -M_PI / 2.0 ) ) {
- lat = -M_PI - temp;
+ if ( temp < ( -halfCircle / 2.0 ) ) {
+ lat = -halfCircle - temp;
}
lat = temp;
if( lon > 0 ) {
- lon = -M_PI + lon;
+ lon = -halfCircle + lon;
} else {
- lon = M_PI + lon;
+ lon = halfCircle + lon;
}
}
return;
--- trunk/KDE/kdeedu/marble/src/lib/geodata/data/GeoDataCoordinates.h #1009764:1009765
@@ -218,16 +218,18 @@
static void setDefaultNotation( GeoDataCoordinates::Notation notation );
/**
- * @brief normalize the longitude to always be -M_PI <= lon <= +M_PI
+ * @brief normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
* @param lon longitude
*/
- static qreal normalizeLon( qreal lon );
+ static qreal normalizeLon( qreal lon,
+ GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
/**
- * @brief normalize latitude to always be in -M_PI / 2. <= lat <= +M_PI / 2.
+ * @brief normalize latitude to always be in -M_PI / 2. <= lat <= +M_PI / 2 (Radian).
* @param lat latitude
*/
- static qreal normalizeLat( qreal lat );
+ static qreal normalizeLat( qreal lat,
+ GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
/**
* @brief normalize both longitude and latitude at the same time
@@ -242,7 +244,8 @@
* @param lon the longitude value
* @param lat the latitude value
*/
- static void normalizeLonLat( qreal &lon, qreal &lat );
+ static void normalizeLonLat( qreal &lon, qreal &lat,
+ GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
/**
* @brief try to parse the string into a coordinate pair
More information about the Marble-commits
mailing list