Merge pull request #3319 from PeterDuerr/fix_map_projection_project

Avoid violation of acos' domain in map_projection
This commit is contained in:
Lorenz Meier
2015-12-04 10:31:22 +01:00
+10 -1
View File
@@ -148,7 +148,16 @@ __EXPORT int map_projection_project(const struct map_projection_reference_s *ref
double cos_lat = cos(lat_rad);
double cos_d_lon = cos(lon_rad - ref->lon_rad);
double c = acos(ref->sin_lat * sin_lat + ref->cos_lat * cos_lat * cos_d_lon);
double arg = ref->sin_lat * sin_lat + ref->cos_lat * cos_lat * cos_d_lon;
if (arg > 1.0) {
arg = 1.0;
} else if (arg < -1.0) {
arg = -1.0;
}
double c = acos(arg);
double k = (fabs(c) < DBL_EPSILON) ? 1.0 : (c / sin(c));
*x = k * (ref->cos_lat * sin_lat - ref->sin_lat * cos_lat * cos_d_lon) * CONSTANTS_RADIUS_OF_EARTH;