Commit: 9670c649d86cbc6a54967b5cb91d745595f0884c
Author: Ramil Roosileht
Date:   Fri Jun 10 11:15:47 2022 +0200
Branches: master
https://developer.blender.org/rB9670c649d86cbc6a54967b5cb91d745595f0884c

Fix regression in the recent unit system change

Resolves unit tests failure since the D15085.
Also addressed API documentation and formatting format.

Differential Revision: https://developer.blender.org/D15162

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

M       source/blender/blenkernel/BKE_unit.h
M       source/blender/blenkernel/intern/unit.c

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

diff --git a/source/blender/blenkernel/BKE_unit.h 
b/source/blender/blenkernel/BKE_unit.h
index 823d32f83ba..f051335fc41 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -19,6 +19,10 @@ struct UnitSettings;
  */
 size_t BKE_unit_value_as_string_adaptive(
     char *str, int len_max, double value, int prec, int system, int type, bool 
split, bool pad);
+/**
+ * Representation of a value in units. Negative precision is used to disable 
stripping of zeroes.
+ * This reduces text jumping when changing values.
+ */
 size_t BKE_unit_value_as_string(char *str,
                                 int len_max,
                                 double value,
diff --git a/source/blender/blenkernel/intern/unit.c 
b/source/blender/blenkernel/intern/unit.c
index 557fb2568fe..b31632f0234 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -462,11 +462,6 @@ static size_t unit_as_string(char *str,
   double value_conv = (value / unit->scalar) - unit->bias;
   bool strip_skip = false;
 
-  /* Adjust precision to expected number of significant digits.
-   * Note that here, we shall not have to worry about very big/small numbers, 
units are expected
-   * to replace 'scientific notation' in those cases. */
-  prec -= integer_digits_d(value_conv);
-
   /* Negative precision is used to disable stripping of zeroes.
    * This reduces text jumping when changing values. */
   if (prec < 0) {
@@ -474,6 +469,11 @@ static size_t unit_as_string(char *str,
     prec *= -1;
   }
 
+  /* Adjust precision to expected number of significant digits.
+   * Note that here, we shall not have to worry about very big/small numbers, 
units are expected
+   * to replace 'scientific notation' in those cases. */
+  prec -= integer_digits_d(value_conv);
+
   CLAMP(prec, 0, 6);
 
   /* Convert to a string. */
@@ -491,10 +491,10 @@ static size_t unit_as_string(char *str,
       while (i > 0 && str[i] == '0') { /* 4.300 -> 4.3 */
         str[i--] = pad;
       }
-    }
 
-    if (i > 0 && str[i] == '.') { /* 10. -> 10 */
-      str[i--] = pad;
+      if (i > 0 && str[i] == '.') { /* 10. -> 10 */
+        str[i--] = pad;
+      }
     }
   }

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

Reply via email to