BRL-CAD
units.h
Go to the documentation of this file.
1 /* U N I T S . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /** @file units.h
22  *
23  */
24 #ifndef BU_UNITS_H
25 #define BU_UNITS_H
26 
27 #include "common.h"
28 
29 #include "bu/defines.h"
30 #include "bu/parse.h"
31 
33 
34 /** @addtogroup units */
35 /** @{ */
36 
37 
38 /** @file libbu/units.c
39  *
40  * Module of libbu to handle units conversion between strings and mm.
41  *
42  */
43 
44 /**
45  * Given a string representation of a unit of distance (e.g., "feet"),
46  * return the multiplier which will convert that unit into the default
47  * unit for the dimension (millimeters for length, mm^3 for volume,
48  * and grams for mass.)
49  *
50  * Returns 0.0 on error and >0.0 on success
51  */
52 BU_EXPORT extern double bu_units_conversion(const char *str);
53 
54 /**
55  * Given a conversion factor to mm, search the table to find what unit
56  * this represents.
57  *
58  * To accommodate floating point fuzz, a "near miss" is allowed. The
59  * algorithm depends on the table being sorted small-to-large.
60  *
61  * Returns -
62  * char* units string
63  * NULL No known unit matches this conversion factor.
64  */
65 BU_EXPORT extern const char *bu_units_string(const double mm);
66 BU_EXPORT extern struct bu_vls *bu_units_strings_vls(void);
67 
68 /**
69  * Given a conversion factor to mm, search the table to find the
70  * closest matching unit.
71  *
72  * Returns -
73  * char* units string
74  * NULL Invalid conversion factor (non-positive)
75  */
76 BU_EXPORT extern const char *bu_nearest_units_string(const double mm);
77 
78 /**
79  * Given a string of the form "25cm" or "5.2ft" returns the
80  * corresponding distance in mm.
81  *
82  * Returns -
83  * -1 on error
84  * >0 on success
85  */
86 BU_EXPORT extern double bu_mm_value(const char *s);
87 
88 /**
89  * Used primarily as a hooked function for bu_structparse tables to
90  * allow input of floating point values in other units.
91  */
92 BU_EXPORT extern void bu_mm_cvt(const struct bu_structparse *sdp,
93  const char *name,
94  void *base,
95  const char *value,
96  void *data);
97 
99 
100 /** @} */
101 
102 #endif /* BU_UNITS_H */
103 
104 /*
105  * Local Variables:
106  * mode: C
107  * tab-width: 8
108  * indent-tabs-mode: t
109  * c-file-style: "stroustrup"
110  * End:
111  * ex: shiftwidth=4 tabstop=8
112  */
if lu s
Definition: nmg_mod.c:3860
Definition: clone.c:90
Header file for the BRL-CAD common definitions.
void bu_mm_cvt(const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data)
Definition: units.c:386
double bu_mm_value(const char *s)
Definition: units.c:355
COMPLEX data[64]
Definition: fftest.c:34
double bu_units_conversion(const char *str)
Definition: units.c:234
const char * bu_nearest_units_string(const double mm)
#define __BEGIN_DECLS
Definition: common.h:73
struct bu_vls * bu_units_strings_vls(void)
Definition: units.c:291
const char * bu_units_string(const double mm)
#define __END_DECLS
Definition: common.h:74
Definition: vls.h:56