Struct Cell

Source
pub struct Cell { /* private fields */ }
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();

Implementations§

Source§

impl Cell

Source

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));
Source

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.

Source

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\"]]");
Source

pub fn from_repr(repr: &CellRepr) -> Self

Source

pub fn with_pos_of(&self, other: Cell) -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn node_id(&self) -> NodeId

Source

pub fn set_node_id(&mut self, new_id: NodeId)

Source

pub fn set_node_id_keep_ios(&mut self, node_id: NodeId)

Source

pub fn label<'a>(&self, buf: &'a mut [u8]) -> Option<&'a str>

Source

pub fn pos(&self) -> (usize, usize)

Source

pub fn offs_dir(&mut self, dir: CellDir) -> bool

Source

pub fn has_dir_set(&self, dir: CellDir) -> bool

Source

pub fn local_port_idx(&self, dir: CellDir) -> Option<u8>

Source

pub fn clear_io_dir(&mut self, dir: CellDir)

Source

pub fn set_io_dir(&mut self, dir: CellDir, idx: usize)

Source

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();
Source

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();
Source

pub fn input(self, i1: Option<u8>, i2: Option<u8>, i3: Option<u8>) -> Self

Source

pub fn out(self, o1: Option<u8>, o2: Option<u8>, o3: Option<u8>) -> Self

Source

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.

Source

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.

Source

pub fn find_unconnected_ports(&self, m: &Matrix, dir: CellDir) -> Vec<CellDir>

Finds all dangling ports in the specified direction. With dir you can specify input with CellDir::T, output with CellDir::B and any with CellDir::C.

Source

pub fn is_port_dir_connected( &self, m: &Matrix, dir: CellDir, ) -> Option<(usize, usize)>

If the port is connected, it will return the position of the other cell.

Trait Implementations§

Source§

impl Clone for Cell

Source§

fn clone(&self) -> Cell

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Cell

Source§

fn cmp(&self, other: &Cell) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Cell

Source§

fn eq(&self, other: &Cell) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Cell

Source§

fn partial_cmp(&self, other: &Cell) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Cell

Source§

impl Eq for Cell

Source§

impl StructuralPartialEq for Cell

Auto Trait Implementations§

§

impl Freeze for Cell

§

impl RefUnwindSafe for Cell

§

impl Send for Cell

§

impl Sync for Cell

§

impl Unpin for Cell

§

impl UnwindSafe for Cell

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.