fn calc_fitness(mut self, target: &Vec<(Point2, Rgb)>) -> Self {
    // kind of a weird way of finding the closest color... we'll see if it works
    let mut closest_color = 0;
    for (i, (pt, color)) in target.iter().enumerate() {
      if pt.distance(self.pos) < target[closest_color].0.distance(self.pos) {
        closest_color = i;
      }
    }

    let closest_color = target[closest_color].1;
    // closer to the target number is better
    let r_fitness = 1.0 - (self.genes[0] - closest_color.red).abs();
    let g_fitness = 1.0 - (self.genes[1] - closest_color.green).abs();
    let b_fitness = 1.0 - (self.genes[2] - closest_color.blue).abs();

    let fitness = (r_fitness + b_fitness + g_fitness) / 3.0;

    self.fitness = fitness;
    self
  }
// this uses an exponential fit that is MUCH MUCH MUCH faster at finding a "solution".
this uses an exponential fit that is MUCH MUCH MUCH faster at finding a "solution".
this uses an exponential fit that is MUCH MUCH MUCH faster at finding a " solution " .
fn calc_fitness(mut self, target: &Vec<(Point2, Rgb)>) -> Self {
    // kind of a weird way of finding the closest color... we'll see if it works
    let mut closest_color = 0;
    for (i, (pt, color)) in target.iter().enumerate() {
      if pt.distance(self.pos) < target[closest_color].0.distance(self.pos) {
        closest_color = i;
      }
    }
    let closest_color = target[closest_color].1;
    // closer to the target number is better
    let r_fitness = 1.0 - (self.genes[0] - closest_color.red).abs();
    let g_fitness = 1.0 - (self.genes[1] - closest_color.green).abs();
    let b_fitness = 1.0 - (self.genes[2] - closest_color.blue).abs();
    let fitness = (r_fitness + b_fitness + g_fitness) / 3.0;
    self.fitness = fitness;
    self
  }
fn calc_fitness ( mut self , target : & Vec < ( Point2 , Rgb ) > ) -> Self { // kind of a weird way of finding the closest color... we'll see if it works let mut closest_color = 0 ; for ( i , ( pt , color ) ) in target . iter ( ) . enumerate ( ) { if pt . distance ( self . pos ) < target [ closest_color ] . 0 . distance ( self . pos ) { closest_color = i ; } } let closest_color = target [ closest_color ] . 1 ; // closer to the target number is better let r_fitness = 1.0 - ( self . genes [ 0 ] - closest_color . red ) . abs ( ) ; let g_fitness = 1.0 - ( self . genes [ 1 ] - closest_color . green ) . abs ( ) ; let b_fitness = 1.0 - ( self . genes [ 2 ] - closest_color . blue ) . abs ( ) ; let fitness = ( r_fitness + b_fitness + g_fitness ) / 3.0 ; self . fitness = fitness ; self }
this uses an exponential fit that is MUCH MUCH MUCH faster at finding a "solution".
this uses an exponential fit that is MUCH MUCH MUCH faster at finding a " solution " .
mut self
target
&Vec<(Point2, Rgb)>