pub struct ActionString(pub Vec<DrawAction>);Expand description
Represents a series of DrawActions.
Tuple Fields§
§0: Vec<DrawAction>Implementations§
Source§impl ActionString
impl ActionString
Sourcepub fn make_path(
&self,
start: Point,
start_angle: f64,
) -> Result<Path, LSystemError>
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));Sourcepub fn make_default_path(&self) -> Result<Path, LSystemError>
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
impl AlmostEq for ActionString
Source§impl Clone for ActionString
impl Clone for ActionString
Source§fn clone(&self) -> ActionString
fn clone(&self) -> ActionString
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 ActionString
impl Debug for ActionString
Source§impl From<Vec<DrawAction>> for ActionString
impl From<Vec<DrawAction>> for ActionString
Source§fn from(v: Vec<DrawAction>) -> Self
fn from(v: Vec<DrawAction>) -> Self
Converts to this type from the input type.
Source§impl PartialEq for ActionString
impl PartialEq for ActionString
Source§impl TryFrom<ActionString> for Path
impl TryFrom<ActionString> for Path
Source§type Error = LSystemError
type Error = LSystemError
The type returned in the event of a conversion error.
impl StructuralPartialEq for ActionString
Auto Trait Implementations§
impl Freeze for ActionString
impl RefUnwindSafe for ActionString
impl Send for ActionString
impl Sync for ActionString
impl Unpin for ActionString
impl UnwindSafe for ActionString
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