Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions | Variables
unit.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_sys_types.h"
#include "DNA_scene_types.h"
#include "BKE_unit.h"

Go to the source code of this file.

Classes

struct  bUnitDef
 
struct  bUnitCollection
 
struct  PreferredUnits
 

Macros

#define TEMP_STR_SIZE   256
 
#define SEP_CHR   '#'
 
#define SEP_STR   "#"
 
#define EPS   0.001
 
#define UN_SC_KM   1000.0f
 
#define UN_SC_HM   100.0f
 
#define UN_SC_DAM   10.0f
 
#define UN_SC_M   1.0f
 
#define UN_SC_DM   0.1f
 
#define UN_SC_CM   0.01f
 
#define UN_SC_MM   0.001f
 
#define UN_SC_UM   0.000001f
 
#define UN_SC_MI   1609.344f
 
#define UN_SC_FUR   201.168f
 
#define UN_SC_CH   20.1168f
 
#define UN_SC_YD   0.9144f
 
#define UN_SC_FT   0.3048f
 
#define UN_SC_IN   0.0254f
 
#define UN_SC_MIL   0.0000254f
 
#define UN_SC_MTON   1000.0f /* Metric ton. */
 
#define UN_SC_QL   100.0f
 
#define UN_SC_KG   1.0f
 
#define UN_SC_HG   0.1f
 
#define UN_SC_DAG   0.01f
 
#define UN_SC_G   0.001f
 
#define UN_SC_MG   0.000001f
 
#define UN_SC_ITON   907.18474f /* Imperial ton. */
 
#define UN_SC_CWT   45.359237f
 
#define UN_SC_ST   6.35029318f
 
#define UN_SC_LB   0.45359237f
 
#define UN_SC_OZ   0.028349523125f
 
#define UN_SC_FAH   0.555555555555f
 
#define UNIT_COLLECTION_LENGTH(def)   (ARRAY_SIZE(def) - 1)
 
#define NULL_UNIT   {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
 
#define UNIT_SYSTEM_TOT   (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)
 

Typedefs

typedef struct bUnitDef bUnitDef
 
typedef struct bUnitCollection bUnitCollection
 

Enumerations

enum  {
  B_UNIT_DEF_NONE = 0 , B_UNIT_DEF_SUPPRESS = 1 , B_UNIT_DEF_TENTH = 2 , B_UNIT_DEF_CASE_SENSITIVE = 4 ,
  B_UNIT_DEF_NO_SPACE = 8
}
 

Functions

static const bUnitCollectionunit_get_system (int system, int type)
 
static const bUnitDefunit_default (const bUnitCollection *usys)
 
static const bUnitDefunit_best_fit (double value, const bUnitCollection *usys, const bUnitDef *unit_start, int suppress)
 
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 size_t unit_as_string (char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *unit, char pad)
 
static bool unit_should_be_split (int type)
 
static PreferredUnits preferred_units_from_UnitSettings (const UnitSettings *settings)
 
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 is_valid_unit_collection (const bUnitCollection *usys)
 
static const bUnitDefget_preferred_display_unit_if_used (int type, PreferredUnits units)
 
static size_t unit_as_string_main (char *str, int len_max, double value, int prec, int type, bool split, bool pad, PreferredUnits units)
 
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)
 
size_t BKE_unit_value_as_string (char *str, int len_max, double value, int prec, int type, const UnitSettings *settings, bool pad)
 
BLI_INLINE bool isalpha_or_utf8 (const int ch)
 
static const char * unit_find_str (const char *str, const char *substr, bool case_sensitive)
 
static bool ch_is_op (char op)
 
static char * find_next_negative (const char *str, const char *remaining_str)
 
static char * find_next_op (const char *str, char *remaining_str, int len_max)
 
static bool unit_distribute_negatives (char *str, const int len_max)
 
static int find_previous_non_value_char (const char *str, const int start_ofs)
 
static int find_end_of_value_chars (const char *str, const int len_max, const int start_ofs)
 
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 int unit_replace (char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit)
 
static bool unit_find (const char *str, const bUnitDef *unit)
 
static const bUnitDefunit_detect_from_str (const bUnitCollection *usys, const char *str, const char *str_prev)
 
bool BKE_unit_string_contains_unit (const char *str, int type)
 
double BKE_unit_apply_preferred_unit (const struct UnitSettings *settings, int type, double value)
 
bool BKE_unit_replace_string (char *str, int len_max, const char *str_prev, double scale_pref, int system, int type)
 
void BKE_unit_name_to_alt (char *str, int len_max, const char *orig_str, int system, int type)
 
double BKE_unit_closest_scalar (double value, int system, int type)
 
double BKE_unit_base_scalar (int system, int type)
 
bool BKE_unit_is_valid (int system, int type)
 
void BKE_unit_system_get (int system, int type, void const **r_usys_pt, int *r_len)
 
int BKE_unit_base_get (const void *usys_pt)
 
int BKE_unit_base_of_type_get (int system, int type)
 
const char * BKE_unit_name_get (const void *usys_pt, int index)
 
const char * BKE_unit_display_name_get (const void *usys_pt, int index)
 
const char * BKE_unit_identifier_get (const void *usys_pt, int index)
 
double BKE_unit_scalar_get (const void *usys_pt, int index)
 
bool BKE_unit_is_suppressed (const void *usys_pt, int index)
 

Variables

static struct bUnitDef buDummyDef [] = { {"", NULL, "", NULL, NULL, NULL, 1.0, 0.0}, NULL_UNIT}
 
static struct bUnitCollection buDummyCollection = {buDummyDef, 0, 0, sizeof(buDummyDef)}
 
static struct bUnitDef buMetricLenDef []
 
static const struct bUnitCollection buMetricLenCollection = {buMetricLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricLenDef)}
 
static struct bUnitDef buImperialLenDef []
 
static struct bUnitCollection buImperialLenCollection = {buImperialLenDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialLenDef)}
 
static struct bUnitDef buMetricAreaDef []
 
static struct bUnitCollection buMetricAreaCollection = {buMetricAreaDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricAreaDef)}
 
static struct bUnitDef buImperialAreaDef []
 
static struct bUnitCollection buImperialAreaCollection = {buImperialAreaDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialAreaDef)}
 
static struct bUnitDef buMetricVolDef []
 
static struct bUnitCollection buMetricVolCollection = {buMetricVolDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricVolDef)}
 
static struct bUnitDef buImperialVolDef []
 
static struct bUnitCollection buImperialVolCollection = {buImperialVolDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialVolDef)}
 
static struct bUnitDef buMetricMassDef []
 
static struct bUnitCollection buMetricMassCollection = {buMetricMassDef, 2, 0, UNIT_COLLECTION_LENGTH(buMetricMassDef)}
 
static struct bUnitDef buImperialMassDef []
 
static struct bUnitCollection buImperialMassCollection = {buImperialMassDef, 3, 0, UNIT_COLLECTION_LENGTH(buImperialMassDef)}
 
static struct bUnitDef buMetricVelDef []
 
static struct bUnitCollection buMetricVelCollection = {buMetricVelDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricVelDef)}
 
static struct bUnitDef buImperialVelDef []
 
static struct bUnitCollection buImperialVelCollection = {buImperialVelDef, 0, 0, UNIT_COLLECTION_LENGTH(buImperialVelDef)}
 
static struct bUnitDef buMetricAclDef []
 
static struct bUnitCollection buMetricAclCollection = {buMetricAclDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricAclDef)}
 
static struct bUnitDef buImperialAclDef []
 
static struct bUnitCollection buImperialAclCollection = {buImperialAclDef, 0, 0, UNIT_COLLECTION_LENGTH(buImperialAclDef)}
 
static struct bUnitDef buNaturalTimeDef []
 
static struct bUnitCollection buNaturalTimeCollection = {buNaturalTimeDef, 3, 0, UNIT_COLLECTION_LENGTH(buNaturalTimeDef)}
 
static struct bUnitDef buNaturalRotDef []
 
static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, UNIT_COLLECTION_LENGTH(buNaturalRotDef)}
 
static struct bUnitDef buCameraLenDef []
 
static struct bUnitCollection buCameraLenCollection = {buCameraLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buCameraLenDef)}
 
static struct bUnitDef buPowerDef []
 
static struct bUnitCollection buPowerCollection = {buPowerDef, 3, 0, UNIT_COLLECTION_LENGTH(buPowerDef)}
 
static struct bUnitDef buMetricTempDef []
 
static struct bUnitCollection buMetricTempCollection = {buMetricTempDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricTempDef)}
 
static struct bUnitDef buImperialTempDef []
 
static struct bUnitCollection buImperialTempCollection
 
static const struct bUnitCollectionbUnitSystems [][B_UNIT_TYPE_TOT]
 

Macro Definition Documentation

◆ EPS

#define EPS   0.001

Definition at line 35 of file unit.c.

◆ NULL_UNIT

#define NULL_UNIT   {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}

Definition at line 123 of file unit.c.

◆ SEP_CHR

#define SEP_CHR   '#'

Definition at line 32 of file unit.c.

◆ SEP_STR

#define SEP_STR   "#"

Definition at line 33 of file unit.c.

◆ TEMP_STR_SIZE

#define TEMP_STR_SIZE   256

Definition at line 30 of file unit.c.

◆ UN_SC_CH

#define UN_SC_CH   20.1168f

Definition at line 48 of file unit.c.

◆ UN_SC_CM

#define UN_SC_CM   0.01f

Definition at line 42 of file unit.c.

◆ UN_SC_CWT

#define UN_SC_CWT   45.359237f

Definition at line 63 of file unit.c.

◆ UN_SC_DAG

#define UN_SC_DAG   0.01f

Definition at line 58 of file unit.c.

◆ UN_SC_DAM

#define UN_SC_DAM   10.0f

Definition at line 39 of file unit.c.

◆ UN_SC_DM

#define UN_SC_DM   0.1f

Definition at line 41 of file unit.c.

◆ UN_SC_FAH

#define UN_SC_FAH   0.555555555555f

Definition at line 68 of file unit.c.

◆ UN_SC_FT

#define UN_SC_FT   0.3048f

Definition at line 50 of file unit.c.

◆ UN_SC_FUR

#define UN_SC_FUR   201.168f

Definition at line 47 of file unit.c.

◆ UN_SC_G

#define UN_SC_G   0.001f

Definition at line 59 of file unit.c.

◆ UN_SC_HG

#define UN_SC_HG   0.1f

Definition at line 57 of file unit.c.

◆ UN_SC_HM

#define UN_SC_HM   100.0f

Definition at line 38 of file unit.c.

◆ UN_SC_IN

#define UN_SC_IN   0.0254f

Definition at line 51 of file unit.c.

◆ UN_SC_ITON

#define UN_SC_ITON   907.18474f /* Imperial ton. */

Definition at line 62 of file unit.c.

◆ UN_SC_KG

#define UN_SC_KG   1.0f

Definition at line 56 of file unit.c.

◆ UN_SC_KM

#define UN_SC_KM   1000.0f

Definition at line 37 of file unit.c.

◆ UN_SC_LB

#define UN_SC_LB   0.45359237f

Definition at line 65 of file unit.c.

◆ UN_SC_M

#define UN_SC_M   1.0f

Definition at line 40 of file unit.c.

◆ UN_SC_MG

#define UN_SC_MG   0.000001f

Definition at line 60 of file unit.c.

◆ UN_SC_MI

#define UN_SC_MI   1609.344f

Definition at line 46 of file unit.c.

◆ UN_SC_MIL

#define UN_SC_MIL   0.0000254f

Definition at line 52 of file unit.c.

◆ UN_SC_MM

#define UN_SC_MM   0.001f

Definition at line 43 of file unit.c.

◆ UN_SC_MTON

