[gimp] app: add gimp_bezier_desc_translate() which translates all points



commit 8c3698eccc695640720712525479885051e84358
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 10 19:16:31 2011 +0200

    app: add gimp_bezier_desc_translate() which translates all points
    
    Also add back an internal "gboolean closed" parameter which I removed
    when copying the function, it might be useful later and doesn't hurt.

 app/core/gimpbezierdesc.c |   32 ++++++++++++++++++++++++++------
 app/core/gimpbezierdesc.h |    4 ++++
 2 files changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/app/core/gimpbezierdesc.c b/app/core/gimpbezierdesc.c
index 79850d5..572498f 100644
--- a/app/core/gimpbezierdesc.c
+++ b/app/core/gimpbezierdesc.c
@@ -63,7 +63,8 @@ gimp_bezier_desc_new (cairo_path_data_t *data,
 static void
 add_polyline (GArray            *path_data,
               const GimpVector2 *points,
-              guint              n_points)
+              gint               n_points,
+              gboolean           closed)
 {
   GimpVector2       prev = { 0.0, 0.0, };
   cairo_path_data_t pd;
@@ -90,11 +91,14 @@ add_polyline (GArray            *path_data,
         }
     }
 
-  /* close the polyline */
-  pd.header.type   = CAIRO_PATH_CLOSE_PATH;
-  pd.header.length = 1;
+  /* close the polyline when needed */
+  if (closed)
+    {
+      pd.header.type   = CAIRO_PATH_CLOSE_PATH;
+      pd.header.length = 1;
 
-  g_array_append_val (path_data, pd);
+      g_array_append_val (path_data, pd);
+    }
 }
 
 GimpBezierDesc *
@@ -142,7 +146,7 @@ gimp_bezier_desc_new_from_bound_segs (BoundSeg *bound_segs,
 
       n_points++;
 
-      add_polyline (path_data, points, n_points);
+      add_polyline (path_data, points, n_points, TRUE);
 
       n_points = 0;
       seg++;
@@ -159,6 +163,22 @@ gimp_bezier_desc_new_from_bound_segs (BoundSeg *bound_segs,
                                path_data->len);
 }
 
+void
+gimp_bezier_desc_translate (GimpBezierDesc *desc,
+                            gdouble         offset_x,
+                            gdouble         offset_y)
+{
+  gint i;
+
+  g_return_if_fail (desc != NULL);
+
+  for (i = 0; i < desc->num_data; i++)
+    {
+      desc->data[i].point.x += offset_x;
+      desc->data[i].point.y += offset_y;
+    }
+}
+
 GimpBezierDesc *
 gimp_bezier_desc_copy (const GimpBezierDesc *desc)
 {
diff --git a/app/core/gimpbezierdesc.h b/app/core/gimpbezierdesc.h
index 3acbc14..c046d4c 100644
--- a/app/core/gimpbezierdesc.h
+++ b/app/core/gimpbezierdesc.h
@@ -36,6 +36,10 @@ GimpBezierDesc * gimp_bezier_desc_new_from_bound_segs (BoundSeg             *bou
                                                        gint                  n_bound_segs,
                                                        gint                  n_bound_groups);
 
+void             gimp_bezier_desc_translate           (GimpBezierDesc       *desc,
+                                                       gdouble               offset_x,
+                                                       gdouble               offset_y);
+
 GimpBezierDesc * gimp_bezier_desc_copy                (const GimpBezierDesc *desc);
 void             gimp_bezier_desc_free                (GimpBezierDesc       *desc);
 



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