uom/si/
solid_angle.rs

1//! Solid angle (dimensionless quantity).
2
3quantity! {
4    /// Solid angle (dimensionless quantity).
5    quantity: SolidAngle; "solid angle";
6    /// Dimension of solid angle, 1 (dimensionless).
7    dimension: ISQ<
8        Z0,     // length
9        Z0,     // mass
10        Z0,     // time
11        Z0,     // electric current
12        Z0,     // thermodynamic temperature
13        Z0,     // amount of substance
14        Z0>;    // luminous intensity
15    kind: dyn (crate::si::marker::SolidAngleKind);
16    units {
17        /// SI derived unit of solid angle is steradians. It is the solid angle subtended at the
18        /// center of a unit sphere by a unit area on its surface.
19        @steradian: 1.0_E0; "sr", "steradian", "steradians";
20        @spat: 1.256_637_061_435_917_3_E1; "sp", "spat", "spats";
21        @square_degree: 3.046_174_197_867_086_E-4; "°²", "square degree", "square degrees";
22        @square_minute: 8.461_594_994_075_238_9_E-8; "′²", "square minute", "square minutes";
23        @square_second: 2.350_443_053_909_788_6_E-11; "″²", "square second", "square seconds";
24    }
25}
26
27#[cfg(feature = "f32")]
28impl SolidAngle<crate::si::SI<f32>, f32> {
29    /// The solid angle subtended by a sphere at its center, i.e. with a value 4π as measured in
30    /// steradians.
31    pub const SPHERE: Self = Self {
32        dimension: crate::lib::marker::PhantomData,
33        units: crate::lib::marker::PhantomData,
34        value: 4. * crate::lib::f32::consts::PI,
35    };
36}
37
38#[cfg(feature = "f64")]
39impl SolidAngle<crate::si::SI<f64>, f64> {
40    /// The solid angle subtended by a sphere at its center, i.e. with a value 4π as measured in
41    /// steradians.
42    pub const SPHERE: Self = Self {
43        dimension: crate::lib::marker::PhantomData,
44        units: crate::lib::marker::PhantomData,
45        value: 4. * crate::lib::f64::consts::PI,
46    };
47}
48
49#[cfg(test)]
50mod tests {
51    storage_types! {
52        use crate::lib::f64::consts::PI;
53        use crate::num::{FromPrimitive, One};
54        use crate::si::quantities::*;
55        use crate::si::solid_angle as sa;
56        use crate::tests::Test;
57
58        #[test]
59        fn check_units() {
60            Test::assert_eq(&SolidAngle::new::<sa::steradian>(V::from_f64(4.0 * PI).unwrap()),
61                &SolidAngle::new::<sa::spat>(V::one()));
62            Test::assert_approx_eq(
63                &SolidAngle::new::<sa::square_degree>(V::from_f64(360.0 * 360.0 / PI).unwrap()),
64                &SolidAngle::new::<sa::spat>(V::one()));
65            Test::assert_approx_eq(
66                &SolidAngle::new::<sa::square_minute>(V::from_f64(60.0 * 60.0).unwrap()),
67                &SolidAngle::new::<sa::square_degree>(V::one()));
68            Test::assert_approx_eq(
69                &SolidAngle::new::<sa::square_second>(
70                    V::from_f64((60.0 * 60.0) * (60.0 * 60.0)).unwrap()),
71                &SolidAngle::new::<sa::square_degree>(V::one()));
72        }
73    }
74}