#define UN_SC_MTON   1000.0f /* Metric ton. */

Definition at line 54 of file unit.c.

◆ UN_SC_OZ

#define UN_SC_OZ   0.028349523125f

Definition at line 66 of file unit.c.

◆ UN_SC_QL

#define UN_SC_QL   100.0f

Definition at line 55 of file unit.c.

◆ UN_SC_ST

#define UN_SC_ST   6.35029318f

Definition at line 64 of file unit.c.

◆ UN_SC_UM

#define UN_SC_UM   0.000001f

Definition at line 44 of file unit.c.

◆ UN_SC_YD

#define UN_SC_YD   0.9144f

Definition at line 49 of file unit.c.

◆ UNIT_COLLECTION_LENGTH

#define UNIT_COLLECTION_LENGTH (   def)    (ARRAY_SIZE(def) - 1)

Definition at line 122 of file unit.c.

◆ UNIT_SYSTEM_TOT

#define UNIT_SYSTEM_TOT   (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)

Definition at line 337 of file unit.c.

Typedef Documentation

◆ bUnitCollection

◆ bUnitDef

typedef struct bUnitDef bUnitDef

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
B_UNIT_DEF_NONE 
B_UNIT_DEF_SUPPRESS 

Use for units that are not used enough to be translated into for common use.

B_UNIT_DEF_TENTH 

Display a unit even if its value is 0.1, eg 0.1mm instead of 100um.

B_UNIT_DEF_CASE_SENSITIVE 

Short unit name is case sensitive, for example to distinguish mW and MW.

B_UNIT_DEF_NO_SPACE 

Short unit name does not have space between it and preceding number.

Definition at line 96 of file unit.c.

Function Documentation

◆ BKE_unit_apply_preferred_unit()

double BKE_unit_apply_preferred_unit ( const struct UnitSettings settings,
int  type,
double  value 
)

If user does not specify a unit, this converts it to the unit from the settings.

Definition at line 1080 of file unit.c.

References bUnitDef::bias, BKE_unit_base_scalar(), get_preferred_display_unit_if_used(), NULL, preferred_units_from_UnitSettings(), bUnitDef::scalar, PreferredUnits::system, and type.

Referenced by user_string_to_number().

◆ BKE_unit_base_get()

int BKE_unit_base_get ( const void usys_pt)

Definition at line 1264 of file unit.c.

Referenced by ED_scene_grid_scale(), and ED_view3d_grid_steps().

◆ BKE_unit_base_of_type_get()

int BKE_unit_base_of_type_get ( int  system,
int  type 
)

Definition at line 1269 of file unit.c.

References bUnitCollection::base_unit, type, and unit_get_system().

Referenced by blo_do_versions_280(), and scene_init_data().

◆ BKE_unit_base_scalar()

double BKE_unit_base_scalar ( int  system,
int  type 
)

Base scale for these units.

Definition at line 1236 of file unit.c.

References bUnitDef::scalar, type, unit_default(), and unit_get_system().

Referenced by BKE_unit_apply_preferred_unit(), and ui_numedit_apply_snapf().

◆ BKE_unit_closest_scalar()

double BKE_unit_closest_scalar ( double  value,
int  system,
int  type 
)

The size of the unit used for this value (used for calculating the click-step).

Definition at line 1220 of file unit.c.

References NULL, bUnitDef::scalar, type, unit_best_fit(), and unit_get_system().

Referenced by ui_get_but_step_unit().

◆ BKE_unit_display_name_get()

const char* BKE_unit_display_name_get ( const void usys_pt,
int  index 
)

Definition at line 1278 of file unit.c.

Referenced by ED_scene_grid_scale(), and ED_view3d_grid_view_scale().

◆ BKE_unit_identifier_get()

const char* BKE_unit_identifier_get ( const void usys_pt,
int  index 
)

Definition at line 1282 of file unit.c.

References BLI_assert_msg, bUnitDef::identifier, and NULL.

◆ BKE_unit_is_suppressed()

bool BKE_unit_is_suppressed ( const void usys_pt,
int  index 
)

Definition at line 1296 of file unit.c.

References B_UNIT_DEF_SUPPRESS.

◆ BKE_unit_is_valid()

bool BKE_unit_is_valid ( int  system,
int  type 
)
Returns
true is the unit system exists.

Definition at line 1246 of file unit.c.

References B_UNIT_TYPE_TOT, and UNIT_SYSTEM_TOT.

Referenced by bpyunits_validate(), and ui_numedit_apply_snapf().

◆ BKE_unit_name_get()

const char* BKE_unit_name_get ( const void usys_pt,
int  index 
)

Definition at line 1274 of file unit.c.

◆ BKE_unit_name_to_alt()

void BKE_unit_name_to_alt ( char *  str,
int  len_max,
const char *  orig_str,
int  system,
int  type 
)

Make string keyboard-friendly, e.g: 10µm -> 10um.

Definition at line 1180 of file unit.c.

References B_UNIT_DEF_CASE_SENSITIVE, BLI_strncpy_rlen(), bUnitDef::name, offset, str, type, unit_find_str(), unit_get_system(), and bUnitCollection::units.

Referenced by bpyunits_to_string(), and ui_but_convert_to_unit_alt_name().

◆ BKE_unit_replace_string()

bool BKE_unit_replace_string ( char *  str,
int  len_max,
const char *  str_prev,
double  scale_pref,
int  system,
int  type 
)

Replace units with values, used before python button evaluation.

Make a copy of the string that replaces the units with numbers. This is only used when evaluating user input and can afford to be a bit slower

This is to be used before python evaluation so: 10.1km -> 10.1*1000.0 ...will be resolved by Python.

Values will be split by an add sign: 5'2" -> 5*0.3048 + 2*0.0254

Parameters
str_previs optional, when valid it is used to get a base unit when none is set.
Returns
True of a change was made.

Definition at line 1091 of file unit.c.

