Commit: 4144a85bda458196d1c1bbd12044e93e1c885337
Author: Chris Blackbourn
Date:   Tue Jun 21 16:36:25 2022 +1200
Branches: master
https://developer.blender.org/rB4144a85bda458196d1c1bbd12044e93e1c885337

Cleanup: Type safety and asserts around ED_select_similar_compare

===================================================================

M       source/blender/editors/include/ED_select_utils.h
M       source/blender/editors/util/select_utils.c

===================================================================

diff --git a/source/blender/editors/include/ED_select_utils.h 
b/source/blender/editors/include/ED_select_utils.h
index fa02ebe18f6..8c856794ec8 100644
--- a/source/blender/editors/include/ED_select_utils.h
+++ b/source/blender/editors/include/ED_select_utils.h
@@ -40,11 +40,11 @@ typedef enum {
 } eSelectOp;
 
 /* Select Similar */
-enum {
+typedef enum {
   SIM_CMP_EQ = 0,
   SIM_CMP_GT,
   SIM_CMP_LT,
-};
+} eSimilarCmp;
 
 #define SEL_OP_USE_OUTSIDE(sel_op) (ELEM(sel_op, SEL_OP_AND))
 #define SEL_OP_USE_PRE_DESELECT(sel_op) (ELEM(sel_op, SEL_OP_SET))
@@ -63,11 +63,11 @@ int ED_select_op_action(eSelectOp sel_op, bool is_select, 
bool is_inside);
  */
 int ED_select_op_action_deselected(eSelectOp sel_op, bool is_select, bool 
is_inside);
 
-int ED_select_similar_compare_float(float delta, float thresh, int compare);
+bool ED_select_similar_compare_float(float delta, float thresh, eSimilarCmp 
compare);
 bool ED_select_similar_compare_float_tree(const struct KDTree_1d *tree,
                                           float length,
                                           float thresh,
-                                          int compare);
+                                          eSimilarCmp compare);
 
 /**
  * Utility to use for selection operations that run multiple times (circle 
select).
diff --git a/source/blender/editors/util/select_utils.c 
b/source/blender/editors/util/select_utils.c
index 263ef06718f..660afa4c3d7 100644
--- a/source/blender/editors/util/select_utils.c
+++ b/source/blender/editors/util/select_utils.c
@@ -66,15 +66,18 @@ eSelectOp ED_select_op_modal(const eSelectOp sel_op, const 
bool is_first)
   return sel_op;
 }
 
-int ED_select_similar_compare_float(const float delta, const float thresh, 
const int compare)
+bool ED_select_similar_compare_float(const float delta,
+                                     const float thresh,
+                                     const eSimilarCmp compare)
 {
+  BLI_assert(thresh >= 0.0f);
   switch (compare) {
     case SIM_CMP_EQ:
       return (fabsf(delta) <= thresh);
     case SIM_CMP_GT:
-      return ((delta + thresh) >= 0.0);
+      return ((delta + thresh) >= 0.0f);
     case SIM_CMP_LT:
-      return ((delta - thresh) <= 0.0);
+      return ((delta - thresh) <= 0.0f);
     default:
       BLI_assert_unreachable();
       return 0;
@@ -84,8 +87,10 @@ int ED_select_similar_compare_float(const float delta, const 
float thresh, const
 bool ED_select_similar_compare_float_tree(const KDTree_1d *tree,
                                           const float length,
                                           const float thresh,
-                                          const int compare)
+                                          const eSimilarCmp compare)
 {
+  BLI_assert(compare == SIM_CMP_EQ || length >= 0.0f); /* See precision note 
below. */
+
   /* Length of the edge we want to compare against. */
   float nearest_edge_length;
 
@@ -112,6 +117,7 @@ bool ED_select_similar_compare_float_tree(const KDTree_1d 
*tree,
 
   KDTreeNearest_1d nearest;
   if (BLI_kdtree_1d_find_nearest(tree, &nearest_edge_length, &nearest) != -1) {
+    BLI_assert(compare == SIM_CMP_EQ || nearest.co[0] >= 0.0f); /* See 
precision note above. */
     float delta = length - nearest.co[0];
     return ED_select_similar_compare_float(delta, thresh, compare);
   }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to