38 const float normal_co[2],
42 const bool use_deform,
43 const bool use_project,
50 const float threshold_sq = threshold * threshold;
58 float dist_best_sq =
FLT_MAX, co[2];
69 co[0] = normal_co[0] * scalex;
70 co[1] = normal_co[1] * scaley;
74 mask_layer_orig !=
nullptr;
75 mask_layer_orig = mask_layer_orig->
next, mask_layer_eval = mask_layer_eval->
next)
82 *spline_eval =
static_cast<MaskSpline *
>(mask_layer_eval->splines.first);
83 spline_orig !=
nullptr;
84 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
89 for (
i = 0, cur_point_eval = use_deform ? spline_eval->points_deform : spline_eval->points;
91 i++, cur_point_eval++)
95 spline_eval, cur_point_eval, width, height, &tot_diff_point);
99 uint tot_feather_point;
100 float *feather_points =
nullptr, *points;
104 spline_eval, cur_point_eval, width, height, &tot_feather_point);
106 points = feather_points;
107 tot_point = tot_feather_point;
110 points = diff_points;
111 tot_point = tot_diff_point;
114 for (j = 0; j < tot_point - 1; j++) {
115 float dist_sq, a[2],
b[2];
117 a[0] = points[2 * j] * scalex;
118 a[1] = points[2 * j + 1] * scaley;
120 b[0] = points[2 * j + 2] * scalex;
121 b[1] = points[2 * j + 3] * scaley;
125 if (dist_sq < dist_best_sq) {
127 sub_v2_v2v2(tangent, &diff_points[2 * j + 2], &diff_points[2 * j]);
130 point_mask_layer = mask_layer_orig;
131 point_spline = spline_orig;
133 &spline_orig->points[(cur_point_eval - spline_eval->points_deform)] :
134 &spline_orig->points[(cur_point_eval - spline_eval->points)];
135 dist_best_sq = dist_sq;
136 u =
float(j) / tot_point;
140 if (feather_points !=
nullptr) {
149 if (point && dist_best_sq < threshold_sq) {
151 *r_mask_layer = point_mask_layer;
155 *r_spline = point_spline;
172 *r_score = dist_best_sq;
179 *r_mask_layer =
nullptr;
206 const float normal_co[2],
207 const float threshold,
220 const float threshold_sq = threshold * threshold;
221 float len_sq =
FLT_MAX, scalex, scaley;
231 co[0] = normal_co[0] * scalex;
232 co[1] = normal_co[1] * scaley;
236 mask_layer_orig !=
nullptr;
237 mask_layer_orig = mask_layer_orig->
next, mask_layer_eval = mask_layer_eval->
next)
245 *spline_eval =
static_cast<MaskSpline *
>(mask_layer_eval->splines.first);
246 spline_orig !=
nullptr;
247 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
251 for (
int i = 0;
i < spline_orig->tot_point;
i++) {
256 float cur_len_sq, vec[2];
258 vec[0] = bezt->
vec[1][0] * scalex;
259 vec[1] = bezt->
vec[1][1] * scaley;
263 if (cur_len_sq < len_sq) {
264 point_spline = spline_orig;
265 point_mask_layer = mask_layer_orig;
266 point = cur_point_orig;
279 float handle_left[2], handle_right[2];
280 float len_left_sq, len_right_sq;
289 if (len_left_sq <= len_right_sq) {
292 cur_len_sq = len_left_sq;
297 cur_len_sq = len_right_sq;
301 if (len_right_sq <= len_left_sq) {
304 cur_len_sq = len_right_sq;
309 cur_len_sq = len_left_sq;
315 point_mask_layer = mask_layer_orig;
316 point_spline = spline_orig;
317 point = cur_point_orig;
319 which_handle = cur_which_handle;
325 if (len_sq < threshold_sq) {
327 *r_mask_layer = point_mask_layer;
331 *r_spline = point_spline;
334 if (r_which_handle) {
335 *r_which_handle = which_handle;
339 *r_score =
sqrtf(len_sq);
346 *r_mask_layer =
nullptr;
353 if (r_which_handle) {
362 const float normal_co[2],
363 const float threshold,
377 const float threshold_sq = threshold * threshold;
379 float scalex, scaley;
388 co[0] = normal_co[0] * scalex;
389 co[1] = normal_co[1] * scaley;
393 mask_layer_orig !=
nullptr;
394 mask_layer_orig = mask_layer_orig->
next, mask_layer_eval = mask_layer_eval->
next)
398 *spline_eval =
static_cast<MaskSpline *
>(mask_layer_eval->splines.first);
399 spline_orig !=
nullptr;
400 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
404 int i, tot_feather_point;
405 float (*feather_points)[2], (*fp)[2];
413 for (
i = 0;
i < spline_orig->tot_point;
i++) {
418 for (j = 0; j <= cur_point_eval->
tot_uw; j++) {
419 float cur_len_sq, vec[2];
421 vec[0] = (*fp)[0] * scalex;
422 vec[1] = (*fp)[1] * scaley;
426 if (point ==
nullptr || cur_len_sq <
len) {
431 uw = &cur_point_orig->
uw[j - 1];
434 point_mask_layer = mask_layer_orig;
435 point_spline = spline_orig;
436 point = cur_point_orig;
448 if (
len < threshold_sq) {
450 *r_mask_layer = point_mask_layer;
454 *r_spline = point_spline;
473 *r_mask_layer =
nullptr;
601 bool handles_as_control_point,
604 if (handles_as_control_point) {
614 bool handles_as_control_point)
621 if (
mask ==
nullptr) {
637 for (
int i = 0;
i < spline->tot_point;
i++) {
677 const bContext *
C,
ScrArea *area,
float r_center[2],
char mode,
bool *r_has_select)
690 if (r_has_select !=
nullptr) {
691 *r_has_select = mask_selected;
745 *r_zoomx = *r_zoomy = 1.0f;
756 *r_zoomx = *r_zoomy = 1.0f;
762 *r_zoomx = *r_zoomy = 1.0f;
776 *r_aspx = *r_aspy = 1.0f;
787 *r_aspx = *r_aspy = 1.0f;
793 *r_aspx = *r_aspy = 1.0f;
813 *r_scalex = *r_scaley = 1.0f;
830 *r_scalex = *r_scaley = 1.0f;
836 *r_scalex = *r_scaley = 1.0f;
Mask * CTX_data_edit_mask(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
#define MASKPOINT_ISSEL_ANY(p)
void BKE_mask_coord_from_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2])
@ MASK_WHICH_HANDLE_RIGHT
@ MASK_WHICH_HANDLE_STICK
float * BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int width, int height, unsigned int *r_tot_feather_point)
void BKE_mask_coord_to_image(struct Image *image, struct ImageUser *iuser, float r_co[2], const float co[2])
float * BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int width, int height, unsigned int *r_tot_diff_point)
void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
void BKE_mask_point_handle(const struct MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
float(* BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2]
eMaskhandleMode BKE_mask_point_handles_mode_get(const struct MaskSplinePoint *point)
void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2])
float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float start_u, const float co[2], eMaskSign sign)
struct MaskSplinePoint * BKE_mask_spline_point_array(struct MaskSpline *spline)
#define LISTBASE_FOREACH(type, var, list)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2(float r[2], const float a[2])
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
#define INIT_MINMAX2(min, max)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void ED_clip_point_stable_pos(const SpaceClip *sc, const ARegion *region, float x, float y, float *xr, float *yr)
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float r_co[2])
void ED_space_clip_get_size(const SpaceClip *sc, int *r_width, int *r_height)
void ED_space_clip_get_zoom(const SpaceClip *sc, const ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_space_clip_get_aspect(const SpaceClip *sc, float *r_aspx, float *r_aspy)
void ED_clip_point_stable_pos__reverse(const SpaceClip *sc, const ARegion *region, const float co[2], float r_co[2])
the reverse of ED_clip_point_stable_pos(), gets the marker region coords. better name here?...
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
void ED_image_mouse_pos(SpaceImage *sima, const ARegion *region, const int mval[2], float co[2])
void ED_image_point_pos(SpaceImage *sima, const ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
void ED_space_image_get_zoom(SpaceImage *sima, const ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_image_point_pos__reverse(SpaceImage *sima, const ARegion *region, const float co[2], float r_co[2])
Read Guarded memory(de)allocation.
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
BPy_StructRNA * depsgraph
void MEM_freeN(void *vmemh)
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
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)
void ED_mask_center_from_pivot_ex(const bContext *C, ScrArea *area, float r_center[2], char mode, bool *r_has_select)
void ED_mask_point_pos(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_mask_get_aspect(ScrArea *area, ARegion *, float *r_aspx, float *r_aspy)
void ED_mask_zoom(ScrArea *area, ARegion *region, float *r_zoomx, float *r_zoomy)
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)
static void mask_point_scaled_handle(const MaskSplinePoint *point, const eMaskWhichHandle which_handle, const float scalex, const float scaley, float handle[2])
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
void ED_mask_point_pos__reverse(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2], bool handles_as_control_point)
static void handle_position_for_minmax(const MaskSplinePoint *point, eMaskWhichHandle which_handle, bool handles_as_control_point, float r_handle[2])
void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
bool ED_mask_find_nearest_diff_point(const bContext *C, Mask *mask_orig, const float normal_co[2], int threshold, bool feather, float tangent[2], const bool use_deform, const bool use_project, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, float *r_u, float *r_score)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
struct MovieClipUser user