References BLI_snprintf(), ch_is_op(), ELEM, is_valid_unit_collection(), bUnitDef::name, bUnitDef::scalar, SEP_CHR, str, TEMP_STR_SIZE, type, unit_detect_from_str(), unit_distribute_negatives(), unit_get_system(), unit_replace(), UNIT_SYSTEM_TOT, and bUnitCollection::units.

Referenced by bpyunits_to_value(), and user_string_to_number().

◆ BKE_unit_scalar_get()

double BKE_unit_scalar_get ( const void usys_pt,
int  index 
)

Definition at line 1291 of file unit.c.

Referenced by ED_scene_grid_scale(), and ED_view3d_grid_steps().

◆ BKE_unit_string_contains_unit()

bool BKE_unit_string_contains_unit ( const char *  str,
int  type 
)
Returns
true if the string contains any valid unit for the given type.

Definition at line 1063 of file unit.c.

References is_valid_unit_collection(), bUnitCollection::length, str, type, unit_find(), unit_get_system(), UNIT_SYSTEM_TOT, and bUnitCollection::units.

Referenced by user_string_to_number().

◆ BKE_unit_system_get()

void BKE_unit_system_get ( int  system,
int  type,
const void **  r_usys_pt,
int *  r_len 
)

Loop over scales, could add names later.

Definition at line 1251 of file unit.c.

References bUnitCollection::length, NULL, type, and unit_get_system().

Referenced by ED_scene_grid_scale(), ED_view3d_grid_steps(), and ED_view3d_grid_view_scale().

◆ BKE_unit_value_as_string()

size_t BKE_unit_value_as_string ( char *  str,
int  len_max,
double  value,
int  prec,
int  type,
const UnitSettings settings,
bool  pad 
)

◆ BKE_unit_value_as_string_adaptive()

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 
)

◆ ch_is_op()

static bool ch_is_op ( char  op)
static

Definition at line 748 of file unit.c.

Referenced by BKE_unit_replace_string(), find_next_op(), and find_previous_non_value_char().

◆ find_end_of_value_chars()

static int find_end_of_value_chars ( const char *  str,
const int  len_max,
const int  start_ofs 
)
static

Helper for unit_scale_str for the process of correctly applying the order of operations for the unit's bias term.

Definition at line 894 of file unit.c.

References str.

Referenced by unit_scale_str().

◆ find_next_negative()

static char* find_next_negative ( const char *  str,
const char *  remaining_str 
)
static

Helper function for unit_distribute_negatives to find the next negative to distribute.

Note
This unnecessarily skips the next space if it comes right after the "-" just to make a more predictable output.

Definition at line 776 of file unit.c.

References ELEM, NULL, and str.

Referenced by unit_distribute_negatives().

◆ find_next_op()

static char* find_next_op ( const char *  str,
char *  remaining_str,
int  len_max 
)
static

Helper function for unit_distribute_negatives to find the next operation, including "-".

Note
This unnecessarily skips the space before the operation character just to make a more predictable output.

Definition at line 802 of file unit.c.

References BLI_assert_msg, ch_is_op(), ELEM, and str.

Referenced by unit_distribute_negatives().

◆ find_previous_non_value_char()

static int find_previous_non_value_char ( const char *  str,
const int  start_ofs 
)
static

Helper for unit_scale_str for the process of correctly applying the order of operations for the unit's bias term.

Definition at line 880 of file unit.c.

References ch_is_op(), and str.

Referenced by unit_scale_str().

◆ get_preferred_display_unit_if_used()

static const bUnitDef* get_preferred_display_unit_if_used ( int  type,
PreferredUnits  units 
)
static

◆ is_valid_unit_collection()

static bool is_valid_unit_collection ( const bUnitCollection usys)
static

◆ isalpha_or_utf8()

BLI_INLINE bool isalpha_or_utf8 ( const int  ch)

Definition at line 691 of file unit.c.

Referenced by unit_find_str().

◆ preferred_units_from_UnitSettings()

static PreferredUnits preferred_units_from_UnitSettings ( const UnitSettings settings)
static

◆ unit_as_string()

static size_t unit_as_string ( char *  str,
int  len_max,
double  value,
int  prec,
const bUnitCollection usys,
const bUnitDef unit,
char  pad 
)
static

◆ unit_as_string_main()

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

◆ unit_as_string_split_pair()

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

Definition at line 551 of file unit.c.

References integer_digits_d(), max_ii(), bUnitDef::scalar, str, unit_as_string(), and unit_dual_convert().

Referenced by unit_as_string_main().

◆ unit_best_fit()

static const bUnitDef* unit_best_fit ( double  value,
const bUnitCollection usys,
const bUnitDef unit_start,
int  suppress 
)
static

◆ unit_default()

static const bUnitDef* unit_default ( const bUnitCollection usys)
static

◆ unit_detect_from_str()

static const bUnitDef* unit_detect_from_str ( const bUnitCollection usys,
const char *  str,
const char *  str_prev 
)
static

Try to find a default unit from current or previous string. This allows us to handle cases like 2 + 2mm, people would expect to get 4mm, not 2.002m!

Note
This does not handle corner cases like 2 + 2cm + 1 + 2.5mm... We can't support everything.

Definition at line 1034 of file unit.c.

References bUnitDef::name, NULL, str, unit_default(), unit_find(), and bUnitCollection::units.

Referenced by BKE_unit_replace_string().

◆ unit_distribute_negatives()

static bool unit_distribute_negatives ( char *  str,
const int  len_max 
)
static

Put parentheses around blocks of values after negative signs to get rid of an implied "+" between numbers without an operation between them. For example:

"-1m50cm + 1 - 2m50cm" -> "-(1m50cm) + 1 - (2m50cm)"

Definition at line 843 of file unit.c.

References find_next_negative(), find_next_op(), NULL, and str.

Referenced by BKE_unit_replace_string().

◆ unit_dual_convert()

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

Definition at line 426 of file unit.c.

References ceil(), blender::math::floor(), NULL, bUnitDef::scalar, and unit_best_fit().

Referenced by unit_as_string_split_pair().

