Commit d5d743fb authored by Baptiste Jonglez's avatar Baptiste Jonglez

Avoid math errors in some corner cases (because of float rounding)

parent b3de9cd9
......@@ -102,6 +102,8 @@ class Point(models.Model):
d = self.line_distance(other)
sin_elev = (other.altitude_abs ** 2 - self.altitude_abs ** 2 - d ** 2) \
/ (2 * self.altitude_abs * d)
# Ensure the value belongs to [-1, 1], which might not be the case because of float rouding
sin_elev = max(min(sin_elev, 1), -1)
return degrees(asin(sin_elev))
class Meta:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment