finishing touches
parent
da397ddd25
commit
692f8334fc
11
build.rs
11
build.rs
|
@ -356,6 +356,7 @@ fn main() {
|
|||
}
|
||||
};
|
||||
let (dimensions, units) = gen_units();
|
||||
let prefixes = gen_prefixes();
|
||||
let modules = quote!{
|
||||
pub mod prelude {
|
||||
pub use crate::units::{
|
||||
|
@ -366,7 +367,7 @@ fn main() {
|
|||
MetersPerSecondPerSecond,
|
||||
Second,
|
||||
};
|
||||
pub use crate::{
|
||||
pub use crate::prefixes::{
|
||||
Centi,
|
||||
Kilo,
|
||||
Micro,
|
||||
|
@ -385,9 +386,15 @@ fn main() {
|
|||
};
|
||||
#units
|
||||
}
|
||||
pub mod prefixes {
|
||||
use crate::{
|
||||
Measurement,
|
||||
Unit,
|
||||
};
|
||||
#prefixes
|
||||
}
|
||||
};
|
||||
code.extend(modules);
|
||||
code.extend(gen_prefixes());
|
||||
File::create(&dest_path).unwrap().write_all(code.to_string().as_bytes()).unwrap();
|
||||
println!["cargo:rerun-if-changed=build.rs"];
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use units::{
|
||||
dimensions::Length,
|
||||
units::{Feet, Meters},
|
||||
units::{
|
||||
Feet,
|
||||
Meter,
|
||||
},
|
||||
Unit,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
println!["{}", Length::new::<Feet>(1601.0).val::<Meters>()];
|
||||
println!["{}", Feet::new(1601.0).to_units::<Meter>()];
|
||||
}
|
||||
|
|
|
@ -8,13 +8,16 @@ use units::{
|
|||
Length,
|
||||
Mass,
|
||||
MassMoment,
|
||||
}, units::{
|
||||
},
|
||||
units::{
|
||||
Gram,
|
||||
Joule,
|
||||
Meter,
|
||||
Rpm,
|
||||
Watthour,
|
||||
}, Kilo, Unit
|
||||
},
|
||||
Unit,
|
||||
prefixes::Kilo,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
use std::{f64::consts::PI, f64::consts::TAU};
|
||||
use std::{
|
||||
f64::consts::PI,
|
||||
f64::consts::TAU,
|
||||
};
|
||||
use units::{
|
||||
dimensions::{Density, Frequency, Length, Pressure, Speed},
|
||||
prefixes::{Deci, Mega},
|
||||
units::{density::KgPerCubicMeter, Meters, MetersPerSecond, Pascals, Rpm},
|
||||
dimensions::{
|
||||
Density,
|
||||
Frequency,
|
||||
Length,
|
||||
Pressure,
|
||||
Speed,
|
||||
},
|
||||
units::{
|
||||
KgPerCubicMeter,
|
||||
Meter,
|
||||
MetersPerSecond,
|
||||
Pascal,
|
||||
Rpm,
|
||||
},
|
||||
prefixes::{
|
||||
Deci,
|
||||
Mega,
|
||||
},
|
||||
Unit,
|
||||
};
|
||||
|
||||
pub fn speed_to_rpm(tip_speed: Speed, radius: Length) -> Frequency {
|
||||
tip_speed / (TAU * radius)
|
||||
tip_speed / (radius * TAU)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -20,33 +39,34 @@ pub struct Flywheel {
|
|||
impl Flywheel {
|
||||
pub fn steel(radius: Length, thickness: Length) -> Self {
|
||||
Self {
|
||||
tensile_strength: Pressure::new::<Mega<Pascals>>(700.0),
|
||||
tensile_strength: Mega::<Pascal>::new(700.0),
|
||||
density: Density::new::<KgPerCubicMeter>(7850.0),
|
||||
radius,
|
||||
thickness,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wood(radius: Length, thickness: Length) -> Self {
|
||||
Self {
|
||||
tensile_strength: Pressure::new::<Mega<Pascals>>(105.0),
|
||||
tensile_strength: Mega::<Pascal>::new(105.0),
|
||||
density: Density::new::<KgPerCubicMeter>(700.0),
|
||||
radius,
|
||||
thickness,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_velocity(&self) -> Speed {
|
||||
Speed::new::<MetersPerSecond>(
|
||||
((self.tensile_strength * 2.0 * self.thickness)
|
||||
/ (self.density * PI.powf(2.0) * self.radius.square()))
|
||||
.val::<units::units::MetersPerSqTime>()
|
||||
.powf(0.5),
|
||||
((self.tensile_strength * 2.0 * self.thickness) / (self.density * PI.powf(2.0) * self.radius.square()))
|
||||
.to_units::<units::units::MetersPerSecondPerSecond>()
|
||||
.powf(0.5),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let steel = Flywheel::steel(Length::new::<Meters>(0.5), Length::new::<Deci<Meters>>(1.0));
|
||||
let steel = Flywheel::steel(Meter::new(0.5), Deci::<Meter>::new(1.0));
|
||||
let max_rpm = speed_to_rpm(steel.max_velocity(), steel.radius);
|
||||
println!["{steel:?}"];
|
||||
println!["{}", max_rpm.val::<Rpm>()];
|
||||
println!["{}", max_rpm.to_units::<Rpm>()];
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct Measurement<
|
|||
const AMOUNT: i8,
|
||||
const INTENSITY: i8,
|
||||
>(
|
||||
f64,
|
||||
pub f64,
|
||||
);
|
||||
|
||||
impl<
|
||||
|
@ -44,8 +44,8 @@ impl<
|
|||
self.0.sub(U::offset()).div(U::scale())
|
||||
}
|
||||
|
||||
pub fn val(self) -> f64 {
|
||||
self.0
|
||||
pub fn square(self) -> Self {
|
||||
Self(self.0.powf(2.0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue