[gimp/soc-2010-cage-2] gimpcage: add a function that return the normal to an edge of the cage



commit 3715837edf062db1bf1dad38c83c5c3441ff0666
Author: Michael Muré <batolettre gmail com>
Date:   Wed Jul 14 23:53:52 2010 +0200

    gimpcage: add a function that return the normal to an edge of the cage

 app/core/gimpcage.c |   70 ++++++++++++++++++++++++++++++++-------------------
 app/core/gimpcage.h |   29 +++++++++++---------
 2 files changed, 60 insertions(+), 39 deletions(-)
---
diff --git a/app/core/gimpcage.c b/app/core/gimpcage.c
index d690574..c6d77ad 100644
--- a/app/core/gimpcage.c
+++ b/app/core/gimpcage.c
@@ -31,7 +31,7 @@ G_DEFINE_TYPE (GimpCage, gimp_cage, G_TYPE_OBJECT)
 
 #define N_ITEMS_PER_ALLOC       10
 
-static void       gimp_cage_finalize (GObject *object);
+static void       gimp_cage_finalize      (GObject *object);
 
 static void
 gimp_cage_class_init (GimpCageClass *klass)
@@ -87,6 +87,7 @@ gimp_cage_compute_coefficient (GimpCage *gc)
   
   g_return_if_fail (GIMP_IS_CAGE (gc));
   
+  
   format = babl_format_n(babl_type("float"), gc->cage_vertice_number);
 
   
@@ -169,40 +170,40 @@ gimp_cage_compute_coefficient (GimpCage *gc)
 }
   
 void
