starfall/astronomy/planet/
mod.rs1use crate::astronomy::gas_giant_planet::GasGiantPlanet;
2use crate::astronomy::terrestrial_planet::TerrestrialPlanet;
3
4pub mod constants;
5pub mod constraints;
6pub mod error;
7use error::Error;
8pub mod math;
9
10#[derive(Clone, Debug, PartialEq)]
12pub enum Planet {
13 GasGiantPlanet(GasGiantPlanet),
15 TerrestrialPlanet(TerrestrialPlanet),
17}
18
19impl Planet {
20 #[named]
22 pub fn get_density(&self) -> f64 {
23 trace_enter!();
24 use Planet::*;
25 let result = match &self {
26 TerrestrialPlanet(terrestrial_planet) => terrestrial_planet.density,
27 GasGiantPlanet(gas_giant_planet) => gas_giant_planet.density,
28 };
29 trace_var!(result);
30 trace_exit!();
31 result
32 }
33
34 #[named]
36 pub fn get_mass(&self) -> f64 {
37 trace_enter!();
38 use Planet::*;
39 let result = match &self {
40 TerrestrialPlanet(terrestrial_planet) => terrestrial_planet.mass,
41 GasGiantPlanet(gas_giant_planet) => gas_giant_planet.mass,
42 };
43 trace_var!(result);
44 trace_exit!();
45 result
46 }
47
48 #[named]
50 pub fn get_radius(&self) -> f64 {
51 trace_enter!();
52 use Planet::*;
53 let result = match &self {
54 TerrestrialPlanet(terrestrial_planet) => terrestrial_planet.radius,
55 GasGiantPlanet(gas_giant_planet) => gas_giant_planet.radius,
56 };
57 trace_var!(result);
58 trace_exit!();
59 result
60 }
61
62 #[named]
64 pub fn get_orbital_period(&self) -> f64 {
65 trace_enter!();
66 use Planet::*;
67 let result = match &self {
68 TerrestrialPlanet(terrestrial_planet) => terrestrial_planet.orbital_period,
69 GasGiantPlanet(gas_giant_planet) => gas_giant_planet.orbital_period,
70 };
71 trace_var!(result);
72 trace_exit!();
73 result
74 }
75
76 #[named]
78 pub fn check_habitable(&self) -> Result<(), Error> {
79 trace_enter!();
80 use Planet::*;
81 match &self {
82 TerrestrialPlanet(terrestrial_planet) => terrestrial_planet.check_habitable()?,
83 _ => return Err(Error::UninhabitablePlanetType),
84 }
85 let result = Ok(());
86 trace_var!(result);
87 trace_exit!();
88 result
89 }
90
91 #[named]
93 pub fn is_habitable(&self) -> bool {
94 trace_enter!();
95 let result = match self.check_habitable() {
96 Ok(()) => true,
97 Err(_) => false,
98 };
99 trace_var!(result);
100 trace_exit!();
101 result
102 }
103}