[Bf-blender-cvs] [2f1e34cfcc0] master: Cleanup: use clamp_* from BLI_math (replace macro)

Campbell Barton noreply at git.blender.org
Sun Jun 17 11:57:37 CEST 2018


Commit: 2f1e34cfcc06a3fa49dc1b7c99e78cecdc509bf9
Author: Campbell Barton
Date:   Sun Jun 17 11:50:56 2018 +0200
Branches: master
https://developer.blender.org/rB2f1e34cfcc06a3fa49dc1b7c99e78cecdc509bf9

Cleanup: use clamp_* from BLI_math (replace macro)

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

M	source/blender/bmesh/tools/bmesh_intersect.c
M	source/blender/compositor/nodes/COM_TimeNode.cpp
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_region_color_picker.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/mesh/editmesh_loopcut.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/python/bmesh/bmesh_py_types.c
M	source/blender/python/bmesh/bmesh_py_types_customdata.c
M	source/blender/python/bmesh/bmesh_py_types_meshdata.c
M	source/blender/python/bmesh/bmesh_py_utils.c

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

diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c
index 88467e60dc0..b1a8c3ccb86 100644
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@ -1233,7 +1233,7 @@ bool BM_mesh_intersect(
 
 				if (BM_vert_in_edge(e, v_prev)) {
 					BMEdge *e_split;
-					v_prev = BM_edge_split(bm, e, v_prev, &e_split, CLAMPIS(fac, 0.0f, 1.0f));
+					v_prev = BM_edge_split(bm, e, v_prev, &e_split, clamp_f(fac, 0.0f, 1.0f));
 					BLI_assert(BM_vert_in_edge(e, v_end));
 
 					if (!BM_edge_exists(v_prev, vi) &&
diff --git a/source/blender/compositor/nodes/COM_TimeNode.cpp b/source/blender/compositor/nodes/COM_TimeNode.cpp
index 8450b521267..0185b85e772 100644
--- a/source/blender/compositor/nodes/COM_TimeNode.cpp
+++ b/source/blender/compositor/nodes/COM_TimeNode.cpp
@@ -54,7 +54,7 @@ void TimeNode::convertToOperations(NodeConverter &converter, const CompositorCon
 
 	curvemapping_initialize((CurveMapping *)node->storage);
 	fac = curvemapping_evaluateF((CurveMapping *)node->storage, 0, fac);
-	operation->setValue(CLAMPIS(fac, 0.0f, 1.0f));
+	operation->setValue(clamp_f(fac, 0.0f, 1.0f));
 	converter.addOperation(operation);
 	
 	converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 5b5b69f8153..aae552c274b 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -5240,12 +5240,12 @@ static int ui_do_but_COLOR(
 			rgb_to_hsv_compat_v(col, hsv);
 
 			if (event->type == WHEELDOWNMOUSE)
-				hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
+				hsv[2] = clamp_f(hsv[2] - 0.05f, 0.0f, 1.0f);
 			else if (event->type == WHEELUPMOUSE)
-				hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
+				hsv[2] = clamp_f(hsv[2] + 0.05f, 0.0f, 1.0f);
 			else {
 				float fac = 0.005 * (event->y - event->prevy);
-				hsv[2] = CLAMPIS(hsv[2] + fac, 0.0f, 1.0f);
+				hsv[2] = clamp_f(hsv[2] + fac, 0.0f, 1.0f);
 			}
 
 			hsv_to_rgb_v(hsv, data->vec);
@@ -5963,12 +5963,12 @@ static int ui_do_but_HSVCIRCLE(
 		}
 		/* XXX hardcoded keymap check.... */
 		else if (event->type == WHEELDOWNMOUSE) {
-			hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
+			hsv[2] = clamp_f(hsv[2] - 0.05f, 0.0f, 1.0f);
 			ui_but_hsv_set(but);    /* converts to rgb */
 			ui_numedit_apply(C, block, but, data);
 		}
 		else if (event->type == WHEELUPMOUSE) {
-			hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
+			hsv[2] = clamp_f(hsv[2] + 0.05f, 0.0f, 1.0f);
 			ui_but_hsv_set(but);    /* converts to rgb */
 			ui_numedit_apply(C, block, but, data);
 		}
diff --git a/source/blender/editors/interface/interface_region_color_picker.c b/source/blender/editors/interface/interface_region_color_picker.c
index 4309e913d9e..00462b456ea 100644
--- a/source/blender/editors/interface/interface_region_color_picker.c
+++ b/source/blender/editors/interface/interface_region_color_picker.c
@@ -585,7 +585,7 @@ static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *blo
 
 				ui_rgb_to_color_picker_compat_v(rgb, hsv);
 
-				hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f);
+				hsv[2] = clamp_f(hsv[2] + add, 0.0f, 1.0f);
 				ui_color_picker_to_rgb_v(hsv, rgb);
 
 				if (use_display_colorspace)
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index e3230d39ae2..b740b410c1a 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2305,7 +2305,7 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float
 	else
 		radius_t = hsv[1];
 
-	radius = CLAMPIS(radius_t, 0.0f, 1.0f) * radius;
+	radius = clamp_f(radius_t, 0.0f, 1.0f) * radius;
 	*xpos = centx + cosf(-ang) * radius;
 	*ypos = centy + sinf(-ang) * radius;
 }
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 35558bd5af1..38810428382 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1114,7 +1114,7 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event
 
 			/* some view2d's (graph) don't have min/max zoom, or extreme ones */
 			if (v2d->maxzoom > 0.0f)
-				zoomfac = CLAMPIS(0.001f * v2d->maxzoom, 0.001f, 0.01f);
+				zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f);
 
 			/* x-axis transform */
 			fac = zoomfac * (event->x - vzd->lastx);
diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c
index f07073cd3d7..a52bf41b9da 100644
--- a/source/blender/editors/mesh/editmesh_loopcut.c
+++ b/source/blender/editors/mesh/editmesh_loopcut.c
@@ -771,7 +771,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	if (cuts != lcd->cuts) {
 		/* allow zero so you can backspace and type in a value
 		 * otherwise 1 as minimum would make more sense */
-		lcd->cuts = CLAMPIS(cuts, 0, SUBD_CUTS_MAX);
+		lcd->cuts = clamp_i(cuts, 0, SUBD_CUTS_MAX);
 		RNA_int_set(op->ptr, "number_cuts", (int)lcd->cuts);
 		ringsel_find_edge(lcd, (int)lcd->cuts);
 		show_cuts = true;
@@ -779,7 +779,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	}
 
 	if (smoothness != lcd->smoothness) {
-		lcd->smoothness = CLAMPIS(smoothness, -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
+		lcd->smoothness = clamp_f(smoothness, -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
 		RNA_float_set(op->ptr, "smoothness", lcd->smoothness);
 		show_cuts = true;
 		ED_region_tag_redraw(lcd->ar);
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 54d56dff903..6bc8f5fc36d 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -1797,7 +1797,7 @@ static void view_zoom_to_window_xy_camera(
 {
 	RegionView3D *rv3d = ar->regiondata;
 	const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
-	const float zoomfac_new = CLAMPIS(zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
+	const float zoomfac_new = clamp_f(zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
 	const float camzoom_new = BKE_screen_view3d_zoom_from_fac(zoomfac_new);
 
 
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 07c255c4abe..2c5fd4e7bf7 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -1399,7 +1399,7 @@ static PyObject *bpy_bmvert_copy_from_vert_interp(BPy_BMVert *self, PyObject *ar
 			return NULL;
 		}
 
-		BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, CLAMPIS(fac, 0.0f, 1.0f));
+		BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f));
 
 		PyMem_FREE(vert_array);
 		Py_RETURN_NONE;
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index cb95ded4f0d..aee9d6405d0 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -1136,7 +1136,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
 				ret = -1;
 			}
 			else {
-				*(float *)value = CLAMPIS(tmp_val, 0.0f, 1.0f);
+				*(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
 			}
 			break;
 		}
@@ -1148,7 +1148,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
 				ret = -1;
 			}
 			else {
-				*(float *)value = CLAMPIS(tmp_val, 0.0f, 1.0f);
+				*(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
 			}
 			break;
 		}
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 7984f625d96..4c44c104037 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -38,6 +38,7 @@
 #include "DNA_meshdata_types.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_math_base.h"
 #include "BLI_math_vector.h"
 
 #include "BKE_deform.h"
@@ -555,7 +556,7 @@ static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key,
 					return -1;
 				}
 
-				dw->weight = CLAMPIS(f, 0.0f, 1.0f);
+				dw->weight = clamp_f(f, 0.0f, 1.0f);
 			}
 		}
 		else {
diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c
index 224c8295a9b..ca34de219b8 100644
--- a/source/blender/python/bmesh/bmesh_py_utils.c
+++ b/source/blender/python/bmesh/bmesh_py_utils.c
@@ -33,6 +33,7 @@
 #include <Python.h>
 
 #include "BLI_utildefines.h"
+#include "BLI_math_base.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -159,7 +160,7 @@ static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObje
 
 	bm = py_edge->bm;
 
-	e_new = BM_vert_collapse_faces(bm, py_edge->e, py_vert->v, CLAMPIS(fac, 0.0f, 1.0f), true, do_join_faces, true);
+	e_new = BM_vert_collapse_faces(bm, py_edge->e, py_vert->v, clamp_f(fac, 0.0f, 1.0f), true, do_join_faces, true);
 
 	if (e_new) {
 		return BPy_BMEdge_CreatePyObject(bm, e_new);
@@ -365,7 +366,7 @@ static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args)
 
 	bm = py_edge->bm;
 
-	v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, CLAMPIS(fac, 0.0f, 1.0f));
+	v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, clamp_f(fac, 0.0f, 1.0f));
 
 	if (v_new && e_new) {
 		PyObject *ret = PyTuple_New(2);



More information about the Bf-blender-cvs mailing list