Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-03-25 11:06:17 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-03-25 11:06:17 +0300
commit4c57f07a0fde0ca067e5b0e6609ded6c0e170cc2 (patch)
tree652abc47c4f68fd7377c031d82ada29949bb4f28 /source/blender/editors/mask/mask_ops.c
parent2bc791437e3b8e42c1369daf15c72934474b1e73 (diff)
Cleanup: move mask queries into own file
Similar functions to lookup nearest mask points were in mask_add.c & mask_edit.c
Diffstat (limited to 'source/blender/editors/mask/mask_ops.c')
-rw-r--r--source/blender/editors/mask/mask_ops.c292
1 files changed, 0 insertions, 292 deletions
diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c
index 79999bcebca..758d0abbab7 100644
--- a/source/blender/editors/mask/mask_ops.c
+++ b/source/blender/editors/mask/mask_ops.c
@@ -52,298 +52,6 @@
#include "mask_intern.h" /* own include */
-/******************** utility functions *********************/
-
-static void mask_point_scaled_handle(/*const*/ MaskSplinePoint *point,
- /*const*/ eMaskWhichHandle which_handle,
- const float scalex,
- const float scaley,
- float handle[2])
-{
- BKE_mask_point_handle(point, which_handle, handle);
- handle[0] *= scalex;
- handle[1] *= scaley;
-}
-
-MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C,
- Mask *mask_orig,
- const float normal_co[2],
- const float threshold,
- MaskLayer **r_mask_layer,
- MaskSpline **r_spline,
- eMaskWhichHandle *r_which_handle,
- float *r_score)
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *region = CTX_wm_region(C);
-
- MaskLayer *point_mask_layer = NULL;
- MaskSpline *point_spline = NULL;
- MaskSplinePoint *point = NULL;
- float co[2];
- const float threshold_sq = threshold * threshold;
- float len_sq = FLT_MAX, scalex, scaley;
- eMaskWhichHandle which_handle = MASK_WHICH_HANDLE_NONE;
- int width, height;
-
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id);
-
- ED_mask_get_size(sa, &width, &height);
- ED_mask_pixelspace_factor(sa, region, &scalex, &scaley);
-
- co[0] = normal_co[0] * scalex;
- co[1] = normal_co[1] * scaley;
-
- for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first,
- *mask_layer_eval = mask_eval->masklayers.first;
- mask_layer_orig != NULL;
- mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next) {
-
- if (mask_layer_orig->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
- continue;
- }
-
- for (MaskSpline *spline_orig = mask_layer_orig->splines.first,
- *spline_eval = mask_layer_eval->splines.first;
- spline_orig != NULL;
- spline_orig = spline_orig->next, spline_eval = spline_eval->next) {
- MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline_eval);
-
- for (int i = 0; i < spline_orig->tot_point; i++) {
- MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
- MaskSplinePoint *cur_point_deform_eval = &points_array[i];
- eMaskWhichHandle cur_which_handle = MASK_WHICH_HANDLE_NONE;
- BezTriple *bezt = &cur_point_deform_eval->bezt;
- float cur_len_sq, vec[2];
-
- vec[0] = bezt->vec[1][0] * scalex;
- vec[1] = bezt->vec[1][1] * scaley;
-
- cur_len_sq = len_squared_v2v2(co, vec);
-
- if (cur_len_sq < len_sq) {
- point_spline = spline_orig;
- point_mask_layer = mask_layer_orig;
- point = cur_point_orig;
- len_sq = cur_len_sq;
- which_handle = MASK_WHICH_HANDLE_NONE;
- }
-
- if (BKE_mask_point_handles_mode_get(cur_point_deform_eval) == MASK_HANDLE_MODE_STICK) {
- float handle[2];
- mask_point_scaled_handle(
- cur_point_deform_eval, MASK_WHICH_HANDLE_STICK, scalex, scaley, handle);
- cur_len_sq = len_squared_v2v2(co, handle);
- cur_which_handle = MASK_WHICH_HANDLE_STICK;
- }
- else {
- float handle_left[2], handle_right[2];
- float len_left_sq, len_right_sq;
- mask_point_scaled_handle(
- cur_point_deform_eval, MASK_WHICH_HANDLE_LEFT, scalex, scaley, handle_left);
- mask_point_scaled_handle(
- cur_point_deform_eval, MASK_WHICH_HANDLE_RIGHT, scalex, scaley, handle_right);
-
- len_left_sq = len_squared_v2v2(co, handle_left);
- len_right_sq = len_squared_v2v2(co, handle_right);
- if (i == 0) {
- if (len_left_sq <= len_right_sq) {
- if (bezt->h1 != HD_VECT) {
- cur_which_handle = MASK_WHICH_HANDLE_LEFT;
- cur_len_sq = len_left_sq;
- }
- }
- else if (bezt->h2 != HD_VECT) {
- cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
- cur_len_sq = len_right_sq;
- }
- }
- else {
- if (len_right_sq <= len_left_sq) {
- if (bezt->h2 != HD_VECT) {
- cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
- cur_len_sq = len_right_sq;
- }
- }
- else if (bezt->h1 != HD_VECT) {
- cur_which_handle = MASK_WHICH_HANDLE_LEFT;
- cur_len_sq = len_left_sq;
- }
- }
- }
-
- if (cur_len_sq <= len_sq && cur_which_handle != MASK_WHICH_HANDLE_NONE) {
- point_mask_layer = mask_layer_orig;
- point_spline = spline_orig;
- point = cur_point_orig;
- len_sq = cur_len_sq;
- which_handle = cur_which_handle;
- }
- }
- }
- }
-
- if (len_sq < threshold_sq) {
- if (r_mask_layer) {
- *r_mask_layer = point_mask_layer;
- }
-
- if (r_spline) {
- *r_spline = point_spline;
- }
-
- if (r_which_handle) {
- *r_which_handle = which_handle;
- }
-
- if (r_score) {
- *r_score = sqrtf(len_sq);
- }
-
- return point;
- }
-
- if (r_mask_layer) {
- *r_mask_layer = NULL;
- }
-
- if (r_spline) {
- *r_spline = NULL;
- }
-
- if (r_which_handle) {
- *r_which_handle = MASK_WHICH_HANDLE_NONE;
- }
-
- return NULL;
-}
-
-bool ED_mask_feather_find_nearest(const bContext *C,
- Mask *mask_orig,
- const float normal_co[2],
- const float threshold,
- MaskLayer **r_mask_layer,
- MaskSpline **r_spline,
- MaskSplinePoint **r_point,
- MaskSplinePointUW **r_uw,
- float *r_score)
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *region = CTX_wm_region(C);
-
- MaskLayer *point_mask_layer = NULL;
- MaskSpline *point_spline = NULL;
- MaskSplinePoint *point = NULL;
- MaskSplinePointUW *uw = NULL;
- const float threshold_sq = threshold * threshold;
- float len = FLT_MAX, co[2];
- float scalex, scaley;
- int width, height;
-
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id);
-
- ED_mask_get_size(sa, &width, &height);
- ED_mask_pixelspace_factor(sa, region, &scalex, &scaley);
-
- co[0] = normal_co[0] * scalex;
- co[1] = normal_co[1] * scaley;
-
- for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first,
- *mask_layer_eval = mask_eval->masklayers.first;
- mask_layer_orig != NULL;
- mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next) {
-
- for (MaskSpline *spline_orig = mask_layer_orig->splines.first,
- *spline_eval = mask_layer_eval->splines.first;
- spline_orig != NULL;
- spline_orig = spline_orig->next, spline_eval = spline_eval->next) {
- // MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
-
- int i, tot_feather_point;
- float(*feather_points)[2], (*fp)[2];
-
- if (mask_layer_orig->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
- continue;
- }
-
- feather_points = fp = BKE_mask_spline_feather_points(spline_eval, &tot_feather_point);
-
- for (i = 0; i < spline_orig->tot_point; i++) {
- int j;
- MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
- MaskSplinePoint *cur_point_eval = &spline_eval->points[i];
-
- for (j = 0; j <= cur_point_eval->tot_uw; j++) {
- float cur_len_sq, vec[2];
-
- vec[0] = (*fp)[0] * scalex;
- vec[1] = (*fp)[1] * scaley;
-
- cur_len_sq = len_squared_v2v2(vec, co);
-
- if (point == NULL || cur_len_sq < len) {
- if (j == 0) {
- uw = NULL;
- }
- else {
- uw = &cur_point_orig->uw[j - 1];
- }
-
- point_mask_layer = mask_layer_orig;
- point_spline = spline_orig;
- point = cur_point_orig;
- len = cur_len_sq;
- }
-
- fp++;
- }
- }
-
- MEM_freeN(feather_points);
- }
- }
-
- if (len < threshold_sq) {
- if (r_mask_layer) {
- *r_mask_layer = point_mask_layer;
- }
-
- if (r_spline) {
- *r_spline = point_spline;
- }
-
- if (r_point) {
- *r_point = point;
- }
-
- if (r_uw) {
- *r_uw = uw;
- }
-
- if (r_score) {
- *r_score = sqrtf(len);
- }
-
- return true;
- }
-
- if (r_mask_layer) {
- *r_mask_layer = NULL;
- }
-
- if (r_spline) {
- *r_spline = NULL;
- }
-
- if (r_point) {
- *r_point = NULL;
- }
-
- return false;
-}
-
/******************** create new mask *********************/
Mask *ED_mask_new(bContext *C, const char *name)