BRL-CAD
|
Module of libbu to handle units conversion between strings and mm. More...
Files | |
file | units.h |
Macros | |
#define | BU_HN_DECIMAL 0x01 |
#define | BU_HN_NOSPACE 0x02 |
#define | BU_HN_B 0x04 |
#define | BU_HN_DIVISOR_1000 0x08 |
#define | BU_HN_IEC_PREFIXES 0x10 |
#define | BU_HN_GETSCALE 0x10 |
#define | BU_HN_AUTOSCALE 0x20 |
Functions | |
double | bu_units_conversion (const char *str) |
const char * | bu_units_string (const double mm) |
struct bu_vls * | bu_units_strings_vls (void) |
const char * | bu_nearest_units_string (const double mm) |
double | bu_mm_value (const char *s) |
void | bu_mm_cvt (const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data) |
int | bu_humanize_number (char *buf, size_t len, int64_t quotient, const char *suffix, size_t scale, int flags) |
int | bu_dehumanize_number (const char *str, int64_t *size) |
Module of libbu to handle units conversion between strings and mm.
double bu_units_conversion | ( | const char * | str | ) |
Convert the provided string into a units conversion factor.
Given a string for a unit of length (e.g., "feet", "yd"), volume (e.g., "cm^3", "cu yards"), or mass (e.g., "kg", "grain", or "oz") return the multiplier (aka conversion factor) that converts the unit into the default (millimeters for length, mm^3 for volume, and grams for mass.) Values may be optionally specified with the unit (e.g., "5ft") to get the conversion factor for a particular quantity.
Returns 0.0 on error and >0.0 on success
const char * bu_units_string | ( | const double | mm | ) |
Given a conversion factor to mm, search the table to find what unit this represents.
To accommodate floating point fuzz, a "near miss" is allowed.
Returns - char* units string NULL No known unit matches this conversion factor.
struct bu_vls * bu_units_strings_vls | ( | void | ) |
undocumented
const char * bu_nearest_units_string | ( | const double | mm | ) |
Given a conversion factor to mm, search the table to find the closest matching unit.
Returns - char* units string NULL Invalid conversion factor (non-positive)
double bu_mm_value | ( | const char * | s | ) |
Given a string of the form "25cm" or "5.2ft" returns the corresponding distance in mm.
Returns - -1 on error >0 on success
void bu_mm_cvt | ( | const struct bu_structparse * | sdp, |
const char * | name, | ||
void * | base, | ||
const char * | value, | ||
void * | data | ||
) |
Used primarily as a hooked function for bu_structparse tables to allow input of floating point values in other units.
int bu_humanize_number | ( | char * | buf, |
size_t | len, | ||
int64_t | quotient, | ||
const char * | suffix, | ||
size_t | scale, | ||
int | flags | ||
) |
Convert digital sizes to human readable form. Based off the BSD function humanize_number(3). Upon success, the humanize_number function returns the number of characters that would have been stored in buf (excluding the terminating NUL) if buf was large enough, or -1 upon failure. Even upon failure, the contents of buf may be modified. If BU_HN_GETSCALE is specified, the prefix index number will be returned instead.
int bu_dehumanize_number | ( | const char * | str, |
int64_t * | size | ||
) |