[gegl] matrix: add gegl_matrix_round_error()



commit ddbeefcd2f613b7d82bbf68c60394396b22d4343
Author: Ell <ell_se yahoo com>
Date:   Thu Jul 9 09:54:25 2020 +0300

    matrix: add gegl_matrix_round_error()
    
    ... which rounds numerical errors in the matrix's coefficients to
    the nearest integer.

 gegl/gegl-matrix.c | 20 ++++++++++++++++++++
 gegl/gegl-matrix.h |  8 ++++++++
 2 files changed, 28 insertions(+)
---
diff --git a/gegl/gegl-matrix.c b/gegl/gegl-matrix.c
index c089db737..524fb66c9 100644
--- a/gegl/gegl-matrix.c
+++ b/gegl/gegl-matrix.c
@@ -72,6 +72,26 @@ gegl_matrix3_identity (GeglMatrix3 *matrix)
   matrix->coeff [2][0] = matrix->coeff [2][1] = 0.;
 }
 
+void
+gegl_matrix3_round_error (GeglMatrix3 *matrix)
+{
+  gint r;
+
+  for (r = 0; r < 3; r++)
+    {
+      gint c;
+
+      for (c = 0; c < 3; c++)
+        {
+          gdouble x = matrix->coeff[r][c];
+          gdouble i = floor (x + 0.5);
+
+          if (fabs (x - i) < EPSILON)
+            matrix->coeff[r][c] = i;
+        }
+    }
+}
+
 gboolean
 gegl_matrix3_equal (GeglMatrix3 *matrix1,
                     GeglMatrix3 *matrix2)
diff --git a/gegl/gegl-matrix.h b/gegl/gegl-matrix.h
index 92d279b02..8f739eda3 100644
--- a/gegl/gegl-matrix.h
+++ b/gegl/gegl-matrix.h
@@ -64,6 +64,14 @@ GeglMatrix3 * gegl_matrix3_new (void);
  */
 void       gegl_matrix3_identity        (GeglMatrix3 *matrix);
 
+/**
+ * gegl_matrix3_round_error:
+ * @matrix: a #GeglMatrix3
+ *
+ * Rounds numerical errors in @matrix to the nearest integer.
+ */
+void       gegl_matrix3_round_error     (GeglMatrix3 *matrix);
+
 /**
  * gegl_matrix3_equal:
  * @matrix1: a #GeglMatrix3


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