[gegl/soc-2013-n-point-deformation: 10/28] libs: npd: update 'add control point' function



commit 85bd2baf471c7121aec4cced193ca604f15feff7
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Wed Aug 7 18:56:57 2013 +0200

    libs: npd: update 'add control point' function
    
    Return NULL when there already is a control point at the position of nearest overlapping points.

 libs/npd/npd_common.c |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/libs/npd/npd_common.c b/libs/npd/npd_common.c
index 0f1ad97..ee52825 100644
--- a/libs/npd/npd_common.c
+++ b/libs/npd/npd_common.c
@@ -80,6 +80,16 @@ npd_destroy_model (NPDModel *model)
   g_free (model->hidden_model);
 }
 
+/**
+ * Finds nearest (to specified position) overlapping points, creates a new
+ * control point at the position of overlapping points and assigns them to the
+ * control point.
+ * 
+ * @param  model
+ * @param  coord     specified position
+ * @return pointer to a newly created control point or NULL when there already
+ * is a control point at the position of nearest overlapping points
+ */
 NPDControlPoint*
 npd_add_control_point (NPDModel *model,
                        NPDPoint *coord)
@@ -88,6 +98,7 @@ npd_add_control_point (NPDModel *model,
   gfloat                min, current;
   NPDOverlappingPoints *list_of_ops;
   NPDControlPoint       cp;
+  NPDPoint             *closest_point;
 
   list_of_ops = model->hidden_model->list_of_overlapping_points;
   num_of_ops  = model->hidden_model->num_of_overlapping_points;
@@ -108,15 +119,26 @@ npd_add_control_point (NPDModel *model,
         }
     }
 
-  cp.point.weight       = list_of_ops[closest].representative->weight;
-  cp.overlapping_points = &list_of_ops[closest];
-  
-  npd_set_point_coordinates (&cp.point, list_of_ops[closest].representative);
-  g_array_append_val (model->control_points, cp);
+  closest_point = list_of_ops[closest].representative;
+
+  /* we want to create a new control point only when there isn't any
+   * control point associated to the closest overlapping points - i.e. we
+   * don't want to have two (or more) different control points manipulating
+   * one overlapping points */
+  if (!npd_get_control_point_at (model, closest_point))
+    {
+      cp.point.weight       = closest_point->weight;
+      cp.overlapping_points = &list_of_ops[closest];
 
-  return &g_array_index (model->control_points,
-                         NPDControlPoint,
-                         model->control_points->len - 1);
+      npd_set_point_coordinates (&cp.point, closest_point);
+      g_array_append_val (model->control_points, cp);
+
+      return &g_array_index (model->control_points,
+                             NPDControlPoint,
+                             model->control_points->len - 1);
+    }
+  else
+    return NULL;
 }
 
 void


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