fix invalid circle centers

This commit is contained in:
Moritz Kobitzsch 2016-06-24 12:29:53 +02:00 committed by Patrick Niklaus
parent 61ba985bc9
commit e03d132823
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B
2 changed files with 11 additions and 1 deletions

View File

@ -258,7 +258,10 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
C2C1_slope * (C2_x + C3_x)) /
(2 * (C3C2_slope - C2C1_slope));
const double lat = (0.5 * (C1_x + C2_x) - lon) / C2C1_slope + 0.5 * (C1_y + C2_y);
return Coordinate(FloatLongitude(lon), FloatLatitude(lat));
if (lon < -180.0 || lon > 180.0 || lat < -90.0 || lat > 90.0)
return boost::none;
else
return Coordinate(FloatLongitude(lon), FloatLatitude(lat));
}
}

View File

@ -302,6 +302,13 @@ BOOST_AUTO_TEST_CASE(circleCenter)
c = Coordinate(FloatLongitude(-112.096419), FloatLatitude(41.147259));
result = coordinate_calculation::circleCenter(a, b, c);
BOOST_CHECK(!result);
// Out of bounds
a = Coordinate(FloatLongitude(-112.096234), FloatLatitude(41.147258));
b = Coordinate(FloatLongitude(-112.106606), FloatLatitude(41.147259));
c = Coordinate(FloatLongitude(-113.096419), FloatLatitude(41.147258));
result = coordinate_calculation::circleCenter(a, b, c);
BOOST_CHECK(!result);
}
BOOST_AUTO_TEST_SUITE_END()