44 lines
917 B
Rust
44 lines
917 B
Rust
use crate::{GraphError, GraphResult};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Node {
|
|
pub kind: usize,
|
|
pub pos: glam::Vec2,
|
|
pub inputs: Vec<Option<SlotIndex>>,
|
|
}
|
|
|
|
impl Node {
|
|
pub fn unwrap_inputs(&self) -> GraphResult<Vec<SlotIndex>> {
|
|
let mut inputs = Vec::with_capacity(self.inputs.len());
|
|
|
|
for input in self.inputs.iter() {
|
|
if let Some(input) = input {
|
|
inputs.push(*input);
|
|
} else {
|
|
return Err(GraphError::MissingEdge);
|
|
}
|
|
}
|
|
|
|
Ok(inputs)
|
|
}
|
|
|
|
pub fn at(self, pos: glam::Vec2) -> Self {
|
|
Self {
|
|
pos,
|
|
..self
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Debug, Clone, Hash, PartialEq, Eq)]
|
|
pub struct SlotIndex {
|
|
pub node: usize,
|
|
pub slot: usize,
|
|
}
|
|
|
|
#[derive(Copy, Debug, Clone, Hash, PartialEq, Eq)]
|
|
pub struct Edge {
|
|
pub input: SlotIndex,
|
|
pub output: SlotIndex,
|
|
}
|