[Bf-blender-cvs] [fa257ad] master: Fix some loss of precision in BKE's unit code.
Bastien Montagne
noreply at git.blender.org
Tue Jun 17 16:08:52 CEST 2014
Commit: fa257adf9644b7c3da28bf4041b77f49f497fb86
Author: Bastien Montagne
Date: Tue Jun 17 16:06:12 2014 +0200
https://developer.blender.org/rBfa257adf9644b7c3da28bf4041b77f49f497fb86
Fix some loss of precision in BKE's unit code.
When converting text to value, units' "value" had only 6 digits of precision,
leading to annoying loss of precision esp. when mixing big and small units
(like e.g. miles and inches).
===================================================================
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 07aeced..5988172 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -61,17 +61,19 @@ const char *bUnit_GetNameDisplay(void *usys_pt, int index);
double bUnit_GetScaler(void *usys_pt, int index);
/* aligned with PropertyUnit */
-#define B_UNIT_NONE 0
-#define B_UNIT_LENGTH 1
-#define B_UNIT_AREA 2
-#define B_UNIT_VOLUME 3
-#define B_UNIT_MASS 4
-#define B_UNIT_ROTATION 5
-#define B_UNIT_TIME 6
-#define B_UNIT_VELOCITY 7
-#define B_UNIT_ACCELERATION 8
-#define B_UNIT_CAMERA 9
-#define B_UNIT_TYPE_TOT 10
+enum {
+ B_UNIT_NONE = 0,
+ B_UNIT_LENGTH = 1,
+ B_UNIT_AREA = 2,
+ B_UNIT_VOLUME = 3,
+ B_UNIT_MASS = 4,
+ B_UNIT_ROTATION = 5,
+ B_UNIT_TIME = 6,
+ B_UNIT_VELOCITY = 7,
+ B_UNIT_ACCELERATION = 8,
+ B_UNIT_CAMERA = 9,
+ B_UNIT_TYPE_TOT = 10,
+};
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index de6424f..8aca9f7 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -536,7 +536,7 @@ static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pr
len_name = strlen(replace_str);
len_move = (len - (found_ofs + len_name)) + 1; /* 1+ to copy the string terminator */
- len_num = BLI_snprintf(str_tmp, TEMP_STR_SIZE, "*%g"SEP_STR, unit->scalar / scale_pref); /* # removed later */
+ len_num = BLI_snprintf(str_tmp, TEMP_STR_SIZE, "*%.9g"SEP_STR, unit->scalar / scale_pref); /* # removed later */
if (len_num > len_max)
len_num = len_max;
@@ -598,7 +598,7 @@ static int unit_find(const char *str, bUnitDef *unit)
* ...will be resolved by python.
*
* values will be split by a comma's
- * 5'2" -> 5'0.0254, 2*0.3048
+ * 5'2" -> 5*0.3048, 2*0.0254
*
* str_prev is optional, when valid it is used to get a base unit when none is set.
*
More information about the Bf-blender-cvs
mailing list