pub struct Cell {
node_id: NodeId,
x: u8,
y: u8,
out1: Option<u8>,
out2: Option<u8>,
out3: Option<u8>,
in1: Option<u8>,
in2: Option<u8>,
in3: Option<u8>,
}
Expand description
This is a cell/tile of the hexagonal Matrix.
The Matrix stores it to keep track of the graphical representation of the hexagonal tilemap. Using Matrix::place you can place new cells.
use hexodsp::*;
let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3);
matrix.place(
2, 2,
Cell::empty(NodeId::Sin(0))
.input(Some(0), None, None)
.out(None, None, Some(0)));
matrix.sync().unwrap();
Fields
node_id: NodeId
x: u8
y: u8
out1: Option<u8>
Top-Right output
out2: Option<u8>
Bottom-Right output
out3: Option<u8>
Bottom output
in1: Option<u8>
Top input
in2: Option<u8>
Top-Left input
in3: Option<u8>
Bottom-Left input
Implementations
sourceimpl Cell
impl Cell
sourcepub fn empty(node_id: NodeId) -> Self
pub fn empty(node_id: NodeId) -> Self
This is the main contructor of a Cell. Empty means that there is no associated position of this cell and no inputs/outputs have been assigned. Use the methods Cell::input and Cell::out to assign inputs / outputs.
use hexodsp::*;
let some_cell =
Cell::empty(NodeId::Sin(0))
.input(None, Some(0), Some(0))
.out(None, Some(0), Some(0));
sourcepub fn empty_at(node_id: NodeId, x: u8, y: u8) -> Self
pub fn empty_at(node_id: NodeId, x: u8, y: u8) -> Self
This is an alternative constructor, in case you know the position of the cell before you got it from the Matrix.
sourcepub fn to_repr(&self) -> CellRepr
pub fn to_repr(&self) -> CellRepr
Returns a serializable representation of this Matrix Cell.
See also CellRepr.
use hexodsp::*;
let some_cell =
Cell::empty(NodeId::Sin(0))
.input(None, Some(0), Some(0))
.out(None, Some(0), Some(0));
let repr = some_cell.to_repr();
assert_eq!(
repr.serialize().to_string(),
"[\"sin\",0,0,0,[-1,\"freq\",\"freq\"],[-1,\"sig\",\"sig\"]]");
pub fn from_repr(repr: &CellRepr) -> Self
pub fn with_pos_of(&self, other: Cell) -> Self
pub fn is_empty(&self) -> bool
pub fn node_id(&self) -> NodeId
pub fn set_node_id(&mut self, new_id: NodeId)
pub fn set_node_id_keep_ios(&mut self, node_id: NodeId)
pub fn label<'a>(&self, buf: &'a mut [u8]) -> Option<&'a str>
pub fn pos(&self) -> (usize, usize)
pub fn offs_dir(&mut self, dir: CellDir) -> bool
pub fn has_dir_set(&self, dir: CellDir) -> bool
pub fn local_port_idx(&self, dir: CellDir) -> Option<u8>
pub fn clear_io_dir(&mut self, dir: CellDir)
pub fn set_io_dir(&mut self, dir: CellDir, idx: usize)
sourcepub fn set_input_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()>
pub fn set_input_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()>
This is a helper function to quickly set an input by name and direction.
use hexodsp::*;
let mut cell = Cell::empty(NodeId::Sin(0));
cell.set_input_by_name("freq", CellDir::T).unwrap();
sourcepub fn set_output_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()>
pub fn set_output_by_name(&mut self, name: &str, dir: CellDir) -> Result<(), ()>
This is a helper function to quickly set an output by name and direction.
use hexodsp::*;
let mut cell = Cell::empty(NodeId::Sin(0));
cell.set_output_by_name("sig", CellDir::B).unwrap();
pub fn input(self, i1: Option<u8>, i2: Option<u8>, i3: Option<u8>) -> Self
pub fn out(self, o1: Option<u8>, o2: Option<u8>, o3: Option<u8>) -> Self
sourcepub fn find_first_adjacent_free(
&self,
m: &Matrix,
dir: CellDir
) -> Option<(CellDir, Option<u8>)>
pub fn find_first_adjacent_free(
&self,
m: &Matrix,
dir: CellDir
) -> Option<(CellDir, Option<u8>)>
Finds the first free input or output (one without an adjacent cell). If any free input/output
has an assigned input, that edge is returned before any else.
With dir
you can specify input with CellDir::T
, output with CellDir::B
and any with CellDir::C
.
sourcepub fn find_all_adjacent_free(
&self,
m: &Matrix,
dir: CellDir
) -> Vec<(CellDir, (usize, usize))>
pub fn find_all_adjacent_free(
&self,
m: &Matrix,
dir: CellDir
) -> Vec<(CellDir, (usize, usize))>
Finds the all adjacent free places around the current cell.
With dir
you can specify input with CellDir::T
, output with CellDir::B
and any with CellDir::C
.
Trait Implementations
sourceimpl Ord for Cell
impl Ord for Cell
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialOrd<Cell> for Cell
impl PartialOrd<Cell> for Cell
sourcefn partial_cmp(&self, other: &Cell) -> Option<Ordering>
fn partial_cmp(&self, other: &Cell) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Cell
impl Eq for Cell
impl StructuralEq for Cell
impl StructuralPartialEq for Cell
Auto Trait Implementations
impl RefUnwindSafe for Cell
impl Send for Cell
impl Sync for Cell
impl Unpin for Cell
impl UnwindSafe for Cell
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.