[−][src]Struct dcc_lsystem::system::LSystem
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]
arena: Arena<Token>,
axiom: Vec<ArenaId>,
rules_map: HashMap<ArenaId, Vec<ArenaId>>
) -> Self
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
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]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> SetParameter for T
[src]
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
Dst: ValueFrom<Src>,
type Err = <Dst as ValueFrom<Src>>::Err
The error type produced by a failed conversion.
fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
Scheme: ApproxScheme,
type Err = NoError
The error type produced by a failed conversion.
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
impl<Src> ValueFrom<Src> for Src
type Err = NoError
The error type produced by a failed conversion.
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
impl<T> ConvUtil for T
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
fn into_as<Dst>(self) -> Dst where
Self: Into<Dst>,
Self: Into<Dst>,
fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: TryInto<Dst>,
Self: TryInto<Dst>,
fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ValueInto<Dst>,
Self: ValueInto<Dst>,
impl<T, Dst> ConvAsUtil<Dst> for T
fn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
impl<Src> TryFrom<Src> for Src
type Err = NoError
The error type produced by a failed conversion.
fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>
impl<Src, Dst> TryInto<Dst> for Src where
Dst: TryFrom<Src>,
Dst: TryFrom<Src>,
type Err = <Dst as TryFrom<Src>>::Err
The error type produced by a failed conversion.
fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Clone for T where
T: Clone,
[src]
T: Clone,