Parcourir la source

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

Baptiste Jonglez il y a 6 ans
Parent
commit
d5d743fbc3
1 fichiers modifiés avec 2 ajouts et 0 suppressions
  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: