Added units

pull/2/head
Mark 2023-04-13 14:10:45 -07:00
parent 5de314e11c
commit 76ac7be050
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 105 additions and 20 deletions

View File

@ -24,16 +24,21 @@ pub enum UnitBase {
Candela, Candela,
// Length units // Length units
Angstrom,
Thou,
Point, // pt, typesetting unit
Inch, Inch,
Foot, Foot,
Mile, Mile,
Furlong,
// Time units // Time units
Minute, Minute,
Hour, Hour,
Day, Day,
//Week, Week,
//Month, Month,
Fortnight,
} }
@ -46,19 +51,58 @@ pub enum UnitBase {
// (Unit, string from, (prefixes_to_generate)) // (Unit, string from, (prefixes_to_generate))
// Prefixes must be valid prefixes as defined in // Prefixes must be valid prefixes as defined in
// Prefix::str_to_prefix. // Prefix::str_to_prefix.
//
// Prefix array can be ommited to prevent prefix generation.
pub (self) use prefix::str_to_prefix; pub (self) use prefix::str_to_prefix;
macro_rules! fromstring_db { macro_rules! fromstring_db {
($X:ident) => { ($X:ident) => {
$X!( $X!(
// No prefix // Base units
(UnitBase::Meter, "meter"), (UnitBase::Meter, "meter"),
(UnitBase::Foot, "ft"), (UnitBase::Meter, "meters"),
(UnitBase::Mile, "mile"), (UnitBase::Ampere, "ampere"),
(UnitBase::Hour, "hour"), (UnitBase::Ampere, "amperes"),
(UnitBase::Minute, "min"), (UnitBase::Gram, "gram"),
(UnitBase::Day, "day"), (UnitBase::Gram, "grams"),
(UnitBase::Second, "sec"), (UnitBase::Kelvin, "kelvin"),
(UnitBase::Mole, "mole"),
(UnitBase::Candela, "candela"),
// Length
(UnitBase::Angstrom, "angstrom"),
(UnitBase::Angstrom, "Å"),
(UnitBase::Thou, "thou"),
(UnitBase::Point, "pt"),
(UnitBase::Point, "point"),
(UnitBase::Inch, "in"),
(UnitBase::Inch, "inch"),
(UnitBase::Foot, "ft"),
(UnitBase::Foot, "foot"),
(UnitBase::Foot, "feet"),
(UnitBase::Mile, "mi"),
(UnitBase::Mile, "mile"),
(UnitBase::Mile, "miles"),
// Time
(UnitBase::Second, "sec"),
(UnitBase::Second, "second"),
(UnitBase::Second, "seconds"),
(UnitBase::Minute, "min"),
(UnitBase::Minute, "minute"),
(UnitBase::Minute, "minutes"),
(UnitBase::Hour, "h"),
(UnitBase::Hour, "hour"),
(UnitBase::Hour, "hours"),
(UnitBase::Day, "d"),
(UnitBase::Day, "day"),
(UnitBase::Day, "days"),
(UnitBase::Week, "w"),
(UnitBase::Week, "week"),
(UnitBase::Week, "weeks"),
(UnitBase::Month, "month"),
(UnitBase::Month, "months"),
(UnitBase::Fortnight, "fortnight"),
(UnitBase::Fortnight, "fortnights"),
(UnitBase::Meter, "m", (UnitBase::Meter, "m",
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
@ -72,11 +116,11 @@ macro_rules! fromstring_db {
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
), ),
(UnitBase::Ampere, "a", (UnitBase::Ampere, "A",
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
), ),
(UnitBase::Kelvin, "k", (UnitBase::Kelvin, "K",
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
), ),
@ -84,7 +128,7 @@ macro_rules! fromstring_db {
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
), ),
(UnitBase::Candela, "c", (UnitBase::Candela, "cd",
("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q") ("Q","R","Y","Z","E","P","T","G","M","k","h","da","d","c","m","u","n","p","f","a","z","y","r","q")
) )
) )
@ -121,11 +165,11 @@ macro_rules! unit_db {
base base
), ),
UnitBase::Ampere => $X!( UnitBase::Ampere => $X!(
UnitBase::Ampere, "a", UnitBase::Ampere, "A",
base base
), ),
UnitBase::Kelvin => $X!( UnitBase::Kelvin => $X!(
UnitBase::Kelvin, "k", UnitBase::Kelvin, "K",
base base
), ),
UnitBase::Mole => $X!( UnitBase::Mole => $X!(
@ -133,12 +177,11 @@ macro_rules! unit_db {
base base
), ),
UnitBase::Candela => $X!( UnitBase::Candela => $X!(
UnitBase::Candela, "c", UnitBase::Candela, "cd",
base base
), ),
UnitBase::Minute => $X!( UnitBase::Minute => $X!(
UnitBase::Minute, "min", UnitBase::Minute, "min",
@ -170,9 +213,39 @@ macro_rules! unit_db {
(UnitBase::Second, 1f64) (UnitBase::Second, 1f64)
), ),
UnitBase::Foot => $X!( UnitBase::Week => $X!(
UnitBase::Foot, "ft", UnitBase::Week, "week",
float, "0.3048", rational, "604800",
(UnitBase::Second, 1f64)
),
UnitBase::Month => $X!(
UnitBase::Month, "month",
rational, "2629746",
(UnitBase::Second, 1f64)
),
UnitBase::Fortnight => $X!(
UnitBase::Fortnight, "fortnight",
rational, "1209600",
(UnitBase::Second, 1f64)
),
UnitBase::Angstrom => $X!(
UnitBase::Angstrom, "Å",
rational, "1e-10",
(UnitBase::Meter, 1f64)
),
UnitBase::Thou => $X!(
UnitBase::Thou, "thou",
float, "0.0000254",
(UnitBase::Meter, 1f64)
),
UnitBase::Point => $X!(
UnitBase::Point, "pt",
float, "0.000352778",
(UnitBase::Meter, 1f64) (UnitBase::Meter, 1f64)
), ),
@ -182,11 +255,23 @@ macro_rules! unit_db {
(UnitBase::Meter, 1f64) (UnitBase::Meter, 1f64)
), ),
UnitBase::Foot => $X!(
UnitBase::Foot, "ft",
float, "0.3048",
(UnitBase::Meter, 1f64)
),
UnitBase::Mile => $X!( UnitBase::Mile => $X!(
UnitBase::Mile, "mile", UnitBase::Mile, "mi",
float, "1609", float, "1609",
(UnitBase::Meter, 1f64) (UnitBase::Meter, 1f64)
), ),
UnitBase::Furlong => $X!(
UnitBase::Furlong, "furlong",
float, "201.168",
(UnitBase::Meter, 1f64)
),
} }