Add "randomly" generated initial nodes
This commit is contained in:
parent
df4fa8789c
commit
184d74a5aa
28
src/main.rs
28
src/main.rs
|
@ -45,6 +45,11 @@ async fn main() {
|
|||
let mut camera = dd.get_camera();
|
||||
set_camera(&camera);
|
||||
let mut iter = 0;
|
||||
|
||||
for _ in 0..160 {
|
||||
dd.add_random_point().unwrap();
|
||||
}
|
||||
|
||||
loop {
|
||||
if iter == 100 {
|
||||
iter = 0;
|
||||
|
@ -174,13 +179,15 @@ impl Default for DelaunayDemo {
|
|||
(edges.3, (Border, (&triangles[1]).into())),
|
||||
(edges.4, (Border, (&triangles[1]).into())),
|
||||
].into();
|
||||
let mut random = 0xACAB_1312;
|
||||
util::pcg64_iterstate(&mut random);
|
||||
let dd = DelaunayDemo {
|
||||
nodes,
|
||||
adjacency,
|
||||
triangles,
|
||||
height: HEIGHT,
|
||||
width: WIDTH,
|
||||
random_state: 1312_1312_1312,
|
||||
random_state: random,
|
||||
poisoned: false,
|
||||
spanning_tree: HashSet::with_capacity(100),
|
||||
spanning_tree_conn: HashMap::with_capacity(100),
|
||||
|
@ -602,16 +609,27 @@ impl DelaunayDemo {
|
|||
}
|
||||
|
||||
fn click(&mut self, pos: Vec2) {
|
||||
if let Err(msg) = self.add_point_random_dir(pos.as_f64()) {
|
||||
self.poisoned = true;
|
||||
eprintln!("POISONED: {}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_random_point(&mut self) -> Result<(), String> {
|
||||
let random = util::pcg64(&mut self.random_state);
|
||||
let x = (random & 0xffffffff) as f64 / (0xffffffffu32 as f64) * self.width;
|
||||
let y = (random >> 32) as f64 / (0xffffffffu32 as f64) * self.height;
|
||||
self.add_point_random_dir((x, y).into())
|
||||
}
|
||||
|
||||
fn add_point_random_dir(&mut self, pos: DVec2) -> Result<(), String> {
|
||||
let random = util::pcg64(&mut self.random_state);
|
||||
let angle = (random as f64) / (u64::MAX as f64) * (2.0 * std::f64::consts::PI);
|
||||
let direction = DVec2::new(
|
||||
f64::cos(angle),
|
||||
f64::sin(angle),
|
||||
);
|
||||
if let Err(msg) = self.add_point(Node(pos.as_f64(), direction * SPEED)) {
|
||||
self.poisoned = true;
|
||||
eprintln!("POISONED: {}", msg);
|
||||
}
|
||||
self.add_point(Node(pos, direction * SPEED))
|
||||
}
|
||||
|
||||
fn add_point(&mut self, node: Node) -> Result<(), String> {
|
||||
|
|
|
@ -6,7 +6,7 @@ pub fn pcg64(state: &mut u128) -> u64 {
|
|||
((x >> 58) as u64).rotate_right(count)
|
||||
}
|
||||
|
||||
fn pcg64_iterstate(state: &mut u128) {
|
||||
pub fn pcg64_iterstate(state: &mut u128) {
|
||||
const MULTIPLIER: u128 = 0xde92a69f6e2f9f25fd0d90f576075fbd;
|
||||
const INCREMENT: u128 = 621;
|
||||
*state = state.wrapping_mul(MULTIPLIER).wrapping_add(INCREMENT);
|
||||
|
|
Loading…
Reference in a new issue