1pub mod goemetry;
5pub mod aerodynamics;
6
7use goemetry::Vec2d;
8use std::f32::consts::PI;
9
10
11pub struct Wind {
13 pub velocity: Vec2d,
14}
15
16pub struct Sail {
17}
18
19pub struct Sailboat {
20}
21
22pub struct SailboatState {
23}
24
25
26impl Wind {
27 pub fn new(velocity: Vec2d) -> Wind {
28 Wind {velocity}
29 }
30
31 pub fn direction(&self) -> f32 {
33 let phi = self.velocity.phi();
34 let alpha = phi / PI * 180.0;
35 alpha
36 }
37
38 pub fn speed(&self) -> f32 {
39 self.velocity.r()
40 }
41}
42
43impl Sailboat {
44 pub fn new() -> Sailboat {
45 Sailboat { }
46 }
47}
48
49
50pub fn apparent_wind(boat_velocity: &Vec2d, wind: &Vec2d) -> Vec2d {
51 boat_velocity.neg().add(wind)
52}
53
54#[cfg(test)]
56mod tests {
57 use crate::*;
58 use approx::assert_abs_diff_eq;
59
60 #[test]
61 fn wind_dir() {
62 assert_abs_diff_eq!(Wind::new(Vec2d::new(1., 0.)).direction(), 0.0);
63 assert_abs_diff_eq!(Wind::new(Vec2d::new(3., 3.)).direction(), 45.0);
64 assert_abs_diff_eq!(Wind::new(Vec2d::new(-3., -3.)).direction(), -135.0);
65 }
66}