ActionString

Struct ActionString 

Source
pub struct ActionString(pub Vec<DrawAction>);
Expand description

Represents a series of DrawActions.

Tuple Fields§

§0: Vec<DrawAction>

Implementations§

Source§

impl ActionString

Source

pub fn make_path( &self, start: Point, start_angle: f64, ) -> Result<Path, LSystemError>

Creates a Path from the action string, starting at a given location and angle.

§Example
use std::f64::consts::PI;

use l_system_fractals::rules::{DrawAction, ActionString};
use l_system_fractals::paths::{Path, PathCommand, Point};
use l_system_fractals::num_validity::AlmostEq;

let action_string = ActionString(
    vec![
        DrawAction::DrawForward(20.0),
        DrawAction::RotateCW(PI/2.0),
        DrawAction::MoveForward(10.0),
        DrawAction::DrawForward(10.0)
    ]
);

let pth = action_string.make_path(Point::new(5.0, 5.0), 0.0).unwrap();

let pc_vec: Vec<PathCommand> = vec![
    PathCommand::MoveTo(Point::new(5.0, 5.0)),
    PathCommand::LineTo(Point::new(25.0, 5.0)),
    // Note that in SVG, the origin is in the top-left corner, and
    // the positive y-axis points downward.
    PathCommand::MoveTo(Point::new(25.0, 15.0)),
    PathCommand::LineTo(Point::new(25.0, 25.0))
];

let pth2: Path = pc_vec.into();

assert!(pth.almost_eq(&pth2, 0.001));
Source

pub fn make_default_path(&self) -> Result<Path, LSystemError>

Creates a path with the default starting point and angle (Point::new(0.0, 0.0) and 0.0, respectively).

The TryFrom<ActionString> trait for Path is identical.

§Example
use std::f64::consts::PI;

use l_system_fractals::rules::{DrawAction, ActionString};
use l_system_fractals::paths::{Path, Point};
use l_system_fractals::num_validity::AlmostEq;

let action_string = ActionString(
    vec![
        DrawAction::DrawForward(20.0),
        DrawAction::RotateCW(PI/2.0),
        DrawAction::MoveForward(10.0),
        DrawAction::DrawForward(10.0)
    ]
);

let pth1 = action_string.make_default_path().unwrap();
let pth2 = action_string.make_path(Point::new(0.0, 0.0), 0.0).unwrap();
let pth3: Path = action_string.try_into().unwrap();

assert!(pth1.almost_eq(&pth2, 0.001));
assert!(pth2.almost_eq(&pth3, 0.001));

Trait Implementations§

Source§

impl AlmostEq for ActionString

Source§

fn almost_eq(&self, other: &Self, epsilon: f64) -> bool

Returns true if the distance between objects is less than epsilon.
Source§

impl Clone for ActionString

Source§

fn clone(&self) -> ActionString

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 ActionString

Source§

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

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

impl From<Vec<DrawAction>> for ActionString

Source§

fn from(v: Vec<DrawAction>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ActionString

Source§

fn eq(&self, other: &ActionString) -> 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 TryFrom<ActionString> for Path

Source§

type Error = LSystemError

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

fn try_from(s: ActionString) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for ActionString

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.