From 356a3c7824c4792b6cd278de5cbc804a8c3c17ec Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 14 Apr 2023 11:05:25 -0700 Subject: [PATCH] More units --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/quantity/unit/mod.rs | 67 ++++++++++++++++++++++++++++++++++++++++ units.md | 12 ------- 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df2c4d9..6b95031 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "daisy" -version = "0.1.2" +version = "0.1.3" dependencies = [ "cfg-if", "rug", diff --git a/Cargo.toml b/Cargo.toml index ba9715c..e582d60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daisy" -version = "0.1.2" +version = "0.1.3" edition = "2021" [profile.release] diff --git a/src/quantity/unit/mod.rs b/src/quantity/unit/mod.rs index e0d0d6e..6bf8fd7 100644 --- a/src/quantity/unit/mod.rs +++ b/src/quantity/unit/mod.rs @@ -33,6 +33,16 @@ pub enum UnitBase { Furlong, Mile, AstronomicalUnit, + Lightyear, + Parsec, + + // Area + Barn, + Hectare, + MilesPerHour, + Acre, + + // Time units Minute, @@ -146,6 +156,12 @@ macro_rules! fromstring_db { (UnitBase::AstronomicalUnit, "AU"), (UnitBase::AstronomicalUnit, "astronomicalUnit"), (UnitBase::AstronomicalUnit, "astronomicalUnits"), + (UnitBase::Lightyear, "ly"), + (UnitBase::Lightyear, "lightyear"), + (UnitBase::Lightyear, "lightyears"), + (UnitBase::Parsec, "pc"), + (UnitBase::Parsec, "parsec"), + (UnitBase::Parsec, "parsecs"), // Time (UnitBase::Second, "sec"), @@ -172,6 +188,17 @@ macro_rules! fromstring_db { (UnitBase::JulianYear, "julianYear"), (UnitBase::JulianYear, "julianYears"), + // Misc + (UnitBase::MilesPerHour, "mph"), + (UnitBase::Barn, "b"), + (UnitBase::Barn, "barn"), + (UnitBase::Hectare, "ha"), + (UnitBase::Hectare, "hectare"), + (UnitBase::Hectare, "hectares"), + (UnitBase::Acre, "acre"), + (UnitBase::Acre, "acres"), + + // Volume (UnitBase::Liter, "liter"), (UnitBase::Liter, "liters"), @@ -416,6 +443,46 @@ macro_rules! unit_db { (UnitBase::Meter, 1f64) ), + UnitBase::Lightyear => $X!( + UnitBase::Lightyear, "ly", + rational, "9460730472580800", + (UnitBase::Meter, 1f64) + ), + + UnitBase::Parsec => $X!( + UnitBase::Parsec, "pc", + float, "3.085677581e16", + (UnitBase::Meter, 1f64) + ), + + + // Misc + UnitBase::MilesPerHour => $X!( + UnitBase::MilesPerHour, "mph", + rational, "1609.344", + (UnitBase::Meter, 1f64), + (UnitBase::Second, -1f64) + ), + + UnitBase::Barn => $X!( + UnitBase::Barn, "b", + rational, "1e-28", + (UnitBase::Meter, 2f64) + ), + + UnitBase::Hectare => $X!( + UnitBase::Hectare, "ha", + rational, "10000", + (UnitBase::Meter, 2f64) + ), + + UnitBase::Acre => $X!( // 66 x 660 feet + UnitBase::Acre, "acre", + rational, "4046.8564224", + (UnitBase::Meter, 2f64) + ), + + // Volume UnitBase::Liter => $X!( diff --git a/units.md b/units.md index 90050f2..785a8d7 100644 --- a/units.md +++ b/units.md @@ -1,8 +1,3 @@ -legal cup - - | Unit | Syntax | - |------------------------------------------------------------------------------|-----------------------------------------------------------------------------| - | [Barn](https://en.wikipedia.org/wiki/Barn_(unit)) | `barn` | | [Becquerel](https://en.wikipedia.org/wiki/Becquerel) | `becquerel`, `Bq` | | [Bel](https://en.wikipedia.org/wiki/Decibel) | `bel` | | [Bit](https://en.wikipedia.org/wiki/Bit) | `bits`, `bit` | @@ -12,7 +7,6 @@ legal cup | [Calorie](https://en.wikipedia.org/wiki/Calorie) | `calories`, `calorie`, `cal` | | [Coulomb](https://en.wikipedia.org/wiki/Coulomb) | `coulomb`, `C` | | [DPI](https://en.wikipedia.org/wiki/Dots_per_inch) | `dpi` | - | [Day](https://en.wikipedia.org/wiki/Day) | `days`, `day`, `d` | | [Degree](https://en.wikipedia.org/wiki/Degree_(angle)) | `degrees`, `degree`, `deg`, `°` | | [Dot](https://en.wikipedia.org/wiki/Dots_per_inch) | `dots`, `dot` | | [Electronvolt](https://en.wikipedia.org/wiki/Electronvolt) | `electronvolt`, `eV` | @@ -22,22 +16,16 @@ legal cup | [Frames per second](https://en.wikipedia.org/wiki/Frame_rate) | `fps` | | [Gauss](https://en.wikipedia.org/wiki/Gauss_(unit)) | `gauss` | | [Gray](https://en.wikipedia.org/wiki/Gray_(unit)) | `gray`, `Gy` | - | [Hectare](https://en.wikipedia.org/wiki/Hectare) | `hectare`, `ha` | | [Henry](https://en.wikipedia.org/wiki/Henry_(unit)) | `henrys`, `henries`, `henry`, `H` | | [Hertz](https://en.wikipedia.org/wiki/Hertz) | `hertz`, `Hz` | | [Joule](https://en.wikipedia.org/wiki/Joule) | `joules`, `joule`, `J` | | [Katal](https://en.wikipedia.org/wiki/Katal) | `katal`, `kat` | - | [Kelvin](https://en.wikipedia.org/wiki/Kelvin) | `kelvin`, `K` | - | [Light-year](https://en.wikipedia.org/wiki/Light-year) | `lightyears`, `lightyear`, `ly` | | [Lumen](https://en.wikipedia.org/wiki/Lumen_(unit)) | `lumen`, `lm` | | [Lux](https://en.wikipedia.org/wiki/Lux) | `lux`, `lx` | - | [Miles per hour](https://en.wikipedia.org/wiki/Miles_per_hour) | `mph` | - | [Millimeter of mercury](https://en.wikipedia.org/wiki/Millimeter_of_mercury) | `mmHg` | | [Newton](https://en.wikipedia.org/wiki/Newton_(unit)) | `newton`, `N` | | [Ohm](https://en.wikipedia.org/wiki/Ohm) | `ohms`, `ohm`, `Ω` | | [Ounce](https://en.wikipedia.org/wiki/Ounce) | `ounces`, `ounce`, `oz` | | [PPI](https://en.wikipedia.org/wiki/Pixels_per_inch) | `ppi` | - | [Parsec](https://en.wikipedia.org/wiki/Parsec) | `parsecs`, `parsec`, `pc` | | [Parts-per-million](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppm` | | [Parts-per-billion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppb` | | [Parts-per-trillion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppt` |