From 6483b9cb076b2988732dc19e354092ccbd653f72 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 27 Apr 2016 13:11:17 +1000 Subject: Fix T48282: Newly added mask points don't follow parent --- source/blender/editors/mask/mask_add.c | 40 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/mask') diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index 3730cff731c..1bca23c57ea 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -198,8 +198,6 @@ static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint * const float point_co[2], const float u, const MaskSplinePoint *reference_point, const bool reference_adjacent) { - MaskSplinePoint *prev_point = NULL; - MaskSplinePoint *next_point = NULL; BezTriple *bezt; float co[3]; @@ -247,14 +245,44 @@ static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint * else { bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1); } + + new_point->parent = reference_point->parent; } else if (reference_adjacent) { if (spline->tot_point != 1) { - int index = (int)(new_point - spline->points); - prev_point = &spline->points[(index - 1) % spline->tot_point]; - next_point = &spline->points[(index + 1) % spline->tot_point]; + MaskSplinePoint *prev_point, *next_point, *close_point; + + const int index = (int)(new_point - spline->points); + if (spline->flag & MASK_SPLINE_CYCLIC) { + prev_point = &spline->points[mod_i(index - 1, spline->tot_point)]; + next_point = &spline->points[mod_i(index + 1, spline->tot_point)]; + } + else { + prev_point = (index != 0) ? &spline->points[index - 1] : NULL; + next_point = (index != spline->tot_point - 1) ? &spline->points[index + 1] : NULL; + } + + if (prev_point && next_point) { + close_point = (len_squared_v2v2(new_point->bezt.vec[1], prev_point->bezt.vec[1]) < + len_squared_v2v2(new_point->bezt.vec[1], next_point->bezt.vec[1])) ? + prev_point : next_point; + } + else { + close_point = prev_point ? prev_point : next_point; + } + + /* handle type */ + char handle_type = 0; + if (prev_point) { + handle_type = prev_point->bezt.h2; + } + if (next_point) { + handle_type = MAX2(next_point->bezt.h2, handle_type); + } + bezt->h1 = bezt->h2 = handle_type; - bezt->h1 = bezt->h2 = MAX2(prev_point->bezt.h2, next_point->bezt.h1); + /* parent */ + new_point->parent = close_point->parent; /* note, we may want to copy other attributes later, radius? pressure? color? */ } -- cgit v1.2.3