[pango/pango2-windows] pango-matrix.c: Have some tolerance in acos() call



commit f6546bc1f389395bab164fb7e01830f35d36901d
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Jun 17 15:41:31 2022 +0800

    pango-matrix.c: Have some tolerance in acos() call
    
    Visual Studio's acos() call do not have tolerance for input values
    greater than 1.0 nor for input values less than -1.0, so we improvise
    our own in this situation.

 pango/pango-matrix.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c
index 78aacae6..cc76d644 100644
--- a/pango/pango-matrix.c
+++ b/pango/pango-matrix.c
@@ -263,13 +263,33 @@ double
 pango_matrix_get_rotation (const PangoMatrix *matrix)
 {
   double x, y;
+  double acos_input;
 
   x = 1;
   y = 0;
 
   pango_matrix_transform_distance (matrix, &x, &y);
+  acos_input = x /  sqrtf (x*x + y*y);
 
-  return RAD_TO_DEG (acos (x /  sqrtf (x*x + y*y)));
+#ifdef _MSC_VER
+  /* Visual Studio's acos() does not have tolerance for any value > 1.0 or < -1.0 */
+# define ACOS_TOLERANCE 0.001
+
+  if (acos_input > 1)
+    {
+      if (fabs (acos_input - 1.0) <= ACOS_TOLERANCE)
+        acos_input = 1;
+    }
+  if (acos_input < -1)
+    {
+      if (fabs (acos_input + 1.0) >= -ACOS_TOLERANCE)
+        acos_input = -1;
+    }
+
+# undef ACOS_TOLERANCE
+#endif
+
+  return RAD_TO_DEG (acos (acos_input));
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]