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
impl AlmostEq for DrawAction
Source§impl Clone for DrawAction
impl Clone for DrawAction
Source§fn clone(&self) -> DrawAction
fn clone(&self) -> DrawAction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DrawAction
impl Debug for DrawAction
Source§impl PartialEq for DrawAction
impl PartialEq for DrawAction
Source§impl TryFrom<JSONDrawAction> for DrawAction
impl TryFrom<JSONDrawAction> for DrawAction
Source§type Error = LSystemError
type Error = LSystemError
The type returned in the event of a conversion error.
impl Copy for DrawAction
impl StructuralPartialEq for DrawAction
Auto Trait Implementations§
impl Freeze for DrawAction
impl RefUnwindSafe for DrawAction
impl Send for DrawAction
impl Sync for DrawAction
impl Unpin for DrawAction
impl UnwindSafe for DrawAction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more