1 | // tUnits.h  |
2 | //  |
3 | // Definitions of various units for length, time, and mass along with the SI multiplier prefixes.  |
4 | //  |
5 | // Copyright (c) 2017, 2020 Tristan Grimmer.  |
6 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
7 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
8 | //  |
9 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
10 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
11 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
12 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
13 | // PERFORMANCE OF THIS SOFTWARE.  |
14 |   |
15 | #pragma once  |
16 |   |
17 |   |
18 | namespace tUnit  |
19 | {  |
20 | // Conversion constants.  |
21 | // Prefixes (SI):  |
22 | // n=nano, u=micro, m=milli  |
23 | // K=kilo, M=mega, G=giga.  |
24 | // p=per  |
25 | // Units:  |
26 | // mi = mile.  |
27 | // m = meter.  |
28 | // L = litre.  |
29 | const float Conv_Km_per_mi = 1.609344f;  |
30 | const float Conv_Kmph_per_mps = 3.6f;  |
31 |   |
32 | enum class tPrefix  |
33 | {  |
34 | Invalid = -1,  |
35 |   |
36 | Yocto, // 10^-24  |
37 | Zepto, // 10^-21  |
38 | Atto, // 10^-18  |
39 | Femto, // 10^-15  |
40 | Pico, // 10^-12  |
41 | Nano, // 10^-9  |
42 | Micro, // 10^-6  |
43 | Milli, // 10^-3  |
44 | Centi, // 10^-2  |
45 | Deci, // 10^-1  |
46 | Unit, // 10^0 Not an SI prefix, but a handy one.  |
47 | Deca, // 10^1  |
48 | Hecto, // 10^2  |
49 | Kilo, // 10^3  |
50 | Mega, // 10^6  |
51 | Giga, // 10^9  |
52 | Tera, // 10^12  |
53 | Peta, // 10^15  |
54 | Exa, // 10^18  |
55 | Zetta, // 10^21  |
56 | Yotta, // 10^24  |
57 |   |
58 | // Non SI prefixes.  |
59 | // Bi and Di are missing on purpose because they are ambiguous. In chemistry they both mean '2 of' like  |
60 | // sodium-BIcarbonate and carbon DIoxide, but sometimes they mean half. Never mind confusion about being paid  |
61 | // bi-monthly. Certainly semi-monthly is clear. Actually, we should look here for more:  |
62 | // https://en.wikipedia.org/wiki/Numeral_prefix like Duo, Quad, Sept, Hex, etc.  |
63 | Thrice,  |
64 | Twice,  |
65 | Semi, // Half of.  |
66 | Half,  |
67 | Quarter,  |
68 | Eighth,  |
69 | Sixteenth,  |
70 | Thirtysecondth,  |
71 | Sixtyfourth,  |
72 |   |
73 | PrefixCount  |
74 | };  |
75 |   |
76 | enum class tTime  |
77 | {  |
78 | Unspecified = -1,  |
79 |   |
80 | PlankTime, // 5.39E-44 seconds.  |
81 | Chronon, // 6.97E-24 seconds. Smallest indivisible unit?!  |
82 |   |
83 | // These next 6 should perhaps not be here since we could use the tPrefix and Second units. Still, they are  |
84 | // common enough that perhaps they do deserve their own units.  |
85 | Attosecond,  |
86 | Femtosecond,  |
87 | Picosecond,  |
88 | Nanosecond,  |
89 | Microsecond,  |
90 | Millisecond,  |
91 |   |
92 | Tick, // 1/60 of a second.  |
93 | Second,  |
94 | She, // Babylonian. 0.3 seconds.  |
95 | Helek, // Hebrew. Plural: halakim. 10/3 seconds.  |
96 | Minute,  |
97 | Hour,  |
98 | Day, // Precisely 24 hours. Not an Earth rotation 23h 59m 56s.  |
99 | Week, // Precisely 7 days.  |
100 |   |
101 | Fortnight, // Precisely 2 weeks.  |
102 | // No months because they vary in duration.  |
103 | Year, // Precisely 365 canonical days.  |
104 | Annum, // Precisely 365 canonical days.  |
105 | Century, // 100 years.  |
106 | Millennium, // 1000 years.  |
107 | GalacticYear, // One GY is 250 million years.  |
108 |   |
109 | NumTimeUnits  |
110 | };  |
111 |   |
112 | enum class tLength  |
113 | {  |
114 | Unspecified = -1,  |
115 | Angstrom,  |
116 | Meter,  |
117 | Kilometer, // Could use the tPrefix, but it's a common measure.  |
118 | Inch,  |
119 | ,  |
120 | Yard,  |
121 | Fathom,  |
122 | Mile,  |
123 | NauticalMile,  |
124 | AstronomicalUnit,  |
125 | NumLengthUnits  |
126 | };  |
127 |   |
128 | enum class tMass  |
129 | {  |
130 | Unspecified = -1,  |
131 | Gram,  |
132 | Kilogram, // Could use the tPrefix, but it's a common measure.  |
133 | Slug,  |
134 | NumMassUnits  |
135 | };  |
136 |   |
137 | // No compound units until we figure out how they'll work. For example, force (LBS, Newtons, etc) is composed of:  |
138 | // mass-unit * distance-unit / (time-unit * time-unit).  |
139 |   |
140 | // These return pointers to persistent (static) char strings. They return nullptr if Unspecified is passed in.  |
141 | const char* GetUnitName(tTime);  |
142 | const char* GetUnitName(tLength);  |
143 | const char* GetUnitName(tMass);  |
144 |   |
145 | // Given a unit name, these return the associated unit. Case insensitive compares, but no other fuzziness. They  |
146 | // return Unspecified if the name can't be found.  |
147 | tTime GetTimeUnit(const char* name);  |
148 | tLength GetLengthUnit(const char* name);  |
149 | tMass GetMassUnit(const char* name);  |
150 | }  |
151 | |