decluster/point.rs
1//! A 2D point representing a location in a results space.
2
3use rand::Rng;
4/// A 2D point representing a location in a results space.
5pub struct Point {
6 pub x: f64,
7 pub y: f64,
8 pub retain: bool,
9}
10
11impl Point {
12 /**
13 Generate a randomised vector of Points constrained by the current window size
14
15 # Arguments
16
17 * - `window_size` - The size of the current window. This sets the upper limit for the x and y values
18 * - `count` - the number of points in the vector
19 */
20 pub fn rnd_vec(window_size: [f64; 2], count: usize) -> Vec<Point> {
21 (0..count).map(|_| Point::rnd(window_size)).collect()
22 }
23
24 /**
25 Generate a single random Point constrained by the the current window size
26 # Arguments
27
28 * - `window_size` - The size of the current window. This sets the upper limit for the x and y values
29 */
30 pub fn rnd(window_size: [f64; 2]) -> Point {
31 let mut rng = rand::thread_rng();
32 Point {
33 retain: true,
34 x: rng.gen_range(0..window_size[0] as i32) as f64,
35 y: rng.gen_range(0..window_size[1] as i32) as f64,
36 }
37 }
38}