pub fn generate_from_rect(
    mass_range: std::ops::Range<f32>,
    allow_negative_mass: bool,
    win: &Rect,
    outside: bool,
  ) -> Self {
    let mass = if allow_negative_mass && chance() {
      random_range(-mass_range.start, -mass_range.end)
    } else {
      random_range(mass_range.start, mass_range.end)
    };

    let x_is_outside = outside && chance();
    let y_is_outside = outside && !x_is_outside;
    let x = if x_is_outside && chance() {
      random_range(win.left() * 1.05, win.left() * 1.4)
    } else if x_is_outside {
      random_range(win.right() * 1.05, win.right() * 1.4)
    } else {
      random_range(win.left(), win.right())
    };

    let y = if y_is_outside && chance() {
      random_range(win.bottom() * 1.05, win.bottom() * 1.4)
    } else if y_is_outside {
      random_range(win.top() * 1.05, win.top() * 1.4)
    } else {
      random_range(win.bottom(), win.top())
    };

    Self { mass, x, y }
  }
// Generates GravitationalBodies within a given mass range
// (and optionally negative masses)
// as well as using a given Rect for bounds.
// When `outside` is true, the GravitationalBodies will be placed
// outside of the Rect. When false, they will be inside the Rect.
Generates GravitationalBodies within a given mass range
(and optionally negative masses)
as well as using a given Rect for bounds.
When `outside` is true, the GravitationalBodies will be placed
outside of the Rect. When false, they will be inside the Rect.
Generates GravitationalBodies within a given mass range ( and optionally negative masses ) as well as using a given Rect for bounds . When ` outside ` is true the GravitationalBodies will be placed outside of the Rect . When false they will be inside the Rect .
pub fn generate_from_rect(
    mass_range: std::ops::Range<f32>,
    allow_negative_mass: bool,
    win: &Rect,
    outside: bool,
  ) -> Self {
    let mass = if allow_negative_mass && chance() {
      random_range(-mass_range.start, -mass_range.end)
    } else {
      random_range(mass_range.start, mass_range.end)
    };
    let x_is_outside = outside && chance();
    let y_is_outside = outside && !x_is_outside;
    let x = if x_is_outside && chance() {
      random_range(win.left() * 1.05, win.left() * 1.4)
    } else if x_is_outside {
      random_range(win.right() * 1.05, win.right() * 1.4)
    } else {
      random_range(win.left(), win.right())
    };
    let y = if y_is_outside && chance() {
      random_range(win.bottom() * 1.05, win.bottom() * 1.4)
    } else if y_is_outside {
      random_range(win.top() * 1.05, win.top() * 1.4)
    } else {
      random_range(win.bottom(), win.top())
    };
    Self { mass, x, y }
  }
pub fn generate_from_rect ( mass_range : std :: ops :: Range < f32 > , allow_negative_mass : bool , win : & Rect , outside : bool , ) -> Self { let mass = if allow_negative_mass && chance ( ) { random_range ( - mass_range . start , - mass_range . end ) } else { random_range ( mass_range . start , mass_range . end ) } ; let x_is_outside = outside && chance ( ) ; let y_is_outside = outside && ! x_is_outside ; let x = if x_is_outside && chance ( ) { random_range ( win . left ( ) * 1.05 , win . left ( ) * 1.4 ) } else if x_is_outside { random_range ( win . right ( ) * 1.05 , win . right ( ) * 1.4 ) } else { random_range ( win . left ( ) , win . right ( ) ) } ; let y = if y_is_outside && chance ( ) { random_range ( win . bottom ( ) * 1.05 , win . bottom ( ) * 1.4 ) } else if y_is_outside { random_range ( win . top ( ) * 1.05 , win . top ( ) * 1.4 ) } else { random_range ( win . bottom ( ) , win . top ( ) ) } ; Self { mass , x , y } }
Generates GravitationalBodies within a given mass range
(and optionally negative masses)
as well as using a given Rect for bounds.
Generates GravitationalBodies within a given mass range ( and optionally negative masses ) as well as using a given Rect for bounds .
mass_range
std::ops::Range<f32>
allow_negative_mass
bool
win
&Rect
outside
bool