From cbb60190b4bb994e836002b3eebed2a63f3ac9c9 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 3 Jul 2024 14:42:14 -0400 Subject: [PATCH] Cleanup: Sculpt: Use const for gesture data, rename variables --- .../editors/sculpt_paint/sculpt_gesture.cc | 31 ++++++++++--------- .../editors/sculpt_paint/sculpt_intern.hh | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/blender/editors/sculpt_paint/sculpt_gesture.cc b/source/blender/editors/sculpt_paint/sculpt_gesture.cc index 00f5305fb9a..48e42844dbb 100644 --- a/source/blender/editors/sculpt_paint/sculpt_gesture.cc +++ b/source/blender/editors/sculpt_paint/sculpt_gesture.cc @@ -17,6 +17,7 @@ #include "BLI_math_matrix.h" #include "BLI_math_matrix_types.hh" #include "BLI_math_vector.h" +#include "BLI_math_vector.hh" #include "BLI_math_vector_types.hh" #include "BLI_rect.h" #include "BLI_vector.hh" @@ -379,12 +380,12 @@ static void update_affected_nodes(GestureData &gesture_data) } } -static bool is_affected_lasso(GestureData &gesture_data, const float co[3]) +static bool is_affected_lasso(const GestureData &gesture_data, const float3 &position) { int scr_co_s[2]; float co_final[3]; - flip_v3_v3(co_final, co, gesture_data.symmpass); + flip_v3_v3(co_final, position, gesture_data.symmpass); /* First project point to 2d space. */ const float2 scr_co_f = ED_view3d_project_float_v2_m4( @@ -394,15 +395,15 @@ static bool is_affected_lasso(GestureData &gesture_data, const float co[3]) scr_co_s[1] = scr_co_f[1]; /* Clip against lasso boundbox. */ - LassoData *lasso = &gesture_data.lasso; - if (!BLI_rcti_isect_pt(&lasso->boundbox, scr_co_s[0], scr_co_s[1])) { + const LassoData &lasso = gesture_data.lasso; + if (!BLI_rcti_isect_pt(&lasso.boundbox, scr_co_s[0], scr_co_s[1])) { return gesture_data.selection_type == SelectionType::Outside; } - scr_co_s[0] -= lasso->boundbox.xmin; - scr_co_s[1] -= lasso->boundbox.ymin; + scr_co_s[0] -= lasso.boundbox.xmin; + scr_co_s[1] -= lasso.boundbox.ymin; - const bool bitmap_result = lasso->mask_px[scr_co_s[1] * lasso->width + scr_co_s[0]].test(); + const bool bitmap_result = lasso.mask_px[scr_co_s[1] * lasso.width + scr_co_s[0]].test(); switch (gesture_data.selection_type) { case SelectionType::Inside: return bitmap_result; @@ -413,9 +414,9 @@ static bool is_affected_lasso(GestureData &gesture_data, const float co[3]) return false; } -bool is_affected(GestureData &gesture_data, const float3 &co, const float3 &vertex_normal) +bool is_affected(const GestureData &gesture_data, const float3 &position, const float3 &normal) { - float dot = dot_v3v3(gesture_data.view_normal, vertex_normal); + float dot = math::dot(gesture_data.view_normal, normal); const bool is_effected_front_face = !(gesture_data.front_faces_only && dot < 0.0f); if (!is_effected_front_face) { @@ -424,19 +425,19 @@ bool is_affected(GestureData &gesture_data, const float3 &co, const float3 &vert switch (gesture_data.shape_type) { case ShapeType::Box: { - const bool is_contained = isect_point_planes_v3(gesture_data.clip_planes, 4, co); + const bool is_contained = isect_point_planes_v3(gesture_data.clip_planes, 4, position); return ((is_contained && gesture_data.selection_type == SelectionType::Inside) || (!is_contained && gesture_data.selection_type == SelectionType::Outside)); } case ShapeType::Lasso: - return is_affected_lasso(gesture_data, co); + return is_affected_lasso(gesture_data, position); case ShapeType::Line: if (gesture_data.line.use_side_planes) { - return plane_point_side_v3(gesture_data.line.plane, co) > 0.0f && - plane_point_side_v3(gesture_data.line.side_plane[0], co) > 0.0f && - plane_point_side_v3(gesture_data.line.side_plane[1], co) > 0.0f; + return plane_point_side_v3(gesture_data.line.plane, position) > 0.0f && + plane_point_side_v3(gesture_data.line.side_plane[0], position) > 0.0f && + plane_point_side_v3(gesture_data.line.side_plane[1], position) > 0.0f; } - return plane_point_side_v3(gesture_data.line.plane, co) > 0.0f; + return plane_point_side_v3(gesture_data.line.plane, position) > 0.0f; } return false; } diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.hh b/source/blender/editors/sculpt_paint/sculpt_intern.hh index fd4bd01a11d..74595d1c074 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_intern.hh @@ -1792,7 +1792,7 @@ struct Operation { }; /* Determines whether or not a gesture action should be applied. */ -bool is_affected(GestureData &gesture_data, const float3 &co, const float3 &vertex_normal); +bool is_affected(const GestureData &gesture_data, const float3 &position, const float3 &normal); /* Initialization functions. */ std::unique_ptr init_from_box(bContext *C, wmOperator *op);