use crate::types::node::NodeId;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SimNode {
pub x: f32,
pub y: f32,
pub vx: f32,
pub vy: f32,
pub fx: Option<f32>,
pub fy: Option<f32>,
pub radius: f32,
pub strength: Option<f32>,
#[cfg_attr(feature = "serde", serde(default))]
pub id: Option<NodeId>,
}
impl SimNode {
pub fn new(x: f32, y: f32) -> Self {
Self {
x,
y,
vx: 0.0,
vy: 0.0,
fx: None,
fy: None,
radius: 1.0,
strength: None,
id: None,
}
}
pub fn with_radius(mut self, radius: f32) -> Self {
self.radius = radius;
self
}
pub fn with_id(mut self, id: NodeId) -> Self {
self.id = Some(id);
self
}
pub fn with_strength(mut self, strength: f32) -> Self {
self.strength = Some(strength);
self
}
}
impl Default for SimNode {
fn default() -> Self {
Self::new(0.0, 0.0)
}
}