diff options
author | Marek Dvoroznak <dvoromar@gmail.com> | 2013-08-07 18:56:57 +0200 |
---|---|---|
committer | Mikael Magnusson <mikachu@src.gnome.org> | 2015-02-27 18:36:48 +0100 |
commit | bc4ddf9ff2b8392568686c011814dc10cc8f5067 (patch) | |
tree | 887266aec172e2ff5ea549a25407f8bd1cf56214 /libs | |
parent | 2f19775355f5f14595691960d3bbb411b704044c (diff) |
libs: npd: update 'add control point' function
Return NULL when there already is a control point at the position of nearest overlapping points.
Diffstat (limited to 'libs')
-rw-r--r-- | 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 0f1ad975..ee528255 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 |