◆ unit_find()

static bool unit_find ( const char *  str,
const bUnitDef unit 
)
static

◆ unit_find_str()

static const char* unit_find_str ( const char *  str,
const char *  substr,
bool  case_sensitive 
)
static

◆ unit_get_system()

static const bUnitCollection* unit_get_system ( int  system,
int  type 
)
static

◆ unit_replace()

static int unit_replace ( char *  str,
int  len_max,
char *  str_tmp,
double  scale_pref,
const bUnitDef unit 
)
static

◆ unit_scale_str()

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

◆ unit_should_be_split()

static bool unit_should_be_split ( int  type)
static

Definition at line 524 of file unit.c.

References B_UNIT_CAMERA, B_UNIT_LENGTH, B_UNIT_MASS, B_UNIT_TIME, ELEM, and type.

Referenced by unit_as_string_main().

Variable Documentation

◆ buCameraLenCollection

struct bUnitCollection buCameraLenCollection = {buCameraLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buCameraLenDef)}
static

Definition at line 1 of file unit.c.

◆ buCameraLenDef

struct bUnitDef buCameraLenDef[]
static
Initial value:
= {
{"meter", "meters", "m", NULL, "Meters", NULL, UN_SC_KM, 0.0, B_UNIT_DEF_NONE},
{"decimeter", "decimeters", "dm", NULL, "10 Centimeters", NULL, UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS},
{"centimeter", "centimeters", "cm", NULL, "Centimeters", NULL, UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS},
{"millimeter", "millimeters", "mm", NULL, "Millimeters", NULL, UN_SC_M, 0.0, B_UNIT_DEF_NONE},
{"micrometer", "micrometers", "µm", "um", "Micrometers", NULL, UN_SC_MM, 0.0, B_UNIT_DEF_SUPPRESS},
}
@ B_UNIT_DEF_SUPPRESS
Definition: unit.c:99
@ B_UNIT_DEF_NONE
Definition: unit.c:97
#define UN_SC_DAM
Definition: unit.c:39
#define UN_SC_KM
Definition: unit.c:37
#define NULL_UNIT
Definition: unit.c:123
#define UN_SC_MM
Definition: unit.c:43
#define UN_SC_HM
Definition: unit.c:38
#define UN_SC_M
Definition: unit.c:40

Definition at line 1 of file unit.c.

◆ buDummyCollection

struct bUnitCollection buDummyCollection = {buDummyDef, 0, 0, sizeof(buDummyDef)}
static

Definition at line 1 of file unit.c.

Referenced by unit_as_string_main().

◆ buDummyDef

struct bUnitDef buDummyDef[] = { {"", NULL, "", NULL, NULL, NULL, 1.0, 0.0}, NULL_UNIT}
static

Definition at line 1 of file unit.c.

◆ buImperialAclCollection

