[pango/pango2-windows: 309/311] pango-matrix.c: Improvise tolerance in acos() on Visual Studio




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

    pango-matrix.c: Improvise tolerance in acos() on Visual Studio
    
    We might have not have rounded the input of acos() to be 1 or -1 when it
    is only marginally larger than 1 or marginally less than -1, so we do
    our tolerance handling ourselves, for Visual Studio builds, since its
    acos() call do not have tolerance for input values greater than 1.0
    nor for input values less than -1.0.

 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 78aacae6d..cc76d644c 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]