Browse Source

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

Baptiste Jonglez 6 years ago
parent
commit
d5d743fbc3
1 changed files with 2 additions and 0 deletions
  1. 2 0
      panorama/models.py

+ 2 - 0
panorama/models.py

@@ -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: