[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37286] trunk/blender/source/blender/ editors/interface/interface.c: smarter precision calculation, so 0. 000001 isn't displayed as 0.00.
Campbell Barton
ideasman42 at gmail.com
Tue Jun 7 06:06:11 CEST 2011
Revision: 37286
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37286
Author: campbellbarton
Date: 2011-06-07 04:06:10 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
smarter precision calculation, so 0.000001 isn't displayed as 0.00.
there is a minor problem with this commit:
0.00001 --> 0.00001 # good
0.000015 --> 0.000015 # good
0.0000199 --> 0.00002 # ok
0.00002 --> 0.000020 # wrong, has trailing 0
Tried to fix this but the case is hard to check for without more calculations which Id like to avoid.
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface.c
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2011-06-07 02:39:40 UTC (rev 37285)
+++ trunk/blender/source/blender/editors/interface/interface.c 2011-06-07 04:06:10 UTC (rev 37286)
@@ -449,11 +449,36 @@
/* link line drawing is not part of buttons or theme.. so we stick with it here */
-static int ui_but_float_precision(uiBut *but, double UNUSED(value))
+static int ui_but_float_precision(uiBut *but, double value)
{
- int prec= (int)but->a2;
- if(prec==0) prec= (but->hardmax < 10.001f) ? 3 : 2;
- else CLAMP(prec, 1, 7);
+ int prec;
+
+ /* first check if prec is 0 and fallback to a simple default */
+ if((prec= (int)but->a2) == 0) {
+ prec= (but->hardmax < 10.001f) ? 3 : 2;
+ }
+
+ /* check on the number of decimal places neede to display
+ * the number, this is so 0.00001 is not displayed as 0.00,
+ * _but_, this is only for small values si 10.0001 will not get
+ * the same treatment */
+ if(value != 0.0 && (value= ABS(value)) < 0.1) {
+ double prec_d= -(log10(value));
+ double prec_d_floor = floor(prec_d + FLT_EPSILON);
+ int test_prec= (int)prec_d_floor;
+
+ /* this check is so 0.00016 from isnt rounded to 0.0001 _but_ it is not working ideally because 0.0002 becomes 0.00020 */
+ if(prec_d - prec_d_floor > FLT_EPSILON) {
+ test_prec += 2;
+ }
+
+ if(test_prec > prec && test_prec <= 7) {
+ prec= test_prec;
+ }
+ }
+
+ CLAMP(prec, 1, 7);
+
return prec;
}
More information about the Bf-blender-cvs
mailing list