pub struct InteractionMatrix { /* private fields */ }Expand description
Interaction matrix storing force relationships between particle types.
Each cell [self_type][other_type] contains:
strength: positive = attract, negative = repel, zero = ignoreradius: interaction range
Implementations§
Source§impl InteractionMatrix
impl InteractionMatrix
Sourcepub fn new(num_types: usize) -> Self
pub fn new(num_types: usize) -> Self
Create a new interaction matrix for num_types particle types.
All interactions start as ignore (strength=0, radius=0).
Sourcepub fn set<T: Into<u32>, U: Into<u32>>(
&mut self,
self_type: T,
other_type: U,
strength: f32,
radius: f32,
)
pub fn set<T: Into<u32>, U: Into<u32>>( &mut self, self_type: T, other_type: U, strength: f32, radius: f32, )
Set the interaction when self_type encounters other_type.
strength > 0: attraction (pulls toward)strength < 0: repulsion (pushes away)strength = 0: ignoreradius: how far the interaction reaches
§Example
m.set(Predator, Prey, 2.0, 0.5); // Predator attracted to Prey
m.set(Prey, Predator, -3.0, 0.4); // Prey repelled by PredatorSourcepub fn attract<T: Into<u32>, U: Into<u32>>(
&mut self,
self_type: T,
other_type: U,
strength: f32,
radius: f32,
)
pub fn attract<T: Into<u32>, U: Into<u32>>( &mut self, self_type: T, other_type: U, strength: f32, radius: f32, )
Convenience: set attraction between types.
Equivalent to set(self_type, other_type, strength.abs(), radius).
Sourcepub fn repel<T: Into<u32>, U: Into<u32>>(
&mut self,
self_type: T,
other_type: U,
strength: f32,
radius: f32,
)
pub fn repel<T: Into<u32>, U: Into<u32>>( &mut self, self_type: T, other_type: U, strength: f32, radius: f32, )
Convenience: set repulsion between types.
Equivalent to set(self_type, other_type, -strength.abs(), radius).
Sourcepub fn set_symmetric<T: Into<u32> + Copy, U: Into<u32> + Copy>(
&mut self,
type_a: T,
type_b: U,
strength: f32,
radius: f32,
)
pub fn set_symmetric<T: Into<u32> + Copy, U: Into<u32> + Copy>( &mut self, type_a: T, type_b: U, strength: f32, radius: f32, )
Set symmetric interaction (both types affect each other the same way).
Useful for mutual attraction/repulsion.
Sourcepub fn max_radius(&self) -> f32
pub fn max_radius(&self) -> f32
Get the maximum interaction radius.
Sourcepub fn to_wgsl_init(&self) -> String
pub fn to_wgsl_init(&self) -> String
Generate WGSL code for initializing interaction variables.
This goes before the neighbor loop.
Sourcepub fn to_wgsl_neighbor(&self) -> String
pub fn to_wgsl_neighbor(&self) -> String
Generate WGSL code for the neighbor loop body.
This runs inside the neighbor loop with access to:
other- the neighbor particleneighbor_dist- distance to neighborneighbor_dir- direction toward self from neighbor
Sourcepub fn to_wgsl_post(&self) -> String
pub fn to_wgsl_post(&self) -> String
Generate WGSL code for applying accumulated interaction forces.
This goes after the neighbor loop.
Trait Implementations§
Source§impl Clone for InteractionMatrix
impl Clone for InteractionMatrix
Source§fn clone(&self) -> InteractionMatrix
fn clone(&self) -> InteractionMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for InteractionMatrix
impl RefUnwindSafe for InteractionMatrix
impl Send for InteractionMatrix
impl Sync for InteractionMatrix
impl Unpin for InteractionMatrix
impl UnwindSafe for InteractionMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.