-gimp_cage_add_cage_point  (GimpCage    *cage,
+gimp_cage_add_cage_point  (GimpCage    *gc,
                            gdouble      x,
                            gdouble      y)
 {
-  g_return_if_fail (GIMP_IS_CAGE (cage));
+  g_return_if_fail (GIMP_IS_CAGE (gc));
   
-  if (cage->cage_vertice_number >= cage->cage_vertices_max)
+  if (gc->cage_vertice_number >= gc->cage_vertices_max)
   {
-    cage->cage_vertices_max += N_ITEMS_PER_ALLOC;
+    gc->cage_vertices_max += N_ITEMS_PER_ALLOC;
 
-    cage->cage_vertices = g_renew(GimpVector2,
-                                cage->cage_vertices,
-                                cage->cage_vertices_max);
+    gc->cage_vertices = g_renew(GimpVector2,
+                                gc->cage_vertices,
+                                gc->cage_vertices_max);
   }
 
-  cage->cage_vertices[cage->cage_vertice_number].x = x;
-  cage->cage_vertices[cage->cage_vertice_number].y = y;
+  gc->cage_vertices[gc->cage_vertice_number].x = x;
+  gc->cage_vertices[gc->cage_vertice_number].y = y;
 
-  cage->cage_vertice_number++;
+  gc->cage_vertice_number++;
 }
 
 void
-gimp_cage_remove_last_cage_point (GimpCage    *cage)
+gimp_cage_remove_last_cage_point (GimpCage    *gc)
 {
-  g_return_if_fail (GIMP_IS_CAGE (cage));
+  g_return_if_fail (GIMP_IS_CAGE (gc));
   
-  if (cage->cage_vertice_number >= 1)
-    cage->cage_vertice_number--;
+  if (gc->cage_vertice_number >= 1)
+    gc->cage_vertice_number--;
 }
 
 
 
 gint
-gimp_cage_is_on_handle  (GimpCage    *cage,
+gimp_cage_is_on_handle  (GimpCage    *gc,
                          gdouble      x,
                          gdouble      y,
                          gint         handle_size)
@@ -210,15 +211,15 @@ gimp_cage_is_on_handle  (GimpCage    *cage,
   gint i;
   gdouble vert_x, vert_y;
   
-  g_return_val_if_fail (GIMP_IS_CAGE (cage), -1);
+  g_return_val_if_fail (GIMP_IS_CAGE (gc), -1);
   
-  if (cage->cage_vertice_number == 0)
+  if (gc->cage_vertice_number == 0)
     return -1;
   
-  for (i = 0; i < cage->cage_vertice_number; i++)
+  for (i = 0; i < gc->cage_vertice_number; i++)
   {
-    vert_x = cage->cage_vertices[i].x;
-    vert_y = cage->cage_vertices[i].y;
+    vert_x = gc->cage_vertices[i].x;
+    vert_y = gc->cage_vertices[i].y;
     
     if (x < vert_x + handle_size / 2 && x > vert_x -handle_size / 2 &&
         y < vert_y + handle_size / 2 && y > vert_y -handle_size / 2)
@@ -231,14 +232,31 @@ gimp_cage_is_on_handle  (GimpCage    *cage,
 }
 
 void
-gimp_cage_move_cage_point  (GimpCage    *cage,
+gimp_cage_move_cage_point  (GimpCage    *gc,
                             gint         point_number,
                             gdouble      x,
                             gdouble      y)
 {
-  g_return_if_fail (GIMP_IS_CAGE (cage));
-  g_return_if_fail (point_number < cage->cage_vertice_number);
+  g_return_if_fail (GIMP_IS_CAGE (gc));
+  g_return_if_fail (point_number < gc->cage_vertice_number);
+  
+  gc->cage_vertices[point_number].x = x;
+  gc->cage_vertices[point_number].y = y;
+}
+
+GimpVector2
+gimp_cage_get_edge_normal  (GimpCage *gc,
+                            gint      edge_index)
+{
+  GimpVector2 result;
+  
+  g_return_val_if_fail (GIMP_IS_CAGE (gc), gimp_vector2_new(1,0));
+  g_return_val_if_fail (edge_index >= 0, gimp_vector2_new(1,0));
+  g_return_val_if_fail (edge_index < gc->cage_vertice_number, gimp_vector2_new(1,0));
+  
+  gimp_vector2_sub (&result,
+                    &gc->cage_vertices[(edge_index+1) % gc->cage_vertice_number],
+                    &gc->cage_vertices[edge_index]);
   
-  cage->cage_vertices[point_number].x = x;
-  cage->cage_vertices[point_number].y = y;
+  return gimp_vector2_normal (&result);
 }
\ No newline at end of file
diff --git a/app/core/gimpcage.h b/app/core/gimpcage.h
index 00b6763..e0f7de6 100644
--- a/app/core/gimpcage.h
+++ b/app/core/gimpcage.h
@@ -68,22 +68,25 @@ GType         gimp_cage_get_type          (void) G_GNUC_CONST;
  * 
  * Add a new point in the polygon of the cage, and make allocation if needed.
  */
-void      gimp_cage_add_cage_point         (GimpCage    *cage,
-                                            gdouble      x,
-                                            gdouble      y);
+void        gimp_cage_add_cage_point         (GimpCage    *cage,
+                                              gdouble      x,
+                                              gdouble      y);
                            
-void      gimp_cage_remove_last_cage_point (GimpCage    *cage);
+void        gimp_cage_remove_last_cage_point (GimpCage    *cage);
 
-gint      gimp_cage_is_on_handle           (GimpCage    *cage,
-                                            gdouble      x,
-                                            gdouble      y,
-                                            gint         handle_size);
+gint        gimp_cage_is_on_handle           (GimpCage    *cage,
+                                              gdouble      x,
+                                              gdouble      y,
+                                              gint         handle_size);
                                             
-void      gimp_cage_move_cage_point        (GimpCage    *cage,
-                                            gint         point_number,
-                                            gdouble      x,
-                                            gdouble      y);
+void        gimp_cage_move_cage_point        (GimpCage    *cage,
+                                              gint         point_number,
+                                              gdouble      x,
+                                              gdouble      y);
 
-void      gimp_cage_compute_coefficient    (GimpCage *gc);
+void        gimp_cage_compute_coefficient    (GimpCage *gc);
+
+GimpVector2 gimp_cage_get_edge_normal        (GimpCage *gc,
+                                              gint      edge_index);
 
 #endif /* __GIMP_CAGE_H__ */



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