siderust-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
//! Power units.
|
|
2
|
+
//!
|
|
3
|
+
//! The canonical scaling unit for this dimension is [`Watt`] (`Watt::RATIO == 1.0`).
|
|
4
|
+
//!
|
|
5
|
+
//! This module focuses on completeness without baking in avoidable precision loss:
|
|
6
|
+
//! - Full SI prefix ladder on the watt (yocto … yotta).
|
|
7
|
+
//! - A small set of widely used non-SI units with unambiguous definitions.
|
|
8
|
+
//! - Nominal astronomical reference: solar luminosity (IAU).
|
|
9
|
+
//!
|
|
10
|
+
//! ```rust
|
|
11
|
+
//! use qtty_core::power::{SolarLuminosities, Watt};
|
|
12
|
+
//!
|
|
13
|
+
//! let sol = SolarLuminosities::new(1.0);
|
|
14
|
+
//! let w = sol.to::<Watt>();
|
|
15
|
+
//! assert!((w.value() - 3.828e26).abs() < 1e18);
|
|
16
|
+
//! ```
|
|
17
|
+
//!
|
|
18
|
+
//! ## All power units
|
|
19
|
+
//!
|
|
20
|
+
//! ```rust
|
|
21
|
+
//! use qtty_core::power::*;
|
|
22
|
+
//! use qtty_core::Quantity;
|
|
23
|
+
//!
|
|
24
|
+
//! macro_rules! touch {
|
|
25
|
+
//! ($T:ty, $v:expr) => {{ let q = <$T>::new($v); let _c = q; assert!(q == q); }};
|
|
26
|
+
//! }
|
|
27
|
+
//!
|
|
28
|
+
//! touch!(Watts, 1.0);
|
|
29
|
+
//! touch!(Kilowatts, 1.0); touch!(Megawatts, 1.0); touch!(Gigawatts, 1.0);
|
|
30
|
+
//! touch!(Milliwatts, 1.0); touch!(Microwatts, 1.0);
|
|
31
|
+
//! touch!(HorsepowerMetrics, 1.0); touch!(HorsepowerElectrics, 1.0);
|
|
32
|
+
//! touch!(SolarLuminosities, 1.0);
|
|
33
|
+
//! let erg = Quantity::<ErgPerSecond>::new(1.0);
|
|
34
|
+
//! assert!(erg == erg);
|
|
35
|
+
//! ```
|
|
36
|
+
|
|
37
|
+
use crate::{Quantity, Unit};
|
|
38
|
+
use qtty_derive::Unit;
|
|
39
|
+
|
|
40
|
+
/// Re-export from the dimension module.
|
|
41
|
+
pub use crate::dimension::Power;
|
|
42
|
+
|
|
43
|
+
/// Marker trait for power units.
|
|
44
|
+
pub trait PowerUnit: Unit<Dim = Power> {}
|
|
45
|
+
impl<T: Unit<Dim = Power>> PowerUnit for T {}
|
|
46
|
+
|
|
47
|
+
/// Watt (SI coherent derived unit).
|
|
48
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
49
|
+
#[unit(symbol = "W", dimension = Power, ratio = 1.0)]
|
|
50
|
+
pub struct Watt;
|
|
51
|
+
/// Type alias shorthand for [`Watt`].
|
|
52
|
+
pub type W = Watt;
|
|
53
|
+
/// A quantity measured in watts.
|
|
54
|
+
pub type Watts = Quantity<W>;
|
|
55
|
+
/// One watt.
|
|
56
|
+
pub const WATT: Watts = Watts::new(1.0);
|
|
57
|
+
|
|
58
|
+
macro_rules! si_watt {
|
|
59
|
+
($name:ident, $sym:literal, $ratio:expr, $alias:ident, $qty:ident, $one:ident) => {
|
|
60
|
+
#[doc = concat!("SI-prefixed watt unit (", stringify!($ratio), " W).")]
|
|
61
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
62
|
+
#[unit(symbol = $sym, dimension = Power, ratio = $ratio)]
|
|
63
|
+
pub struct $name;
|
|
64
|
+
#[doc = concat!("Type alias shorthand for [`", stringify!($name), "`].")]
|
|
65
|
+
pub type $alias = $name;
|
|
66
|
+
#[doc = concat!("A quantity measured in ", stringify!($name), "s.")]
|
|
67
|
+
pub type $qty = Quantity<$alias>;
|
|
68
|
+
#[doc = concat!("One ", stringify!($name), ".")]
|
|
69
|
+
pub const $one: $qty = $qty::new(1.0);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Full SI prefix ladder on watt
|
|
74
|
+
si_watt!(Yoctowatt, "yW", 1e-24, Yw, Yoctowatts, YW);
|
|
75
|
+
si_watt!(Zeptowatt, "zW", 1e-21, Zw, Zeptowatts, ZW);
|
|
76
|
+
si_watt!(Attowatt, "aW", 1e-18, Aw, Attowatts, AW);
|
|
77
|
+
si_watt!(Femtowatt, "fW", 1e-15, Fw, Femtowatts, FW);
|
|
78
|
+
si_watt!(Picowatt, "pW", 1e-12, Pw, Picowatts, PW);
|
|
79
|
+
si_watt!(Nanowatt, "nW", 1e-9, Nw, Nanowatts, NW);
|
|
80
|
+
si_watt!(Microwatt, "µW", 1e-6, Uw, Microwatts, UW);
|
|
81
|
+
si_watt!(Milliwatt, "mW", 1e-3, Mw, Milliwatts, MW_1);
|
|
82
|
+
|
|
83
|
+
si_watt!(Deciwatt, "dW", 1e-1, Dw, Deciwatts, DW);
|
|
84
|
+
si_watt!(Decawatt, "daW", 1e1, Daw, Decawatts, DAW);
|
|
85
|
+
si_watt!(Hectowatt, "hW", 1e2, Hw, Hectowatts, HW);
|
|
86
|
+
si_watt!(Kilowatt, "kW", 1e3, Kw, Kilowatts, KW);
|
|
87
|
+
si_watt!(Megawatt, "MW", 1e6, MW, Megawatts, MEGAWATT);
|
|
88
|
+
si_watt!(Gigawatt, "GW", 1e9, GW, Gigawatts, GW_1);
|
|
89
|
+
si_watt!(Terawatt, "TW", 1e12, TW, Terawatts, TW_1);
|
|
90
|
+
si_watt!(Petawatt, "PW", 1e15, PW, Petawatts, PETAWATT);
|
|
91
|
+
si_watt!(Exawatt, "EW", 1e18, EW, Exawatts, EW_1);
|
|
92
|
+
si_watt!(Zettawatt, "ZW", 1e21, ZW, Zettawatts, ZW_1);
|
|
93
|
+
si_watt!(Yottawatt, "YW", 1e24, YW, Yottawatts, YW_1);
|
|
94
|
+
|
|
95
|
+
/// Erg per second (`erg/s`).
|
|
96
|
+
///
|
|
97
|
+
/// Exact: `1 erg = 1e-7 J`, so `1 erg/s = 1e-7 W`.
|
|
98
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
99
|
+
#[unit(symbol = "erg/s", dimension = Power, ratio = 1e-7)]
|
|
100
|
+
pub struct ErgPerSecond;
|
|
101
|
+
/// One erg/s.
|
|
102
|
+
pub const ERG_PER_S: Quantity<ErgPerSecond> = Quantity::new(1.0);
|
|
103
|
+
|
|
104
|
+
/// Metric horsepower (`PS`), defined as exactly `735.49875 W`.
|
|
105
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
106
|
+
#[unit(symbol = "PS", dimension = Power, ratio = 73_549_875.0 / 100_000.0)]
|
|
107
|
+
pub struct HorsepowerMetric;
|
|
108
|
+
/// A quantity measured in metric horsepower.
|
|
109
|
+
pub type HorsepowerMetrics = Quantity<HorsepowerMetric>;
|
|
110
|
+
/// One metric horsepower.
|
|
111
|
+
pub const PS: HorsepowerMetrics = HorsepowerMetrics::new(1.0);
|
|
112
|
+
|
|
113
|
+
/// Electric horsepower (`hp_e`), defined as exactly `746 W`.
|
|
114
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
115
|
+
#[unit(symbol = "hp_e", dimension = Power, ratio = 746.0)]
|
|
116
|
+
pub struct HorsepowerElectric;
|
|
117
|
+
/// A quantity measured in electric horsepower.
|
|
118
|
+
pub type HorsepowerElectrics = Quantity<HorsepowerElectric>;
|
|
119
|
+
/// One electric horsepower.
|
|
120
|
+
pub const HP_E: HorsepowerElectrics = HorsepowerElectrics::new(1.0);
|
|
121
|
+
|
|
122
|
+
/// Solar luminosity (IAU nominal constant; watts per L☉).
|
|
123
|
+
///
|
|
124
|
+
/// This is a *nominal reference* value intended for consistent conversion.
|
|
125
|
+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Unit)]
|
|
126
|
+
#[unit(symbol = "L☉", dimension = Power, ratio = 3.828e26)]
|
|
127
|
+
pub struct SolarLuminosity;
|
|
128
|
+
/// A quantity measured in solar luminosities.
|
|
129
|
+
pub type SolarLuminosities = Quantity<SolarLuminosity>;
|
|
130
|
+
/// One solar luminosity.
|
|
131
|
+
pub const L_SUN: SolarLuminosities = SolarLuminosities::new(1.0);
|
|
132
|
+
|
|
133
|
+
// Generate all bidirectional From implementations between power units.
|
|
134
|
+
crate::impl_unit_from_conversions!(
|
|
135
|
+
Watt,
|
|
136
|
+
Yoctowatt,
|
|
137
|
+
Zeptowatt,
|
|
138
|
+
Attowatt,
|
|
139
|
+
Femtowatt,
|
|
140
|
+
Picowatt,
|
|
141
|
+
Nanowatt,
|
|
142
|
+
Microwatt,
|
|
143
|
+
Milliwatt,
|
|
144
|
+
Deciwatt,
|
|
145
|
+
Decawatt,
|
|
146
|
+
Hectowatt,
|
|
147
|
+
Kilowatt,
|
|
148
|
+
Megawatt,
|
|
149
|
+
Gigawatt,
|
|
150
|
+
Terawatt,
|
|
151
|
+
Petawatt,
|
|
152
|
+
Exawatt,
|
|
153
|
+
Zettawatt,
|
|
154
|
+
Yottawatt,
|
|
155
|
+
ErgPerSecond,
|
|
156
|
+
HorsepowerMetric,
|
|
157
|
+
HorsepowerElectric,
|
|
158
|
+
SolarLuminosity
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// Optional cross-unit operator support (`==`, `<`, etc.).
|
|
162
|
+
#[cfg(feature = "cross-unit-ops")]
|
|
163
|
+
crate::impl_unit_cross_unit_ops!(
|
|
164
|
+
Watt,
|
|
165
|
+
Yoctowatt,
|
|
166
|
+
Zeptowatt,
|
|
167
|
+
Attowatt,
|
|
168
|
+
Femtowatt,
|
|
169
|
+
Picowatt,
|
|
170
|
+
Nanowatt,
|
|
171
|
+
Microwatt,
|
|
172
|
+
Milliwatt,
|
|
173
|
+
Deciwatt,
|
|
174
|
+
Decawatt,
|
|
175
|
+
Hectowatt,
|
|
176
|
+
Kilowatt,
|
|
177
|
+
Megawatt,
|
|
178
|
+
Gigawatt,
|
|
179
|
+
Terawatt,
|
|
180
|
+
Petawatt,
|
|
181
|
+
Exawatt,
|
|
182
|
+
Zettawatt,
|
|
183
|
+
Yottawatt,
|
|
184
|
+
ErgPerSecond,
|
|
185
|
+
HorsepowerMetric,
|
|
186
|
+
HorsepowerElectric,
|
|
187
|
+
SolarLuminosity
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
#[cfg(test)]
|
|
191
|
+
mod tests {
|
|
192
|
+
use super::*;
|
|
193
|
+
use approx::assert_relative_eq;
|
|
194
|
+
use proptest::prelude::*;
|
|
195
|
+
|
|
196
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
197
|
+
// Basic conversions
|
|
198
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
199
|
+
|
|
200
|
+
#[test]
|
|
201
|
+
fn solar_luminosity_to_watts() {
|
|
202
|
+
let sol = SolarLuminosities::new(1.0);
|
|
203
|
+
let w = sol.to::<Watt>();
|
|
204
|
+
// 1 L☉ = 3.828e26 W
|
|
205
|
+
assert_relative_eq!(w.value(), 3.828e26, max_relative = 1e-9);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#[test]
|
|
209
|
+
fn watts_to_solar_luminosity() {
|
|
210
|
+
let w = Watts::new(3.828e26);
|
|
211
|
+
let sol = w.to::<SolarLuminosity>();
|
|
212
|
+
assert_relative_eq!(sol.value(), 1.0, max_relative = 1e-9);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[test]
|
|
216
|
+
fn multiple_solar_luminosities() {
|
|
217
|
+
let sol = SolarLuminosities::new(3.0);
|
|
218
|
+
let w = sol.to::<Watt>();
|
|
219
|
+
assert_relative_eq!(w.value(), 3.0 * 3.828e26, max_relative = 1e-9);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
223
|
+
// Solar luminosity sanity checks
|
|
224
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
#[test]
|
|
227
|
+
fn solar_luminosity_ratio_sanity() {
|
|
228
|
+
// RATIO should be 3.828e26
|
|
229
|
+
assert_relative_eq!(SolarLuminosity::RATIO, 3.828e26, max_relative = 1e-9);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#[test]
|
|
233
|
+
fn solar_luminosity_order_of_magnitude() {
|
|
234
|
+
let sun = SolarLuminosities::new(1.0);
|
|
235
|
+
let w = sun.to::<Watt>();
|
|
236
|
+
// Should be between 1e26 and 1e27
|
|
237
|
+
assert!(w.value() > 1e26);
|
|
238
|
+
assert!(w.value() < 1e27);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
242
|
+
// Roundtrip conversions
|
|
243
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
244
|
+
|
|
245
|
+
#[test]
|
|
246
|
+
fn roundtrip_w_sol() {
|
|
247
|
+
let original = Watts::new(1e26);
|
|
248
|
+
let converted = original.to::<SolarLuminosity>();
|
|
249
|
+
let back = converted.to::<Watt>();
|
|
250
|
+
assert_relative_eq!(back.value(), original.value(), max_relative = 1e-12);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
254
|
+
// Property-based tests
|
|
255
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
256
|
+
|
|
257
|
+
proptest! {
|
|
258
|
+
#[test]
|
|
259
|
+
fn prop_roundtrip_w_sol(w in 1e20..1e30f64) {
|
|
260
|
+
let original = Watts::new(w);
|
|
261
|
+
let converted = original.to::<SolarLuminosity>();
|
|
262
|
+
let back = converted.to::<Watt>();
|
|
263
|
+
prop_assert!((back.value() - original.value()).abs() / original.value() < 1e-12);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ─── SI-prefixed watt units ──────────────────────────────────────────────
|
|
268
|
+
|
|
269
|
+
#[test]
|
|
270
|
+
fn kilowatt_to_watt() {
|
|
271
|
+
let kw = Kilowatts::new(1.0);
|
|
272
|
+
let w = kw.to::<Watt>();
|
|
273
|
+
assert_relative_eq!(w.value(), 1_000.0, max_relative = 1e-12);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#[test]
|
|
277
|
+
fn megawatt_to_kilowatt() {
|
|
278
|
+
let mw = Megawatts::new(1.0);
|
|
279
|
+
let kw = mw.to::<Kilowatt>();
|
|
280
|
+
assert_relative_eq!(kw.value(), 1_000.0, max_relative = 1e-12);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[test]
|
|
284
|
+
fn milliwatt_to_watt() {
|
|
285
|
+
let mw = Milliwatts::new(1000.0);
|
|
286
|
+
let w = mw.to::<Watt>();
|
|
287
|
+
assert_relative_eq!(w.value(), 1.0, max_relative = 1e-12);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ─── Non-SI power units ──────────────────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
#[test]
|
|
293
|
+
fn erg_per_second_to_watt() {
|
|
294
|
+
let erg_s = Quantity::<ErgPerSecond>::new(1e7);
|
|
295
|
+
let w = erg_s.to::<Watt>();
|
|
296
|
+
// 1e7 erg/s = 1 W
|
|
297
|
+
assert_relative_eq!(w.value(), 1.0, max_relative = 1e-9);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#[test]
|
|
301
|
+
fn metric_horsepower_to_watt() {
|
|
302
|
+
let ps = HorsepowerMetrics::new(1.0);
|
|
303
|
+
let w = ps.to::<Watt>();
|
|
304
|
+
// 1 PS = 735.49875 W
|
|
305
|
+
assert_relative_eq!(w.value(), 735.498_75, max_relative = 1e-9);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#[test]
|
|
309
|
+
fn electric_horsepower_to_watt() {
|
|
310
|
+
let hp = HorsepowerElectrics::new(1.0);
|
|
311
|
+
let w = hp.to::<Watt>();
|
|
312
|
+
// 1 hp_e = 746 W (exact)
|
|
313
|
+
assert_relative_eq!(w.value(), 746.0, max_relative = 1e-12);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#[test]
|
|
317
|
+
fn symbols_are_correct() {
|
|
318
|
+
assert_eq!(Watt::SYMBOL, "W");
|
|
319
|
+
assert_eq!(Kilowatt::SYMBOL, "kW");
|
|
320
|
+
assert_eq!(Megawatt::SYMBOL, "MW");
|
|
321
|
+
assert_eq!(HorsepowerMetric::SYMBOL, "PS");
|
|
322
|
+
assert_eq!(ErgPerSecond::SYMBOL, "erg/s");
|
|
323
|
+
}
|
|
324
|
+
}
|