BRL-CAD

Module of libbu to handle units conversion between strings and mm. More...

Collaboration diagram for Units:

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_vlsbu_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)
 

Detailed Description

Module of libbu to handle units conversion between strings and mm.

Macro Definition Documentation

◆ BU_HN_DECIMAL

#define BU_HN_DECIMAL   0x01

Definition at line 106 of file units.h.

◆ BU_HN_NOSPACE

#define BU_HN_NOSPACE   0x02

Definition at line 107 of file units.h.

◆ BU_HN_B

#define BU_HN_B   0x04

Definition at line 108 of file units.h.

◆ BU_HN_DIVISOR_1000

#define BU_HN_DIVISOR_1000   0x08

Definition at line 109 of file units.h.

◆ BU_HN_IEC_PREFIXES

#define BU_HN_IEC_PREFIXES   0x10

Definition at line 110 of file units.h.

◆ BU_HN_GETSCALE

#define BU_HN_GETSCALE   0x10

Definition at line 113 of file units.h.

◆ BU_HN_AUTOSCALE

#define BU_HN_AUTOSCALE   0x20

Definition at line 114 of file units.h.

Function Documentation

◆ bu_units_conversion()

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

◆ bu_units_string()

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.

◆ bu_units_strings_vls()

struct bu_vls * bu_units_strings_vls ( void  )

undocumented

◆ bu_nearest_units_string()

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)

◆ bu_mm_value()

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

◆ bu_mm_cvt()

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.

◆ bu_humanize_number()

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.

◆ bu_dehumanize_number()

int bu_dehumanize_number ( const char *  str,
int64_t *  size 
)