use_statics_basic_usage/
basic_usage.rs1use use_statics::{
2 CantileverReaction, Force2D, StaticSystem2D, cantilever_end_point_load_reaction,
3 simply_supported_point_load_reactions,
4};
5
6fn approx_eq(left: f64, right: f64, tolerance: f64) {
7 assert!(
8 (left - right).abs() <= tolerance,
9 "expected {left} to be within {tolerance} of {right}"
10 );
11}
12
13fn main() {
14 let Some(force_left) = Force2D::new(100.0, 0.0) else {
15 panic!("valid force should construct");
16 };
17 let Some(force_right) = Force2D::new(-100.0, 0.0) else {
18 panic!("valid force should construct");
19 };
20
21 let Some(system) = StaticSystem2D::new(vec![force_left, force_right], vec![0.0]) else {
22 panic!("valid system should construct");
23 };
24
25 assert_eq!(system.is_equilibrium(0.0), Some(true));
26
27 let Some((left, right)) = simply_supported_point_load_reactions(10.0, 100.0, 5.0) else {
28 panic!("valid point load should produce reactions");
29 };
30
31 approx_eq(left, 50.0, 1.0e-12);
32 approx_eq(right, 50.0, 1.0e-12);
33
34 assert_eq!(
35 cantilever_end_point_load_reaction(10.0, 100.0),
36 Some(CantileverReaction {
37 vertical_reaction: 100.0,
38 fixed_end_moment: 1000.0,
39 })
40 );
41}