[Bf-blender-cvs] [43b49130516] master: Math Lib: Add non-clamped round_* functions

Campbell Barton noreply at git.blender.org
Wed Sep 27 03:01:25 CEST 2017


Commit: 43b49130516db974c125d89919fe8ddc25cf4405
Author: Campbell Barton
Date:   Wed Sep 27 11:13:03 2017 +1000
Branches: master
https://developer.blender.org/rB43b49130516db974c125d89919fe8ddc25cf4405

Math Lib: Add non-clamped round_* functions

Replace iroundf with round_fl_to_int, add other types

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

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/blenlib/intern/timecode.c
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/animation/anim_ops.c
M	source/blender/editors/armature/pose_slide.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_action/action_edit.c
M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/editors/space_graph/graph_ops.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_nla/nla_edit.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_snap.c
M	source/blender/modifiers/intern/MOD_meshcache_util.c
M	source/blender/render/intern/source/imagetexture.c
M	source/blender/windowmanager/intern/wm_gesture.c

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

diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index e7e89a6424a..e6a72298ae7 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -149,10 +149,23 @@ MINLINE int power_of_2_min_i(int n);
 MINLINE unsigned int power_of_2_max_u(unsigned int x);
 MINLINE unsigned int power_of_2_min_u(unsigned int x);
 
-MINLINE int iroundf(float a);
 MINLINE int divide_round_i(int a, int b);
 MINLINE int mod_i(int i, int n);
 
+MINLINE signed char    round_fl_to_char(float a);
+MINLINE unsigned char  round_fl_to_uchar(float a);
+MINLINE short          round_fl_to_short(float a);
+MINLINE unsigned short round_fl_to_ushort(float a);
+MINLINE int            round_fl_to_int(float a);
+MINLINE unsigned int   round_fl_to_uint(float a);
+
+MINLINE signed char    round_db_to_char(double a);
+MINLINE unsigned char  round_db_to_uchar(double a);
+MINLINE short          round_db_to_short(double a);
+MINLINE unsigned short round_db_to_ushort(double a);
+MINLINE int            round_db_to_int(double a);
+MINLINE unsigned int   round_db_to_uint(double a);
+
 MINLINE signed char    round_fl_to_char_clamp(float a);
 MINLINE unsigned char  round_fl_to_uchar_clamp(float a);
 MINLINE short          round_fl_to_short_clamp(float a);
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 37efe95791c..749c18fc0ce 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -184,11 +184,6 @@ MINLINE unsigned power_of_2_min_u(unsigned x)
 
 /* rounding and clamping */
 
-MINLINE int iroundf(float a)
-{
-	return (int)floorf(a + 0.5f);
-}
-
 #define _round_clamp_fl_impl(arg, ty, min, max) { \
 	float r = floorf(arg + 0.5f); \
 	if      (UNLIKELY(r <= (float)min)) return (ty)min; \
@@ -203,6 +198,26 @@ MINLINE int iroundf(float a)
 	else return (ty)r; \
 }
 
+#define _round_fl_impl(arg, ty) { return (ty)floorf(arg + 0.5f); }
+#define _round_db_impl(arg, ty) { return (ty)floor(arg + 0.5); }
+
+MINLINE signed char    round_fl_to_char(float a) { _round_fl_impl(a, signed char) }
+MINLINE unsigned char  round_fl_to_uchar(float a) { _round_fl_impl(a, unsigned char) }
+MINLINE short          round_fl_to_short(float a) { _round_fl_impl(a, short) }
+MINLINE unsigned short round_fl_to_ushort(float a) { _round_fl_impl(a, unsigned short) }
+MINLINE int            round_fl_to_int(float a) { _round_fl_impl(a, int) }
+MINLINE unsigned int   round_fl_to_uint(float a) { _round_fl_impl(a, unsigned int) }
+
+MINLINE signed char    round_db_to_char(double a) { _round_db_impl(a, signed char) }
+MINLINE unsigned char  round_db_to_uchar(double a) { _round_db_impl(a, unsigned char) }
+MINLINE short          round_db_to_short(double a) { _round_db_impl(a, short) }
+MINLINE unsigned short round_db_to_ushort(double a) { _round_db_impl(a, unsigned short) }
+MINLINE int            round_db_to_int(double a) { _round_db_impl(a, int) }
+MINLINE unsigned int   round_db_to_uint(double a) { _round_db_impl(a, unsigned int) }
+
+#undef _round_fl_impl
+#undef _round_db_impl
+
 MINLINE signed char    round_fl_to_char_clamp(float a) { _round_clamp_fl_impl(a, signed char, SCHAR_MIN, SCHAR_MAX) }
 MINLINE unsigned char  round_fl_to_uchar_clamp(float a) { _round_clamp_fl_impl(a, unsigned char, 0, UCHAR_MAX) }
 MINLINE short          round_fl_to_short_clamp(float a) { _round_clamp_fl_impl(a, short, SHRT_MIN, SHRT_MAX) }
diff --git a/source/blender/blenlib/intern/timecode.c b/source/blender/blenlib/intern/timecode.c
index e755a7ae52c..7856bad4d99 100644
--- a/source/blender/blenlib/intern/timecode.c
+++ b/source/blender/blenlib/intern/timecode.c
@@ -94,11 +94,11 @@ size_t BLI_timecode_string_from_time(
 		 * to cope with 'half' frames, etc., which should be fine in most cases
 		 */
 		seconds = (int)time;
-		frames = iroundf((float)(((double)time - (double)seconds) * fps));
+		frames = round_fl_to_int((float)(((double)time - (double)seconds) * fps));
 	}
 	else {
 		/* seconds (with pixel offset rounding) */
-		seconds = iroundf(time);
+		seconds = round_fl_to_int(time);
 	}
 
 	switch (timecode_style) {
@@ -169,7 +169,7 @@ size_t BLI_timecode_string_from_time(
 
 			/* precision of decimal part */
 			const int ms_dp = (power <= 0) ? (1 - power) : 1;
-			const int ms = iroundf((time - (float)seconds) * 1000.0f);
+			const int ms = round_fl_to_int((time - (float)seconds) * 1000.0f);
 
 			rlen = BLI_snprintf_rlen(
 			           str, maxncpy, "%s%02d:%02d:%02d,%0*d", neg, hours, minutes, seconds, ms_dp, ms);
@@ -183,7 +183,7 @@ size_t BLI_timecode_string_from_time(
 				rlen = BLI_snprintf_rlen(str, maxncpy, "%.*f", 1 - power, time_seconds);
 			}
 			else {
-				rlen = BLI_snprintf_rlen(str, maxncpy, "%d", iroundf(time_seconds));
+				rlen = BLI_snprintf_rlen(str, maxncpy, "%d", round_fl_to_int(time_seconds));
 			}
 			break;
 		}
@@ -250,7 +250,7 @@ size_t BLI_timecode_string_from_time_seconds(
 		rlen = BLI_snprintf_rlen(str, maxncpy, "%.*f", 1 - power, time_seconds);
 	}
 	else {
-		rlen = BLI_snprintf_rlen(str, maxncpy, "%d", iroundf(time_seconds));
+		rlen = BLI_snprintf_rlen(str, maxncpy, "%d", round_fl_to_int(time_seconds));
 	}
 
 	return rlen;
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index 5852ee72b19..dba060bfb29 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -4458,8 +4458,8 @@ void ANIM_channel_draw_widgets(const bContext *C, bAnimContext *ac, bAnimListEle
 		 *       a callback available (e.g. broken F-Curve rename)
 		 */
 		if (acf->name_prop(ale, &ptr, &prop)) {
-			const short margin_x = 3 * iroundf(UI_DPI_FAC);
-			const short channel_height = iroundf(ymaxc - yminc);
+			const short margin_x = 3 * round_fl_to_int(UI_DPI_FAC);
+			const short channel_height = round_fl_to_int(ymaxc - yminc);
 			const short width = ac->ar->winx - offset - (margin_x * 2);
 			uiBut *but;
 			
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index be01f8cbe69..efcc3e9477c 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -149,7 +149,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f
 					    (side == 'L' && marker->frame < cfra) ||
 					    (side == 'R' && marker->frame >= cfra))
 					{
-						marker->frame += iroundf(value);
+						marker->frame += round_fl_to_int(value);
 						changed_tot++;
 					}
 					break;
@@ -157,7 +157,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f
 				case TFM_TIME_SCALE:
 				{
 					/* rescale the distance between the marker and the current frame */
-					marker->frame = cfra + iroundf((float)(marker->frame - cfra) * value);
+					marker->frame = cfra + round_fl_to_int((float)(marker->frame - cfra) * value);
 					changed_tot++;
 					break;
 				}
@@ -195,7 +195,7 @@ TimeMarker *ED_markers_find_nearest_marker(ListBase *markers, float x)
 int ED_markers_find_nearest_marker_time(ListBase *markers, float x)
 {
 	TimeMarker *nearest = ED_markers_find_nearest_marker(markers, x);
-	return (nearest) ? (nearest->frame) : iroundf(x);
+	return (nearest) ? (nearest->frame) : round_fl_to_int(x);
 }
 
 
diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c
index 0eb6508f7b2..fcdd45d4ac3 100644
--- a/source/blender/editors/animation/anim_ops.c
+++ b/source/blender/editors/animation/anim_ops.c
@@ -108,7 +108,7 @@ static void change_frame_apply(bContext *C, wmOperator *op)
 		SUBFRA = frame - (int)frame;
 	}
 	else {
-		CFRA = iroundf(frame);
+		CFRA = round_fl_to_int(frame);
 		SUBFRA = 0.0f;
 	}
 	FRAMENUMBER_MIN_CLAMP(CFRA);
@@ -301,8 +301,8 @@ static int previewrange_define_exec(bContext *C, wmOperator *op)
 	if (efra < sfra) efra = sfra;
 	
 	scene->r.flag |= SCER_PRV_RANGE;
-	scene->r.psfra = iroundf(sfra);
-	scene->r.pefra = iroundf(efra);
+	scene->r.psfra = round_fl_to_int(sfra);
+	scene->r.pefra = round_fl_to_int(efra);
 	
 	/* send notifiers */
 	WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c
index 84a94ff87dd..f62073d56ef 100644
--- a/source/blender/editors/armature/pose_slide.c
+++ b/source/blender/editors/armature/pose_slide.c
@@ -1481,7 +1481,7 @@ static void pose_propagate_fcurve(wmOperator *op, Object *ob, FCurve *fcu,
 			
 			/* stop on matching marker if there is one */
 			for (ce = modeData.sel_markers.first; ce; ce = ce->next) {
-				if (ce->cfra == iroundf(bezt->vec[1][0]))
+				if (ce->cfra == round_fl_to_int(bezt->vec[1][0]))
 					break;
 			}
 			
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index ecab37c729f..c08ed0db400 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1732,10 +1732,10 @@ void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, AReg
 		rctf rectf;
 		ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, true); /* no shift */
 		
-		offsx = iroundf(rectf.xmin);
-		offsy = iroundf(rectf.ymin);
-		winx  = iroundf(rectf.xmax - rectf.xmin);
-		winy  = iroundf(rectf.ymax - rectf.ymin);
+		offsx = round_fl_to_int(rectf.xmin);
+		offsy = round_fl_to_int(rectf.ymin);
+		winx  = round_fl_to_int(rectf.xmax - rectf.xmin);
+		winy  = round_fl_to_int(rectf.ymax - rectf.ymin);
 	}
 	else {
 		offsx = 0;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 031011ddaee..5349744af6c 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4295,7 +4295,7 @@ static bool ui_numedit_but_NUM(
 
 
 		if (!is_float) {
-			temp = iroundf(tempf);
+			temp = round_fl_to_int(tempf);
 
 			temp = ui_numedit_apply_snap(temp, softmin, softmax, snap);
 
@@ -4580,7 +4580

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list