struct bUnitCollection buImperialAclCollection = {buImperialAclDef, 0, 0, UNIT_COLLECTION_LENGTH(buImperialAclDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialAclDef

struct bUnitDef buImperialAclDef[]
static
Initial value:
= {
{"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},
}
#define UN_SC_FT
Definition: unit.c:50

Definition at line 1 of file unit.c.

◆ buImperialAreaCollection

struct bUnitCollection buImperialAreaCollection = {buImperialAreaDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialAreaDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialAreaDef

struct bUnitDef buImperialAreaDef[]
static
Initial value:
= {
{"square mile", "square miles", "sq mi", "sq m", "Square Miles", NULL, UN_SC_MI * UN_SC_MI, 0.0, B_UNIT_DEF_NONE},
{"square furlong", "square furlongs", "sq fur", NULL, "Square Furlongs", NULL, UN_SC_FUR * UN_SC_FUR, 0.0, B_UNIT_DEF_SUPPRESS},
{"square chain", "square chains", "sq ch", NULL, "Square Chains", NULL, UN_SC_CH * UN_SC_CH, 0.0, B_UNIT_DEF_SUPPRESS},
{"square yard", "square yards", "sq yd", NULL, "Square Yards", NULL, UN_SC_YD * UN_SC_YD, 0.0, B_UNIT_DEF_NONE},
{"square foot", "square feet", "sq ft", NULL, "Square Feet", NULL, UN_SC_FT * UN_SC_FT, 0.0, B_UNIT_DEF_NONE},
{"square inch", "square inches", "sq in", NULL, "Square Inches", NULL, UN_SC_IN * UN_SC_IN, 0.0, B_UNIT_DEF_NONE},
{"square thou", "square thou", "sq mil", NULL, "Square Thou", NULL, UN_SC_MIL * UN_SC_MIL, 0.0, B_UNIT_DEF_NONE},
}
#define UN_SC_FUR
Definition: unit.c:47
#define UN_SC_IN
Definition: unit.c:51
#define UN_SC_MIL
Definition: unit.c:52
#define UN_SC_MI
Definition: unit.c:46
#define UN_SC_CH
Definition: unit.c:48
#define UN_SC_YD
Definition: unit.c:49

Definition at line 1 of file unit.c.

◆ buImperialLenCollection

struct bUnitCollection buImperialLenCollection = {buImperialLenDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialLenDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialLenDef

struct bUnitDef buImperialLenDef[]
static
Initial value:
= {
{"mile", "miles", "mi", NULL, "Miles", "MILES", UN_SC_MI, 0.0, B_UNIT_DEF_NONE},
{"furlong", "furlongs", "fur", NULL, "Furlongs", "FURLONGS", UN_SC_FUR, 0.0, B_UNIT_DEF_SUPPRESS},
{"chain", "chains", "ch", NULL, "Chains", "CHAINS", UN_SC_CH, 0.0, B_UNIT_DEF_SUPPRESS},
{"yard", "yards", "yd", NULL, "Yards", "YARDS", UN_SC_YD, 0.0, B_UNIT_DEF_SUPPRESS},
{"foot", "feet", "'", "ft", "Feet", "FEET", UN_SC_FT, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE},
{"inch", "inches", "\"", "in", "Inches", "INCHES", UN_SC_IN, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE},
{"thou", "thou", "thou", "mil", "Thou", "THOU", UN_SC_MIL, 0.0, B_UNIT_DEF_NONE},
}
@ B_UNIT_DEF_NO_SPACE
Definition: unit.c:105

Definition at line 1 of file unit.c.

◆ buImperialMassCollection

struct bUnitCollection buImperialMassCollection = {buImperialMassDef, 3, 0, UNIT_COLLECTION_LENGTH(buImperialMassDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialMassDef

struct bUnitDef buImperialMassDef[]
static
Initial value:
= {
{"ton", "tonnes", "ton", "t", "Tonnes", "TONNES", UN_SC_ITON, 0.0, B_UNIT_DEF_NONE},
{"centum weight", "centum weights", "cwt", NULL, "Centum weights", "CENTUM_WEIGHTS", UN_SC_CWT, 0.0, B_UNIT_DEF_NONE},
{"stone", "stones", "st", NULL, "Stones", "STONES", UN_SC_ST, 0.0, B_UNIT_DEF_NONE},
{"pound", "pounds", "lb", NULL, "Pounds", "POUNDS", UN_SC_LB, 0.0, B_UNIT_DEF_NONE},
{"ounce", "ounces", "oz", NULL, "Ounces", "OUNCES", UN_SC_OZ, 0.0, B_UNIT_DEF_NONE},
}
#define UN_SC_ITON
Definition: unit.c:62
#define UN_SC_CWT
Definition: unit.c:63
#define UN_SC_LB
Definition: unit.c:65
#define UN_SC_ST
Definition: unit.c:64
#define UN_SC_OZ
Definition: unit.c:66

Definition at line 1 of file unit.c.

◆ buImperialTempCollection

struct bUnitCollection buImperialTempCollection
static
Initial value:
= {
#define UNIT_COLLECTION_LENGTH(def)
Definition: unit.c:122
static struct bUnitDef buImperialTempDef[]
Definition: unit.c:327

Definition at line 1 of file unit.c.

◆ buImperialTempDef

struct bUnitDef buImperialTempDef[]
static
Initial value:
= {
{"kelvin", "kelvin", "K", NULL, "Kelvin", "KELVIN", 1.0f, 0.0, B_UNIT_DEF_NONE},
{"fahrenheit", "fahrenheit", "°F", "F", "Fahrenheit", "FAHRENHEIT", UN_SC_FAH, 459.67, B_UNIT_DEF_NONE},
}
#define UN_SC_FAH
Definition: unit.c:68

Definition at line 1 of file unit.c.

◆ buImperialVelCollection

struct bUnitCollection buImperialVelCollection = {buImperialVelDef, 0, 0, UNIT_COLLECTION_LENGTH(buImperialVelDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialVelDef

struct bUnitDef buImperialVelDef[]
static
Initial value:
= {
{"foot per second", "feet per second", "ft/s", "fps", "Feet per second", NULL, UN_SC_FT, 0.0, B_UNIT_DEF_NONE},
{"mile per hour", "miles per hour", "mph", NULL, "Miles per hour", NULL, UN_SC_MI / 3600.0f, 0.0, B_UNIT_DEF_SUPPRESS},
}

Definition at line 1 of file unit.c.

◆ buImperialVolCollection

struct bUnitCollection buImperialVolCollection = {buImperialVolDef, 4, 0, UNIT_COLLECTION_LENGTH(buImperialVolDef)}
static

Definition at line 1 of file unit.c.

◆ buImperialVolDef

struct bUnitDef buImperialVolDef[]
static
Initial value:
= {
{"cubic mile", "cubic miles", "cu mi", "cu m", "Cubic Miles", NULL, UN_SC_MI * UN_SC_MI * UN_SC_MI, 0.0, B_UNIT_DEF_NONE},
{"cubic furlong", "cubic furlongs", "cu fur", NULL, "Cubic Furlongs", NULL, UN_SC_FUR * UN_SC_FUR * UN_SC_FUR, 0.0, B_UNIT_DEF_SUPPRESS},
{"cubic chain", "cubic chains", "cu ch", NULL, "Cubic Chains", NULL, UN_SC_CH * UN_SC_CH * UN_SC_CH, 0.0, B_UNIT_DEF_SUPPRESS},
{"cubic yard", "cubic yards", "cu yd", NULL, "Cubic Yards", NULL, UN_SC_YD * UN_SC_YD * UN_SC_YD, 0.0, B_UNIT_DEF_NONE},
{"cubic foot", "cubic feet", "cu ft", NULL, "Cubic Feet", NULL, UN_SC_FT * UN_SC_FT * UN_SC_FT, 0.0, B_UNIT_DEF_NONE},
{"cubic inch", "cubic inches", "cu in", NULL, "Cubic Inches", NULL, UN_SC_IN * UN_SC_IN * UN_SC_IN, 0.0, B_UNIT_DEF_NONE},
{"cubic thou", "cubic thou", "cu mil", NULL, "Cubic Thou", NULL, UN_SC_MIL * UN_SC_MIL * UN_SC_MIL, 0.0, B_UNIT_DEF_NONE},
}

Definition at line 1 of file unit.c.

◆ buMetricAclCollection

struct bUnitCollection buMetricAclCollection = {buMetricAclDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricAclDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricAclDef

struct bUnitDef buMetricAclDef[]
static
Initial value:
= {
{"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},
}

Definition at line 1 of file unit.c.

◆ buMetricAreaCollection

struct bUnitCollection buMetricAreaCollection = {buMetricAreaDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricAreaDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricAreaDef

struct bUnitDef buMetricAreaDef[]
static
Initial value:
= {
{"square kilometer", "square kilometers", "km²", "km2", "Square Kilometers", NULL, UN_SC_KM * UN_SC_KM, 0.0, B_UNIT_DEF_NONE},
{"square hectometer", "square hectometers", "hm²", "hm2", "Square Hectometers", NULL, UN_SC_HM * UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS},
{"square dekameter", "square dekameters", "dam²", "dam2", "Square Dekameters", NULL, UN_SC_DAM * UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS},
{"square meter", "square meters", "m²", "m2", "Square Meters", NULL, UN_SC_M * UN_SC_M, 0.0, B_UNIT_DEF_NONE},
{"square decimeter", "square decimetees", "dm²", "dm2", "Square Decimeters", NULL, UN_SC_DM * UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS},
{"square centimeter", "square centimeters", "cm²", "cm2", "Square Centimeters", NULL, UN_SC_CM * UN_SC_CM, 0.0, B_UNIT_DEF_NONE},
{"square millimeter", "square millimeters", "mm²", "mm2", "Square Millimeters", NULL, UN_SC_MM * UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH},
{"square micrometer", "square micrometers", "µm²", "um2", "Square Micrometers", NULL, UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE},
}
@ B_UNIT_DEF_TENTH
Definition: unit.c:101
#define UN_SC_DM
Definition: unit.c:41
#define UN_SC_CM
Definition: unit.c:42
#define UN_SC_UM
Definition: unit.c:44

Definition at line 1 of file unit.c.

◆ buMetricLenCollection

const struct bUnitCollection buMetricLenCollection = {buMetricLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricLenDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricLenDef

struct bUnitDef buMetricLenDef[]
static
Initial value:
= {
{"kilometer", "kilometers", "km", NULL, "Kilometers", "KILOMETERS", UN_SC_KM, 0.0, B_UNIT_DEF_NONE},
{"hectometer", "hectometers", "hm", NULL, "100 Meters", "HECTOMETERS", UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS},
{"dekameter", "dekameters", "dam", NULL, "10 Meters", "DEKAMETERS", UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS},
{"meter", "meters", "m", NULL, "Meters", "METERS", UN_SC_M, 0.0, B_UNIT_DEF_NONE},
{"decimeter", "decimeters", "dm", NULL, "10 Centimeters", "DECIMETERS", UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS},
{"centimeter", "centimeters", "cm", NULL, "Centimeters", "CENTIMETERS", UN_SC_CM, 0.0, B_UNIT_DEF_NONE},
{"millimeter", "millimeters", "mm", NULL, "Millimeters", "MILLIMETERS", UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH},
{"micrometer", "micrometers", "µm", "um", "Micrometers", "MICROMETERS", UN_SC_UM, 0.0, B_UNIT_DEF_NONE},
}

Definition at line 1 of file unit.c.

◆ buMetricMassCollection

struct bUnitCollection buMetricMassCollection = {buMetricMassDef, 2, 0, UNIT_COLLECTION_LENGTH(buMetricMassDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricMassDef

struct bUnitDef buMetricMassDef[]
static
Initial value:
= {
{"ton", "tonnes", "ton", "t", "Tonnes", "TONNES", UN_SC_MTON, 0.0, B_UNIT_DEF_NONE},
{"quintal", "quintals", "ql", "q", "100 Kilograms", "QUINTALS", UN_SC_QL, 0.0, B_UNIT_DEF_SUPPRESS},
{"kilogram", "kilograms", "kg", NULL, "Kilograms", "KILOGRAMS", UN_SC_KG, 0.0, B_UNIT_DEF_NONE},
{"hectogram", "hectograms", "hg", NULL, "Hectograms", "HECTOGRAMS", UN_SC_HG, 0.0, B_UNIT_DEF_SUPPRESS},
{"dekagram", "dekagrams", "dag", NULL, "10 Grams", "DEKAGRAMS", UN_SC_DAG, 0.0, B_UNIT_DEF_SUPPRESS},
{"gram", "grams", "g", NULL, "Grams", "GRAMS", UN_SC_G, 0.0, B_UNIT_DEF_NONE},
{"milligram", "milligrams", "mg", NULL, "Milligrams", "MILLIGRAMS", UN_SC_MG, 0.0, B_UNIT_DEF_NONE},
}
#define UN_SC_MG
Definition: unit.c:60
#define UN_SC_MTON
Definition: unit.c:54
#define UN_SC_HG
Definition: unit.c:57
#define UN_SC_G
Definition: unit.c:59
#define UN_SC_QL
Definition: unit.c:55
#define UN_SC_DAG
Definition: unit.c:58
#define UN_SC_KG
Definition: unit.c:56

Definition at line 1 of file unit.c.

◆ buMetricTempCollection

struct bUnitCollection buMetricTempCollection = {buMetricTempDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricTempDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricTempDef

struct bUnitDef buMetricTempDef[]
static
Initial value:
= {
{"kelvin", "kelvin", "K", NULL, "Kelvin", "KELVIN", 1.0f, 0.0, B_UNIT_DEF_NONE},
{"celsius", "celsius", "°C", "C", "Celsius", "CELSIUS", 1.0f, 273.15, B_UNIT_DEF_NONE},
}

Definition at line 1 of file unit.c.

◆ buMetricVelCollection

struct bUnitCollection buMetricVelCollection = {buMetricVelDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricVelDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricVelDef

struct bUnitDef buMetricVelDef[]
static
Initial value:
= {
{"meter per second", "meters per second", "m/s", NULL, "Meters per second", NULL, UN_SC_M, 0.0, B_UNIT_DEF_NONE},
{"kilometer per hour", "kilometers per hour", "km/h", NULL, "Kilometers per hour", NULL, UN_SC_KM / 3600.0f, 0.0, B_UNIT_DEF_SUPPRESS},
}

Definition at line 1 of file unit.c.

◆ buMetricVolCollection

struct bUnitCollection buMetricVolCollection = {buMetricVolDef, 3, 0, UNIT_COLLECTION_LENGTH(buMetricVolDef)}
static

Definition at line 1 of file unit.c.

◆ buMetricVolDef

struct bUnitDef buMetricVolDef[]
static
Initial value:
= {
{"cubic kilometer", "cubic kilometers", "km³", "km3", "Cubic Kilometers", NULL, UN_SC_KM * UN_SC_KM * UN_SC_KM, 0.0, B_UNIT_DEF_NONE},
{"cubic hectometer", "cubic hectometers", "hm³", "hm3", "Cubic Hectometers", NULL, UN_SC_HM * UN_SC_HM * UN_SC_HM, 0.0, B_UNIT_DEF_SUPPRESS},
{"cubic dekameter", "cubic dekameters", "dam³", "dam3", "Cubic Dekameters", NULL, UN_SC_DAM * UN_SC_DAM * UN_SC_DAM, 0.0, B_UNIT_DEF_SUPPRESS},
{"cubic meter", "cubic meters", "m³", "m3", "Cubic Meters", NULL, UN_SC_M * UN_SC_M * UN_SC_M, 0.0, B_UNIT_DEF_NONE},
{"cubic decimeter", "cubic decimeters", "dm³", "dm3", "Cubic Decimeters", NULL, UN_SC_DM * UN_SC_DM * UN_SC_DM, 0.0, B_UNIT_DEF_SUPPRESS},
{"cubic centimeter", "cubic centimeters", "cm³", "cm3", "Cubic Centimeters", NULL, UN_SC_CM * UN_SC_CM * UN_SC_CM, 0.0, B_UNIT_DEF_NONE},
{"cubic millimeter", "cubic millimeters", "mm³", "mm3", "Cubic Millimeters", NULL, UN_SC_MM * UN_SC_MM * UN_SC_MM, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_TENTH},
{"cubic micrometer", "cubic micrometers", "µm³", "um3", "Cubic Micrometers", NULL, UN_SC_UM * UN_SC_UM * UN_SC_UM, 0.0, B_UNIT_DEF_NONE},
}

Definition at line 1 of file unit.c.

◆ buNaturalRotCollection

struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, UNIT_COLLECTION_LENGTH(buNaturalRotDef)}
static

Definition at line 1 of file unit.c.

◆ buNaturalRotDef

struct bUnitDef buNaturalRotDef[]
static
Initial value:
= {
{"degree", "degrees", "°", "d", "Degrees", "DEGREES", M_PI / 180.0, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE},
{"arcminute", "arcminutes", "'", NULL, "Arcminutes", "ARCMINUTES", (M_PI / 180.0) / 60.0, 0.0, B_UNIT_DEF_SUPPRESS | B_UNIT_DEF_NO_SPACE},
{"arcsecond", "arcseconds", "\"", NULL, "Arcseconds", "ARCSECONDS", (M_PI / 180.0) / 3600.0, 0.0, B_UNIT_DEF_SUPPRESS | B_UNIT_DEF_NO_SPACE},
{"radian", "radians", "r", NULL, "Radians", "RADIANS", 1.0, 0.0, B_UNIT_DEF_NONE},
}
#define M_PI
Definition: BLI_math_base.h:20

Definition at line 1 of file unit.c.

◆ buNaturalTimeCollection

struct bUnitCollection buNaturalTimeCollection = {buNaturalTimeDef, 3, 0, UNIT_COLLECTION_LENGTH(buNaturalTimeDef)}
static

Definition at line 1 of file unit.c.

◆ buNaturalTimeDef

struct bUnitDef buNaturalTimeDef[]
static
Initial value:
= {
{"day", "days", "d", NULL, "Days", "DAYS", 86400.0, 0.0, B_UNIT_DEF_NONE},
{"hour", "hours", "hr", "h", "Hours", "HOURS", 3600.0, 0.0, B_UNIT_DEF_NONE},
{"minute", "minutes", "min", "m", "Minutes", "MINUTES", 60.0, 0.0, B_UNIT_DEF_NONE},
{"second", "seconds", "sec", "s", "Seconds", "SECONDS", 1.0, 0.0, B_UNIT_DEF_NONE},
{"millisecond", "milliseconds", "ms", NULL, "Milliseconds", "MILLISECONDS", 0.001, 0.0, B_UNIT_DEF_NONE},
{"microsecond", "microseconds", "µs", "us", "Microseconds", "MICROSECONDS", 0.000001, 0.0, B_UNIT_DEF_NONE},
}

Definition at line 1 of file unit.c.

◆ bUnitSystems

const struct bUnitCollection* bUnitSystems[][B_UNIT_TYPE_TOT]
static

Definition at line 338 of file unit.c.

Referenced by unit_get_system().

◆ buPowerCollection

struct bUnitCollection buPowerCollection = {buPowerDef, 3, 0, UNIT_COLLECTION_LENGTH(buPowerDef)}
static

Definition at line 1 of file unit.c.

◆ buPowerDef

struct bUnitDef buPowerDef[]
static
Initial value:
= {
{"gigawatt", "gigawatts", "GW", NULL, "Gigawatts", NULL, 1e9f, 0.0, B_UNIT_DEF_NONE},
{"megawatt", "megawatts", "MW", NULL, "Megawatts", NULL, 1e6f, 0.0, B_UNIT_DEF_CASE_SENSITIVE},
{"kilowatt", "kilowatts", "kW", NULL, "Kilowatts", NULL, 1e3f, 0.0, B_UNIT_DEF_SUPPRESS},
{"watt", "watts", "W", NULL, "Watts", NULL, 1.0f, 0.0, B_UNIT_DEF_NONE},
{"milliwatt", "milliwatts", "mW", NULL, "Milliwatts", NULL, 1e-3f, 0.0, B_UNIT_DEF_CASE_SENSITIVE},
{"microwatt", "microwatts", "µW", "uW", "Microwatts", NULL, 1e-6f, 0.0, B_UNIT_DEF_NONE},
{"nanowatt", "nanowatts", "nW", NULL, "Nanowatts", NULL, 1e-9f, 0.0, B_UNIT_DEF_NONE},
}
@ B_UNIT_DEF_CASE_SENSITIVE
Definition: unit.c:103

Definition at line 1 of file unit.c.