/// Add a single particle to the DLA model.
Add a single particle to the DLA model.
Add a single particle to the DLA model .
fn add_particle(&mut self) {
        let mut coords = self.generate_random_coord();
        loop {
            let distance: f64;
            let nearest_index: NodeIndex;
            {
                let nearest = self
                    .index
                    .nearest(&coords, 1, &squared_euclidean)
                    .expect("Failed to find nearest particles");
                let results = *nearest.first().expect("Failed to get nearest particle");
                distance = results.0;
                nearest_index = *results.1;
            }
            if distance < self.attraction_distance {
                if self.attempt_to_join(&mut coords, nearest_index) {
                    trace!("Added particle POINT({} {})", coords[0], coords[1]);
                    return;
                }
            } else {
                // Random walk
                let v = &coords;
                let m = f64::max(self.min_move_distance, distance - self.attraction_distance);
                let u = Model::norm(&[self.rng.gen_range(0.0..1.0), self.rng.gen_range(0.0..1.0)]);
                coords = [v[0] + u[0] * m, v[1] + u[1] * m];
                if Model::length(&coords) > self.bounding_radius * 2.0 {
                    coords = self.generate_random_coord();
                }
            }
        }
    }
fn add_particle ( & mut self ) { let mut coords = self . generate_random_coord ( ) ; loop { let distance : f64 ; let nearest_index : NodeIndex ; { let nearest = self . index . nearest ( & coords , 1 , & squared_euclidean ) . expect ( " " ) ; let results = * nearest . first ( ) . expect ( " " ) ; distance = results . 0 ; nearest_index = * results . 1 ; } if distance < self . attraction_distance { if self . attempt_to_join ( & mut coords , nearest_index ) { trace ! ( " " coords [ 0 ] coords [ 1 ] ) ; return ; } } else { // Random walk let v = & coords ; let m = f64 :: max ( self . min_move_distance , distance - self . attraction_distance ) ; let u = Model :: norm ( & [ self . rng . gen_range ( 0.0 .. 1.0 ) , self . rng . gen_range ( 0.0 .. 1.0 ) ] ) ; coords = [ v [ 0 ] + u [ 0 ] * m , v [ 1 ] + u [ 1 ] * m ] ; if Model :: length ( & coords ) > self . bounding_radius * 2.0 { coords = self . generate_random_coord ( ) ; } } } }
Add a single particle to the DLA model.
Add a single particle to the DLA model .
&mut self