Radial random through macro

This commit is contained in:
rendo 2026-04-06 10:39:33 +05:00
commit b6098ce825
2 changed files with 15 additions and 3 deletions

View file

@ -9,6 +9,19 @@ pub use gene_source::GeneSource;
pub use gene_place::GenePlace;
use godot::builtin::Vector2;
#[macro_export]
macro_rules! radial_child_position {
($radius:literal) => {
|_|{
use rand::{RngExt};
use godot::builtin::Vector2;
let mut rng = rand::rng();
Vector2::from_angle(rng.random_range(0.0..=1.0)*3.1415*2.) * rng.random_range(($radius/2.)..=$radius)
}
};
}
#[derive(PartialEq,Eq,Clone)]
pub struct Gene {
pub plant_source: GeneSource,
@ -58,10 +71,9 @@ impl Gene {
}
impl Display for Gene {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"({}) {}",self.plant_source,self.place)
}
}

View file

@ -33,6 +33,6 @@ fn get_place_head(place: GenePlace) -> Vector2 {
match place {
GenePlace::Mouth => Vector2::new(1.,4.),
GenePlace::Eyes => Vector2::new(1.,-2.),
_ =>return Vector2::ZERO
_ => crate::radial_child_position!(10.)(place.clone())
}
}