starfall/astronomy/distant_binary_star/
mod.rs

1use crate::astronomy::planetary_system::PlanetarySystem;
2
3pub mod constants;
4pub mod constraints;
5pub mod error;
6use error::Error;
7
8/// A `DistantBinaryStar` is actually a pair of `PlanetarySystem` objects.
9///
10/// This may seem counterintuitive, but each member of a distant binary star
11/// can itself be a binary star with its own orbiting planets.  A distant
12/// binary star is thus very different in critical ways from a close binary
13/// star, and we have to treat them as completely distinct although they
14/// sound and might seem very similar.
15///
16/// And let's not get started on how disappointing it is to call something a
17/// planetary system when it may not actually have any planets.  But I don't
18/// think we have a better word or phrase for the idea.
19#[derive(Clone, Debug, PartialEq)]
20pub struct DistantBinaryStar {
21  /// The primary planetary system is the one with greater mass.
22  pub primary: PlanetarySystem,
23  /// The secondary planetary system has less mass.
24  pub secondary: PlanetarySystem,
25}
26
27impl DistantBinaryStar {
28  /// Indicate whether this star is capable of supporting conventional life.
29  #[named]
30  pub fn check_habitable(&self) -> Result<(), Error> {
31    trace_enter!();
32    self.primary.check_habitable()?;
33    self.secondary.check_habitable()?;
34    let result = Ok(());
35    trace_var!(result);
36    trace_exit!();
37    result
38  }
39
40  /// Indicate whether this star is capable of supporting conventional life.
41  #[named]
42  pub fn is_habitable(&self) -> bool {
43    trace_enter!();
44    let result = match self.check_habitable() {
45      Ok(()) => true,
46      Err(_) => false,
47    };
48    trace_var!(result);
49    trace_exit!();
50    result
51  }
52
53  /// Retrieve or calculate the total mass of the stars.
54  ///
55  /// Calculated in Msol.
56  #[named]
57  pub fn get_stellar_mass(&self) -> f64 {
58    trace_enter!();
59    let result = self.primary.get_stellar_mass() + self.secondary.get_stellar_mass();
60    trace_var!(result);
61    trace_exit!();
62    result
63  }
64
65  /// Retrieve or calculate the total number of stars in the system.
66  #[named]
67  pub fn get_stellar_count(&self) -> u8 {
68    trace_enter!();
69    let result = self.primary.get_stellar_count() + self.secondary.get_stellar_count();
70    trace_var!(result);
71    trace_exit!();
72    result
73  }
74}