[][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, variable};

let mut builder = LSystemBuilder::new();

// Set up our two tokens
let a = variable!(builder, "A");
let b = variable!(builder, "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, variable};

let mut builder = LSystemBuilder::new();

//  Create a simple L-System with one variable `A` and production rule `A -> AA`
let a = variable!(builder, "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]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for LSystem[src]

Auto Trait Implementations

impl Sync for LSystem

impl Send for LSystem

impl Unpin for LSystem

impl RefUnwindSafe for LSystem

impl UnwindSafe for LSystem

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

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<T> ConvUtil for T

fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 

Approximate the subject to a given type with the default scheme.

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 

Approximate the subject to a given type with a specific scheme.

fn into_as<Dst>(self) -> Dst where
    Self: Into<Dst>, 

Convert the subject to a given type.

fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: TryInto<Dst>, 

Attempt to convert the subject to a given type.

fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ValueInto<Dst>, 

Attempt a value conversion of the subject to a given type.

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, Dst> ConvAsUtil<Dst> for T

fn approx(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 

Approximate the subject with the default scheme.

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 

Approximate the subject with a specific scheme.

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.