DrawAction

Enum DrawAction 

Source
pub enum DrawAction {
    DrawForward(f64),
    MoveForward(f64),
    RotateCW(f64),
    Push(usize),
    Pop(usize),
    Null,
}
Expand description

Represents the various actions that can be assigned to characters in a string.

Variants§

§

DrawForward(f64)

Draws forward the given distance.

§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)]);

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))
];

let pth2: Path = pc_vec.into();

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

MoveForward(f64)

Moves forward the given distance.

§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::MoveForward(10.0),
        DrawAction::DrawForward(5.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)),
    PathCommand::MoveTo(Point::new(35.0, 5.0)),
    PathCommand::LineTo(Point::new(40.0, 5.0))
];

let pth2: Path = pc_vec.into();

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

RotateCW(f64)

Rotates the current angle the given amount clockwise.

§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::DrawForward(5.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::LineTo(Point::new(25.0, 10.0))
];

let pth2: Path = pc_vec.into();

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

Push(usize)

Pushes the current location and angle onto the specified stack.

§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::Push(0),
        DrawAction::RotateCW(PI/2.0),
        DrawAction::DrawForward(5.0),
        DrawAction::Pop(0),
        DrawAction::DrawForward(6.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)),
    // Location and direction saved to stack
    //
    // Note that in SVG, the origin is in the top-left corner, and
    // the positive y-axis points downward.
    PathCommand::LineTo(Point::new(25.0, 10.0)),
    // Back to previous location and direction
    PathCommand::MoveTo(Point::new(25.0, 5.0)),
    PathCommand::LineTo(Point::new(31.0, 5.0))
];

let pth2: Path = pc_vec.into();

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

Pop(usize)

Pops the top location/angle pair off the specified stack and adopts that as the current 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::Push(0),
        DrawAction::RotateCW(PI/2.0),
        DrawAction::DrawForward(5.0),
        DrawAction::Push(1),
        DrawAction::RotateCW(-PI/2.0),
        DrawAction::DrawForward(1.0),
        DrawAction::Pop(0),
        DrawAction::DrawForward(6.0),
        DrawAction::Pop(1),
        DrawAction::DrawForward(1.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)),
    // Location and direction saved to stack 0
    //
    // Note that in SVG, the origin is in the top-left corner, and
    // the positive y-axis points downward.
    PathCommand::LineTo(Point::new(25.0, 10.0)),
    // Location and direction saved to stack 1
    PathCommand::LineTo(Point::new(26.0, 10.0)),
    // Back to previous location and direction from stack 0
    PathCommand::MoveTo(Point::new(25.0, 5.0)),
    PathCommand::LineTo(Point::new(31.0, 5.0)),
    // Back to previous location and direction from stack 1
    PathCommand::MoveTo(Point::new(25.0, 10.0)),
    PathCommand::LineTo(Point::new(25.0, 11.0))
];

let pth2: Path = pc_vec.into();

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

Null

Does nothing.

Trait Implementations§

Source§

impl AlmostEq for DrawAction

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 DrawAction

Source§

fn clone(&self) -> DrawAction

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 DrawAction

Source§

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

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

impl PartialEq for DrawAction

Source§

fn eq(&self, other: &DrawAction) -> 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<JSONDrawAction> for DrawAction

Source§

type Error = LSystemError

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

fn try_from(j: JSONDrawAction) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for DrawAction

Source§

impl StructuralPartialEq for DrawAction

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.