[pango/pango2-windows: 16/17] pango-matrix.c: Improvise tolerance in acos() on Visual Studio
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2-windows: 16/17] pango-matrix.c: Improvise tolerance in acos() on Visual Studio
- Date: Mon, 20 Jun 2022 02:48:53 +0000 (UTC)
commit 9f67cea664d4db7739bf6a28ebfe4cd2714636fc
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 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]