fn poisson_sample_points(&mut self, count: i32) -> Vec<Position> {
        let (w, h) = (self.map.width, self.map.height);

        let mut result = Vec::new();
        let mut rng = RandomNumberGenerator::new();
        let mut candidates = Vec::new();
        for _ in 0..count * 3 {
            candidates.push(Position { x: rng.range(0, w), y: rng.range(0, h) })
        }

        let first = candidates.pop().unwrap();

        let mut distances = Vec::new();
        for candidate in &candidates {
            distances.push(first.square_distance(&candidate));
        }

        result.push(first);

        for _ in 0..count {
            let pick = (0..distances.len())
                .min_by_key(|i| &distances[*i as usize])
                .unwrap();

            let new = candidates.remove(pick);
            distances.remove(pick);

            for (i, candidate) in candidates.iter().enumerate() {
                let distance = new.square_distance(candidate);
                if distance < distances[i] {
                    distances[i] = distance;
                }
            }

            result.push(new);
        }

        result
    }
/// Use something approaching poisson sampling to find centre points
/// to grow rooms
Use something approaching poisson sampling to find centre points
to grow rooms
Use something approaching poisson sampling to find centre points to grow rooms
fn poisson_sample_points(&mut self, count: i32) -> Vec<Position> {
        let (w, h) = (self.map.width, self.map.height);
        let mut result = Vec::new();
        let mut rng = RandomNumberGenerator::new();
        let mut candidates = Vec::new();
        for _ in 0..count * 3 {
            candidates.push(Position { x: rng.range(0, w), y: rng.range(0, h) })
        }
        let first = candidates.pop().unwrap();
        let mut distances = Vec::new();
        for candidate in &candidates {
            distances.push(first.square_distance(&candidate));
        }
        result.push(first);
        for _ in 0..count {
            let pick = (0..distances.len())
                .min_by_key(|i| &distances[*i as usize])
                .unwrap();
            let new = candidates.remove(pick);
            distances.remove(pick);
            for (i, candidate) in candidates.iter().enumerate() {
                let distance = new.square_distance(candidate);
                if distance < distances[i] {
                    distances[i] = distance;
                }
            }
            result.push(new);
        }
        result
    }
fn poisson_sample_points ( & mut self , count : i32 ) -> Vec < Position > { let ( w , h ) = ( self . map . width , self . map . height ) ; let mut result = Vec :: new ( ) ; let mut rng = RandomNumberGenerator :: new ( ) ; let mut candidates = Vec :: new ( ) ; for _ in 0 .. count * 3 { candidates . push ( Position { x : rng . range ( 0 , w ) , y : rng . range ( 0 , h ) } ) } let first = candidates . pop ( ) . unwrap ( ) ; let mut distances = Vec :: new ( ) ; for candidate in & candidates { distances . push ( first . square_distance ( & candidate ) ) ; } result . push ( first ) ; for _ in 0 .. count { let pick = ( 0 .. distances . len ( ) ) . min_by_key ( | i | & distances [ * i as usize ] ) . unwrap ( ) ; let new = candidates . remove ( pick ) ; distances . remove ( pick ) ; for ( i , candidate ) in candidates . iter ( ) . enumerate ( ) { let distance = new . square_distance ( candidate ) ; if distance < distances [ i ] { distances [ i ] = distance ; } } result . push ( new ) ; } result }
Use something approaching poisson sampling to find centre points
to grow rooms
Use something approaching poisson sampling to find centre points to grow rooms
&mut self
count
i32