Struct Stickfigure

Source
pub struct Stickfigure {
    pub version: i32,
    pub build: i32,
    pub scale: f32,
    pub color: Color,
    pub nodes: Graph<Rc<RefCell<Node>>, ()>,
    pub polyfills: Vec<Rc<RefCell<Polyfill>>>,
    /* private fields */
}

Fields§

§version: i32§build: i32§scale: f32§color: Color§nodes: Graph<Rc<RefCell<Node>>, ()>§polyfills: Vec<Rc<RefCell<Polyfill>>>

Implementations§

Source§

impl Stickfigure

Public Methods

Source

pub fn new() -> Self

Creates a new, empty Stickfigure, set to latest version and build.

Source

pub fn from_version_and_build( version: i32, build: i32, ) -> Result<Self, LibraryError>

Creates a new, empty Stickfigure, set to the specified version and build.

Source

pub fn to_serializable(&self) -> SerializableStickfigure

Source

pub fn set_is_node_limit_enabled( &mut self, is_enabled: bool, agree: IWillNotAbuseUnlimitedNodes, )

Source

pub fn from_bytes(reader: &mut impl Read) -> Result<Self, LibraryError>

Creates a new Stickfigure from raw bytes of a .nodes file.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, LibraryError>

Get raw bytes of a .nodes file from an existing Stickfigure.

Source

pub fn add_node( &mut self, node: Node, parent_draw_index: DrawOrderIndex, ) -> Result<DrawOrderIndex, StickfigureError>

Adds a new node to the stickfigure.

The node is given a unique DrawOrderIndex.

§Parameters
  • node - The Node to add to the Stickfigure.
  • parent_draw_index - The DrawOrderIndex of the node to add this node as a child of
§Returns

Result of DrawOrderIndex of the newly added node.

Source

pub fn add_node_at_index( &mut self, node: Node, parent_draw_index: DrawOrderIndex, draw_index: DrawOrderIndex, ) -> Result<DrawOrderIndex, StickfigureError>

Source

pub fn change_draw_index( &mut self, draw_index: DrawOrderIndex, new_draw_index: DrawOrderIndex, ) -> Result<(), StickfigureError>

Source

pub fn get_node(&self, draw_index: DrawOrderIndex) -> Option<&Rc<RefCell<Node>>>

Gets a reference to a node.

§Parameters
  • draw_index - The DrawOrderIndex of the node.
§Returns

An Option containing a reference to the node if it exists.

Source

pub fn get_parent(&self, draw_index: DrawOrderIndex) -> Option<DrawOrderIndex>

Get the DrawOrderIndex of the direct parent of the Node at the specified DrawOrderIndex.

Source

pub fn get_children( &self, parent_draw_index: DrawOrderIndex, ) -> Vec<DrawOrderIndex>

Get a Vec<DrawOrderIndex> containing all DrawOrderIndexs of Nodes that are direct children of the Node at the specified DrawOrderIndex.

Source

pub fn get_children_recursive( &self, draw_index: DrawOrderIndex, ) -> Vec<DrawOrderIndex>

Source

pub fn get_parents_recursive( &self, draw_index: DrawOrderIndex, ) -> Vec<DrawOrderIndex>

Source

pub fn get_all_node_indices(&self) -> Vec<DrawOrderIndex>

Source

pub fn get_siblings(&self, draw_index: DrawOrderIndex) -> Vec<DrawOrderIndex>

Gets the sibling nodes of a given node.

Sibling nodes are nodes that share the same parent.

§Parameters
  • draw_index - The DrawOrderIndex of the node whose siblings are to be found.
§Returns

A Vec of DrawOrderIndex representing the siblings of the given node.

Source

pub fn get_nodes_with_property<F>(&self, predicate: F) -> Vec<DrawOrderIndex>
where F: FnMut(&Rc<RefCell<Node>>) -> bool,

Source

pub fn update_nodes_with_property<F>(&mut self, predicate: F, updater: F)
where F: FnMut(&Rc<RefCell<Node>>),

Source

pub fn remove_node( &mut self, draw_index: DrawOrderIndex, ) -> Result<(), StickfigureError>

Source

pub fn add_polyfill(&mut self, polyfill: Polyfill) -> DrawOrderIndex

Source

pub fn get_polyfill( &self, draw_index: DrawOrderIndex, ) -> Option<Rc<RefCell<Polyfill>>>

Source

pub fn remove_polyfill( &mut self, anchor_draw_order: DrawOrderIndex, ) -> Result<(), StickfigureError>

Source

pub fn all_draw_indices_exist(&self, indices: &[DrawOrderIndex]) -> bool

Returns true if all provided DrawOrderIndices exist in the node_index_map.

Source

pub fn draw_index_exists(&self, draw_index: DrawOrderIndex) -> bool

Returns true if provided DrawOrderIndex exists in the node_index_map.

Source

pub fn draw_index_is_polyfill_anchor(&self, draw_index: DrawOrderIndex) -> bool

Source

pub fn missing_draw_indices( &self, indices: &[DrawOrderIndex], ) -> Vec<DrawOrderIndex>

Returns a Vec of DrawOrderIndices that do not exist in node_index_map.

Trait Implementations§

Source§

impl Clone for Stickfigure

Source§

fn clone(&self) -> Stickfigure

Returns a copy 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 Stickfigure

Source§

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

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

impl Default for Stickfigure

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<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.