44 #define TEMP_STR_SIZE 256
51 #define UN_SC_KM 1000.0f
52 #define UN_SC_HM 100.0f
53 #define UN_SC_DAM 10.0f
56 #define UN_SC_CM 0.01f
57 #define UN_SC_MM 0.001f
58 #define UN_SC_UM 0.000001f
60 #define UN_SC_MI 1609.344f
61 #define UN_SC_FUR 201.168f
62 #define UN_SC_CH 20.1168f
63 #define UN_SC_YD 0.9144f
64 #define UN_SC_FT 0.3048f
65 #define UN_SC_IN 0.0254f
66 #define UN_SC_MIL 0.0000254f
68 #define UN_SC_MTON 1000.0f
69 #define UN_SC_QL 100.0f
72 #define UN_SC_DAG 0.01f
73 #define UN_SC_G 0.001f
74 #define UN_SC_MG 0.000001f
76 #define UN_SC_ITON 907.18474f
77 #define UN_SC_CWT 45.359237f
78 #define UN_SC_ST 6.35029318f
79 #define UN_SC_LB 0.45359237f
80 #define UN_SC_OZ 0.028349523125f
82 #define UN_SC_FAH 0.555555555555f
136 #define UNIT_COLLECTION_LENGTH(def) (ARRAY_SIZE(def) - 1)
137 #define NULL_UNIT {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
271 {
"meter per second squared",
"meters per second squared",
"m/s²",
"m/s2",
"Meters per second squared",
NULL,
UN_SC_M, 0.0,
B_UNIT_DEF_NONE},
277 {
"foot per second squared",
"feet per second squared",
"ft/s²",
"ft/s2",
"Feet per second squared",
NULL,
UN_SC_FT, 0.0,
B_UNIT_DEF_NONE},
286 {
"hour",
"hours",
"hr",
"h",
"Hours",
"HOURS", 3600.0, 0.0,
B_UNIT_DEF_NONE},
287 {
"minute",
"minutes",
"min",
"m",
"Minutes",
"MINUTES", 60.0, 0.0,
B_UNIT_DEF_NONE},
288 {
"second",
"seconds",
"sec",
"s",
"Seconds",
"SECONDS", 1.0, 0.0,
B_UNIT_DEF_NONE},
289 {
"millisecond",
"milliseconds",
"ms",
NULL,
"Milliseconds",
"MILLISECONDS", 0.001, 0.0,
B_UNIT_DEF_NONE},
290 {
"microsecond",
"microseconds",
"µs",
"us",
"Microseconds",
"MICROSECONDS", 0.000001, 0.0,
B_UNIT_DEF_NONE},
336 {
"celsius",
"celsius",
"°C",
"C",
"Celsius",
"CELSIUS", 1.0f, 273.15,
B_UNIT_DEF_NONE},
351 #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)
392 {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL},
412 double value_abs = value > 0.0 ? value : -value;
414 for (
const bUnitDef *unit = unit_start ? unit_start : usys->
units; unit->
name; unit++) {
422 if (value_abs >= unit->scalar * (0.1 -
EPS)) {
427 if (value_abs >= unit->scalar * (1.0 -
EPS)) {
448 *r_value_b = value - (*r_value_a);
473 double value_conv = (value / unit->
scalar) - unit->
bias;
492 while (i > 0 &&
str[i] ==
'0') {
496 if (i > 0 &&
str[i] ==
'.') {
510 while (unit->
name_short[j] && (i < len_max)) {
559 double value_a, value_b;
563 if (unit_b > unit_a) {
571 if (i + 2 < len_max) {
595 int max_offset = usys->
length - 1;
617 return usys->
units + 0;
620 return usys->
units + 3;
662 return unit_as_string(
str, len_max, value, prec, usys, main_unit, pad ?
' ' :
'\0');
666 char *
str,
int len_max,
double value,
int prec,
int system,
int type,
bool split,
bool pad)
693 return (ch >= 128 || isalpha(ch));
698 if (substr ==
NULL || substr[0] ==
'\0') {
704 const char *str_found;
705 if (case_sensitive) {
706 str_found = strstr(
str, substr);
714 if (str_found ==
str ||
719 int len_name = strlen(substr);
778 char *str_found = strstr(remaining_str,
"-");
780 if (str_found ==
NULL) {
785 if ((str_found !=
str) &&
ELEM(*(str_found - 1),
'e',
'E')) {
789 if (*(str_found + 1) ==
' ') {
793 return str_found + 1;
805 for (i = 0; i < len_max; i++) {
806 if (remaining_str[i] ==
'\0') {
807 return remaining_str + i;
812 if (remaining_str !=
str && i != 0) {
814 if ((remaining_str[i] ==
'/') &&
ELEM(remaining_str[i - 1],
't',
'T',
'm',
'M') &&
815 ELEM(remaining_str[i + 1],
's',
'S')) {
820 if (
ELEM(remaining_str[i - 1],
'e',
'E')) {
825 if (remaining_str[i - 1] ==
' ') {
830 return remaining_str + i;
833 BLI_assert(!
"String should be NULL terminated");
834 return remaining_str + i;
845 bool changed =
false;
847 char *remaining_str =
str;
848 int remaining_str_len = len_max;
851 remaining_str_len = len_max - (int)(remaining_str -
str);
852 if (remaining_str_len <= 2) {
859 memmove(remaining_str + 1, remaining_str, remaining_str_len - 2);
860 *remaining_str =
'(';
863 remaining_str =
find_next_op(
str, remaining_str + 1, remaining_str_len);
864 remaining_str_len = len_max - (int)(remaining_str -
str);
865 memmove(remaining_str + 1, remaining_str, remaining_str_len - 2);
866 *remaining_str =
')';
882 for (
int i = start_ofs; i > 0; i--) {
897 for (i = start_ofs; i < len_max; i++) {
898 if (!strchr(
"0123456789eE.",
str[i])) {
910 const char *replace_str,
920 if (str_found ==
NULL) {
924 int found_ofs = (int)(str_found -
str);
933 if (unit->
bias != 0.0) {
936 if (
len + 1 < len_max) {
937 memmove(
str + prev_op_ofs + 1,
str + prev_op_ofs,
len - prev_op_ofs + 1);
938 str[prev_op_ofs] =
'(';
947 if (value_end_ofs + len_bias_num < len_max) {
948 memmove(
str + value_end_ofs + len_bias_num,
str + value_end_ofs,
len - value_end_ofs + 1);
949 memcpy(
str + value_end_ofs, str_tmp, len_bias_num);
951 found_ofs += len_bias_num;
952 str_found += len_bias_num;
956 int len_name = strlen(replace_str);
957 int len_move = (
len - (found_ofs + len_name)) + 1;
962 if (len_num > len_max) {
966 if (found_ofs + len_num + len_move > len_max) {
968 len_move -= (found_ofs + len_num + len_move) - len_max;
974 memmove(str_found + len_num, str_found + len_name, len_move);
977 if (found_ofs + len_num > len_max) {
979 len_num -= (found_ofs + len_num) - len_max;
984 memcpy(str_found, str_tmp, len_num);
989 str[len_max - 1] =
'\0';
990 return found_ofs + len_num;
994 char *
str,
int len_max,
char *str_tmp,
double scale_pref,
const bUnitDef *unit)
999 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_short, case_sensitive);
1001 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_plural,
false);
1003 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_alt, case_sensitive);
1035 const char *str_prev)
1040 for (unit = usys->
units; unit->
name; unit++) {
1046 if (str_prev && (unit ==
NULL || unit->
name ==
NULL)) {
1048 for (unit = usys->
units; unit->
name; unit++) {
1070 for (
int i = 0; i < usys->
length; i++) {
1085 const double bias = (unit ==
NULL) ? 0.0 : unit->
bias;
1087 return value * scalar + bias;
1107 char *
str,
int len_max,
const char *str_prev,
double scale_pref,
int system,
int type)
1114 double scale_pref_base = scale_pref;
1116 bool changed =
false;
1126 scale_pref_base *= default_unit->
scalar;
1132 strncpy(
str, str_tmp, len_max);
1152 for (
int system_iter = 0; system_iter <
UNIT_SYSTEM_TOT; system_iter++) {
1153 if (system_iter != system) {
1159 while ((ofs =
unit_replace(
str + ofs, len_max - ofs, str_tmp, scale_pref_base, unit))) {
1172 char *str_found =
str;
1173 const char *ch =
str;
1175 while ((str_found = strchr(str_found,
SEP_CHR))) {
1176 bool op_found =
false;
1179 for (ch = str_found + 1; *ch !=
'\0'; ch++) {
1180 if (
ELEM(*ch,
' ',
'\t')) {
1188 *str_found++ = op_found ?
' ' :
'+';
1202 if (len_max > 0 && unit->name_alt) {
1204 const char *found =
unit_find_str(orig_str, unit->name_short, case_sensitive);
1206 int offset = (int)(found - orig_str);
1210 offset = (offset < len_max ? offset : len_max);
1211 strncpy(
str, orig_str, offset);
1214 orig_str += offset + strlen(unit->name_short);
1218 if (unit->name_alt) {
1225 len_name = (len_name < len_max ? len_name : len_max);
1227 len_max -= len_name;
1233 strncpy(
str, orig_str, len_max);
1302 BLI_assert(
false &&
"identifier for this unit is not specified yet");
MINLINE int integer_digits_d(const double d)
MINLINE int max_ii(int a, int b)
char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_str_prev_char_utf8(const char *p) ATTR_NONNULL()
Compatibility-like things for windows.
#define USER_UNIT_OPT_SPLIT
#define USER_UNIT_ROT_RADIANS
#define USER_UNIT_ADAPTIVE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Group RGB to Bright Vector Camera CLAMP
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
const struct bUnitDef * units
const char * name_display
static struct bUnitCollection buMetricTempCollection
static int find_end_of_value_chars(const char *str, const int len_max, const int start_ofs)
static struct bUnitDef buImperialLenDef[]
int BKE_unit_base_of_type_get(int system, int type)
static struct bUnitCollection buNaturalTimeCollection
@ B_UNIT_DEF_CASE_SENSITIVE
static const struct bUnitCollection * bUnitSystems[][B_UNIT_TYPE_TOT]
static PreferredUnits preferred_units_from_UnitSettings(const UnitSettings *settings)
static char * find_next_op(const char *str, char *remaining_str, int len_max)
static struct bUnitDef buMetricAreaDef[]
static struct bUnitCollection buCameraLenCollection
static struct bUnitDef buCameraLenDef[]
static struct bUnitDef buMetricAclDef[]
static struct bUnitCollection buImperialLenCollection
static struct bUnitDef buMetricVelDef[]
static char * find_next_negative(const char *str, const char *remaining_str)
static struct bUnitCollection buImperialVelCollection
bool BKE_unit_is_valid(int system, int type)
static struct bUnitCollection buMetricVolCollection
static struct bUnitDef buMetricMassDef[]
static const bUnitCollection * unit_get_system(int system, int type)
static struct bUnitCollection buDummyCollection
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)
static struct bUnitCollection buMetricAclCollection
static struct bUnitCollection buPowerCollection
static void unit_dual_convert(double value, const bUnitCollection *usys, bUnitDef const **r_unit_a, bUnitDef const **r_unit_b, double *r_value_a, double *r_value_b, const bUnitDef *main_unit)
static bool is_valid_unit_collection(const bUnitCollection *usys)
const char * BKE_unit_display_name_get(const void *usys_pt, int index)
static const struct bUnitCollection buMetricLenCollection
bool BKE_unit_is_suppressed(const void *usys_pt, int index)
#define UNIT_COLLECTION_LENGTH(def)
void BKE_unit_system_get(int system, int type, void const **r_usys_pt, int *r_len)
static struct bUnitCollection buImperialVolCollection
static const bUnitDef * unit_best_fit(double value, const bUnitCollection *usys, const bUnitDef *unit_start, int suppress)
static int unit_replace(char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit)
static struct bUnitDef buMetricTempDef[]
void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type)
static struct bUnitCollection buMetricMassCollection
static struct bUnitDef buNaturalTimeDef[]
static struct bUnitDef buImperialAclDef[]
static const bUnitDef * unit_detect_from_str(const bUnitCollection *usys, const char *str, const char *str_prev)
const char * BKE_unit_identifier_get(const void *usys_pt, int index)
static size_t unit_as_string_split_pair(char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *main_unit)
static bool unit_find(const char *str, const bUnitDef *unit)
int BKE_unit_base_get(const void *usys_pt)
static struct bUnitCollection buImperialAreaCollection
static struct bUnitDef buImperialMassDef[]
static size_t unit_as_string(char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *unit, char pad)
double BKE_unit_scalar_get(const void *usys_pt, int index)
static struct bUnitDef buPowerDef[]
static struct bUnitDef buImperialTempDef[]
static bool ch_is_op(char op)
double BKE_unit_closest_scalar(double value, int system, int type)
static struct bUnitDef buImperialVolDef[]
static struct bUnitCollection buImperialMassCollection
static size_t unit_as_string_main(char *str, int len_max, double value, int prec, int type, bool split, bool pad, PreferredUnits units)
static struct bUnitCollection buImperialTempCollection
size_t BKE_unit_value_as_string(char *str, int len_max, double value, int prec, int type, const UnitSettings *settings, bool pad)
static struct bUnitDef buMetricLenDef[]
bool BKE_unit_replace_string(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type)
double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int type, double value)
static int find_previous_non_value_char(const char *str, const int start_ofs)
static struct bUnitCollection buImperialAclCollection
double BKE_unit_base_scalar(int system, int type)
struct bUnitCollection bUnitCollection
static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit, const char *replace_str, bool case_sensitive)
static struct bUnitDef buMetricVolDef[]
static const bUnitDef * unit_default(const bUnitCollection *usys)
static const char * unit_find_str(const char *str, const char *substr, bool case_sensitive)
bool BKE_unit_string_contains_unit(const char *str, int type)
static struct bUnitCollection buMetricAreaCollection
static struct bUnitCollection buMetricVelCollection
static struct bUnitDef buImperialVelDef[]
const char * BKE_unit_name_get(const void *usys_pt, int index)
static struct bUnitCollection buNaturalRotCollection
static bool unit_distribute_negatives(char *str, const int len_max)
static struct bUnitDef buImperialAreaDef[]
static const bUnitDef * get_preferred_display_unit_if_used(int type, PreferredUnits units)
static struct bUnitDef buDummyDef[]
static struct bUnitDef buNaturalRotDef[]
BLI_INLINE bool isalpha_or_utf8(const int ch)
static bool unit_should_be_split(int type)
ccl_device_inline float2 floor(const float2 &a)
ccl_device_inline float3 ceil(const float3 &a)