[goffice] GOArrow: add go_arrow_equal.



commit c7fe709d8e508e036f4df20399669df9801d8f8f
Author: Morten Welinder <terra gnome org>
Date:   Mon Feb 16 14:48:23 2015 -0500

    GOArrow: add go_arrow_equal.

 ChangeLog                  |    7 +++++++
 goffice/gtk/go-arrow-sel.c |    8 +++-----
 goffice/utils/go-line.c    |   25 +++++++++++++++++++++++++
 goffice/utils/go-line.h    |    2 ++
 4 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 91f829f..9329d43 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-14  Morten Welinder  <terra gnome org>
+
+       * goffice/utils/go-line.c (go_arrow_equal): New function.
+
+       * goffice/gtk/go-arrow-sel.c (go_arrow_sel_set_arrow): Use
+       go_arrow_equal.
+
 2015-02-12  Morten Welinder  <terra gnome org>
 
        * goffice/utils/go-line.c: Use 0.0, not G_MINDOUBLE, to make cairo
diff --git a/goffice/gtk/go-arrow-sel.c b/goffice/gtk/go-arrow-sel.c
index 0a9e65d..b4b499a 100644
--- a/goffice/gtk/go-arrow-sel.c
+++ b/goffice/gtk/go-arrow-sel.c
@@ -238,12 +238,10 @@ void
 go_arrow_sel_set_arrow (GOArrowSel *as, GOArrow const *arrow)
 {
        g_return_if_fail (GO_IS_ARROW_SEL (as));
+       g_return_if_fail (arrow != NULL);
 
-       if (as->arrow.typ == arrow->typ &&
-           as->arrow.a == arrow->a &&
-           as->arrow.b == arrow->b &&
-           as->arrow.c == arrow->c)
-               return;     
+       if (go_arrow_equal (arrow, &as->arrow))
+               return;
 
        g_object_freeze_notify (G_OBJECT (as));
        as->arrow = *arrow;
diff --git a/goffice/utils/go-line.c b/goffice/utils/go-line.c
index 6dfa85d..cc99dc1 100644
--- a/goffice/utils/go-line.c
+++ b/goffice/utils/go-line.c
@@ -510,6 +510,31 @@ go_arrow_dup (GOArrow *src)
        return g_memdup (src, sizeof (*src));
 }
 
+gboolean
+go_arrow_equal (const GOArrow *a, const GOArrow *b)
+{
+       g_return_val_if_fail (a != NULL, FALSE);
+       g_return_val_if_fail (b != NULL, FALSE);
+
+       if (a->typ != b->typ)
+               return FALSE;
+
+       switch (a->typ) {
+       default:
+               g_assert_not_reached ();
+       case GO_ARROW_NONE:
+               return TRUE;
+
+       case GO_ARROW_KITE:
+               if (a->c != b->c)
+                       return FALSE;
+               /* fall through */
+       case GO_ARROW_OVAL:
+               return (a->a == b->a && a->b == b->b);
+       }
+}
+
+
 /**
  * go_arrow_draw:
  * @arrow: arrow to draw
diff --git a/goffice/utils/go-line.h b/goffice/utils/go-line.h
index f4c116d..f902c42 100644
--- a/goffice/utils/go-line.h
+++ b/goffice/utils/go-line.h
@@ -76,6 +76,8 @@ void go_arrow_clear (GOArrow *dst);
 void go_arrow_init_kite (GOArrow *dst, double a, double b, double c);
 void go_arrow_init_oval (GOArrow *dst, double ra, double rb);
 
+gboolean go_arrow_equal (const GOArrow *a, const GOArrow *b);
+
 void go_arrow_draw (const GOArrow *arrow, cairo_t *cr,
                    double *dx, double *dy, double phi);
 


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