[][src]Struct dcc_lsystem::system::LSystem

pub struct LSystem { /* fields omitted */ }

An L-system.

Basic Usage

The suggested method for constructing an LSystem is to use a LSystemBuilder, as shown in our implementation of Lindenmayer's system below.

use dcc_lsystem::LSystemBuilder;

let mut builder = LSystemBuilder::new();

// Set up our two tokens
let a = builder.token("A");
let b = builder.token("B");

// Set the axiom
builder.axiom(vec![a]);

// Set the transformation rules
builder.transformation_rule(a, vec![a, b]);
builder.transformation_rule(b, vec![a]);

// Build our L-system
let mut system = builder.finish();

Once the LSystem has been built, you can use the step() and step_by() methods to iterate the system.

use dcc_lsystem::LSystemBuilder;

let mut builder = LSystemBuilder::new();

/* <---- snip ----> */

let mut system = builder.finish();

// The initial state of our system
assert_eq!(system.render(), "A");

system.step();

assert_eq!(system.render(), "AB");

system.step();

assert_eq!(system.render(), "ABA");

system.step_by(5);

// The state after 7 iterations
assert_eq!(system.render(), "ABAABABAABAABABAABABAABAABABAABAAB");

Methods

impl LSystem[src]

pub fn new(
    arena: Arena<Token>,
    axiom: Vec<ArenaId>,
    rules_map: HashMap<ArenaId, Vec<ArenaId>>
) -> Self
[src]

Create a new instance of LSystem. In general you should avoid using this and use an LSystemBuilder instead.

pub fn reset(&mut self)[src]

Reset the system to its initial state.

Example

use dcc_lsystem::LSystemBuilder;

let mut builder = LSystemBuilder::new();

//  Create a simple L-System with one variable `A` and production rule `A -> AA`
let a = builder.token("A");
builder.axiom(vec![a]);
builder.transformation_rule(a, vec![a, a]);
let mut system = builder.finish();

// Do some work with the system
system.step_by(3);
assert_eq!(system.render(), "AAAAAAAA");

// Reset the system back to its axiom
system.reset();
assert_eq!(system.render(), "A");

pub fn step(&mut self)[src]

Iterate the system a single step.

pub fn step_by(&mut self, n: usize)[src]

Iterate the system by n steps.

pub fn steps(&self) -> usize[src]

Returns the number of iterations the system has undergone so far

pub fn render(&self) -> String[src]

Returns the current state of the system as a String.

pub fn get_state(&self) -> &[ArenaId][src]

Returns the current state of the system.

Trait Implementations

impl Clone for LSystem[src]

impl Debug for LSystem[src]

Auto Trait Implementations

impl Send for LSystem

impl Sync for LSystem

impl Unpin for LSystem

impl UnwindSafe for LSystem

impl RefUnwindSafe for LSystem

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T[src]

impl<Src, Dst> ValueInto<Dst> for Src where
    Dst: ValueFrom<Src>, 

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
    Scheme: ApproxScheme, 

type Err = NoError

The error type produced by a failed conversion.

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
    Dst: ApproxFrom<Src, Scheme>,
    Scheme: ApproxScheme, 

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.

impl<Src> ValueFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<T> ConvUtil for T

impl<T, Dst> ConvAsUtil<Dst> for T

impl<Src> TryFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<Src, Dst> TryInto<Dst> for Src where
    Dst: TryFrom<Src>, 

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Clone for T where
    T: Clone
[src]