1use crate::*;
2use crate::tensor::*;
3use crate::complex::c64;
4
5pub type Area = Dimension<2, 0, 0, 0, 0, 0, 0>;
10pub type Volume = Dimension<3, 0, 0, 0, 0, 0, 0>;
11pub type Frequency = Dimension<0, 0, -1, 0, 0, 0, 0>;
12pub type Intensity = Dimension<0, 0, 0, 0, 0, 0, 1>;
13pub type Velocity = Dimension<1, 0, -1, 0, 0, 0, 0>;
14pub type Acceleration = Dimension<1, 0, -2, 0, 0, 0, 0>;
15pub type Force = Dimension<1, 1, -2, 0, 0, 0, 0>;
16pub type Energy = Dimension<2, 1, -2, 0, 0, 0, 0>;
17pub type Entropy = Dimension<2, 1, -2, -1, 0, 0, 0>;
18pub type Power = Dimension<2, 1, -3, 0, 0, 0, 0>;
19pub type Pressure = Dimension<-1, 1, -2, 0, 0, 0, 0>;
20pub type Charge = Dimension<0, 0, 1, 0, 1, 0, 0>;
21pub type HeatCapacity = Dimension<2, 1, -2, -1, 0, 0, 0>;
22
23#[macro_export]
29macro_rules! impl_unit {
30 ($unit:ident, $dimension:ty, $scale:expr, $offset:expr, $symbol:expr, $name:expr) => {
31 impl Default for $unit {
32 fn default() -> Self {
33 $unit
34 }
35 }
36 impl Unit for $unit {
37 type Dimension = $dimension;
38 fn parameters() -> UnitParameters {
39 UnitParameters {
40 scale: $scale,
41 offset: $offset,
42 symbol: $symbol,
43 name: $name,
44 }
45 }
46 }
47 };
48}
49
50pub struct Nanometer;
52pub struct Micrometer;
53pub struct Millimeter;
54pub struct Meter;
55pub struct Kilometer;
56pub struct Centimeter;
57pub struct LightYear;
58pub struct Ångström;
59pub struct PlankLength;
60
61impl_unit!(PlankLength, Length, 1.0, 0.0, "l_p", "PlankLength");
62impl_unit!(Micrometer, Length, 1.0e-6, 0.0, "µm", "Micrometer");
63impl_unit!(Millimeter, Length, 1.0e-3, 0.0, "mm", "Millimeter");
64impl_unit!(Meter, Length, 1.0, 0.0, "m", "Meter");
65impl_unit!(Kilometer, Length, 1000.0, 0.0, "km", "Kilometer");
66impl_unit!(Centimeter, Length, 0.01, 0.0, "cm", "Centimeter");
67impl_unit!(LightYear, Length, 9.461e15, 0.0, "ly", "LightYear");
68impl_unit!(Ångström, Length, 1.0e-10, 0.0, "Å", "Ångström");
69
70pub struct Nanosecond;
72pub struct Microsecond;
73pub struct Millisecond;
74pub struct Second;
75pub struct Minute;
76pub struct Hour;
77pub struct Day;
78pub struct Year;
79pub struct Century;
80
81impl_unit!(Nanosecond, Time, 1.0e-9, 0.0, "ns", "Nanosecond");
82impl_unit!(Microsecond, Time, 1.0e-6, 0.0, "µs", "Microsecond");
83impl_unit!(Millisecond, Time, 1.0e-3, 0.0, "ms", "Millisecond");
84impl_unit!(Second, Time, 1.0, 0.0, "s", "Second");
85impl_unit!(Minute, Time, 60.0, 0.0, "min", "Minute");
86impl_unit!(Hour, Time, 3600.0, 0.0, "h", "Hour");
87impl_unit!(Day, Time, 86400.0, 0.0, "day", "Day");
88impl_unit!(Year, Time, 365.25 * 86400.0, 0.0, "year", "Year");
89impl_unit!(Century, Time, 100.0 * 365.25 * 86400.0, 0.0, "century", "Century");
90
91pub struct Newton;
93pub struct Lbf;
94
95impl_unit!(Newton, Force, 1.0, 0.0, "N", "Newton");
96impl_unit!(Lbf, Force, 4.44822, 0.0, "lbf", "Pound-force");
97
98pub struct MetersPerSecond;
100pub struct KilometersPerHour;
101
102impl_unit!(MetersPerSecond, Velocity, 1.0, 0.0, "m/s", "MetersPerSecond");
103impl_unit!(KilometersPerHour, Velocity, 1.0 / 3.6, 0.0, "km/h", "KilometersPerHour");
104
105pub struct MetersPerSecondSquared;
107
108impl_unit!(MetersPerSecondSquared, Acceleration, 1.0, 0.0, "m/s²", "MeterPerSecondSquared");
109
110pub struct Celsius;
112pub struct Kelvin;
113pub struct Fahrenheit;
114
115impl_unit!(Kelvin, Temperature, 1.0, 0.0, "K", "Kelvin");
116impl_unit!(Celsius, Temperature, 1.0, 273.15, "°C", "Celsius");
117impl_unit!(Fahrenheit, Temperature, 5.0/9.0, 255.372222, "°F", "Fahrenheit");
118
119pub struct Joule;
121pub struct ElectronVolt;
122
123impl_unit!(Joule, Energy, 1.0, 0.0, "J", "Joule");
124impl_unit!(ElectronVolt, Energy, 1.602176634e-19, 0.0, "eV", "ElectronVolt");
125
126pub struct Kilogram;
128pub struct Gram;
129pub struct Pound;
130pub struct Dalton;
131
132impl_unit!(Kilogram, Mass, 1.0, 0.0, "kg", "Kilogram");
133impl_unit!(Gram, Mass, 1.0e-3, 0.0, "g", "Gram");
134impl_unit!(Pound, Mass, 0.45359237, 0.0, "lb", "Pound");
135impl_unit!(Dalton, Mass, 1.66053906660e-27, 0.0, "Da", "Dalton");
136
137pub struct Candela;
139
140impl_unit!(Candela, LuminousIntensity, 1.0, 0.0, "cd", "Candela");
141
142pub struct Mole;
144
145impl_unit!(Mole, Amount, 1.0, 0.0, "mol", "Mole");
146
147pub struct Pascal;
149pub struct Bar;
150pub struct Atmosphere;
151
152impl_unit!(Pascal, Pressure, 1.0, 0.0, "Pa", "Pascal");
153impl_unit!(Bar, Pressure, 100000.0, 0.0, "bar", "Bar");
154impl_unit!(Atmosphere, Pressure, 101325.0, 0.0, "atm", "Atmosphere");
155
156pub struct Watt;
158pub struct Horsepower;
159
160impl_unit!(Watt, Power, 1.0, 0.0, "W", "Watt");
161impl_unit!(Horsepower, Power, 745.7, 0.0, "hp", "Horsepower");
162
163pub struct SquareMeter;
165
166impl_unit!(SquareMeter, Area, 1.0, 0.0, "m²", "SquareMeter");
167
168pub struct CubicMeter;
170pub struct Liter;
171pub struct Milliliter;
172pub struct Gallon;
173
174impl_unit!(CubicMeter, Volume, 1.0, 0.0, "m³", "CubicMeter");
175impl_unit!(Liter, Volume, 1.0e-3, 0.0, "L", "Liter");
176impl_unit!(Milliliter, Volume, 1.0e-6, 0.0, "mL", "Milliliter");
177impl_unit!(Gallon, Volume, 3.78541, 0.0, "gal", "Gallon");
178
179pub struct Hertz;
181
182impl_unit!(Hertz, Frequency, 1.0, 0.0, "Hz", "Hertz");
183
184pub struct Ampere;
186
187impl_unit!(Ampere, Current, 1.0, 0.0, "A", "Ampere");
188
189use std::marker::PhantomData;
193
194pub const C: Scalar<f64,Velocity> = Scalar {
195 data: [ 299_792_458.0],
196 _phantom: PhantomData
197};
198
199pub const G: Scalar<f64,Acceleration> = Scalar {
200 data: [ 9.80665],
201 _phantom: PhantomData
202};
203
204pub const H: Scalar<f64,Energy> = Scalar {
205 data: [ 6.62607015e-34],
206 _phantom: PhantomData
207};
208
209pub const K: Scalar<f64,Temperature> = Scalar {
210 data: [ 1.380649e-23],
211 _phantom: PhantomData
212};
213
214pub const E: Scalar<f64,Energy> = Scalar {
215 data: [ 1.602176634e-19],
216 _phantom: PhantomData
217};
218
219pub const M: Scalar<f64,Mass> = Scalar {
220 data: [ 1.6726219e-27],
221 _phantom: PhantomData
222};
223