pub struct RuleAssignment(pub HashMap<char, DrawAction>);Expand description
Represents an assignment of chars to DrawActions.
Tuple Fields§
§0: HashMap<char, DrawAction>Implementations§
Source§impl RuleAssignment
impl RuleAssignment
Sourcepub fn translate(&self, s: String) -> ActionString
pub fn translate(&self, s: String) -> ActionString
Applies the assignment to a string to produce an action string.
§Example
use std::f64::consts::PI;
use std::collections::HashMap;
use l_system_fractals::num_validity::AlmostEq;
use l_system_fractals::rules::{DrawAction, ActionString, RuleAssignment};
let assignment = RuleAssignment(
HashMap::from([
('A', DrawAction::DrawForward(1.0)),
('B', DrawAction::MoveForward(1.0))
])
);
let action1 = assignment.translate("ABA".to_string());
let action2 = ActionString(
vec![
DrawAction::DrawForward(1.0),
DrawAction::MoveForward(1.0),
DrawAction::DrawForward(1.0)
]
);
assert!(action1.almost_eq(&action2, 0.001));Sourcepub fn make_path(
&self,
s: String,
start: Point,
start_angle: f64,
) -> Result<Path, LSystemError>
pub fn make_path( &self, s: String, start: Point, start_angle: f64, ) -> Result<Path, LSystemError>
Translates the string using the assignment and then makes a path with the given starting point and initial angle.
§Example
use std::f64::consts::PI;
use std::collections::HashMap;
use l_system_fractals::rules::{DrawAction, ActionString, RuleAssignment};
use l_system_fractals::paths::{Path, Point};
use l_system_fractals::num_validity::AlmostEq;
let assignment = RuleAssignment(
HashMap::from([
('A', DrawAction::DrawForward(1.0)),
('B', DrawAction::MoveForward(1.0))
])
);
let pth1 = assignment
.make_path("ABA".to_string(), Point::new(1.0, 1.0), 0.0)
.unwrap();
let pth2 = assignment
.translate("ABA".to_string())
.make_path(Point::new(1.0, 1.0), 0.0)
.unwrap();
assert!(pth1.almost_eq(&pth2, 0.001));Sourcepub fn make_default_path(&self, s: String) -> Result<Path, LSystemError>
pub fn make_default_path(&self, s: String) -> Result<Path, LSystemError>
Translates the string using the assignment and then makes a path with the default starting
point and angle (Point::new(0.0, 0.0) and 0.0, respectively).
§Example
use std::f64::consts::PI;
use std::collections::HashMap;
use l_system_fractals::rules::{DrawAction, ActionString, RuleAssignment};
use l_system_fractals::paths::{Path, Point};
use l_system_fractals::num_validity::AlmostEq;
let assignment = RuleAssignment(
HashMap::from([
('A', DrawAction::DrawForward(1.0)),
('B', DrawAction::MoveForward(1.0))
])
);
let pth1 = assignment
.make_path("ABA".to_string(), Point::new(0.0, 0.0), 0.0)
.unwrap();
let pth2 = assignment
.make_default_path("ABA".to_string())
.unwrap();
assert!(pth1.almost_eq(&pth2, 0.001));Trait Implementations§
Source§impl AlmostEq for RuleAssignment
impl AlmostEq for RuleAssignment
Source§impl Clone for RuleAssignment
impl Clone for RuleAssignment
Source§fn clone(&self) -> RuleAssignment
fn clone(&self) -> RuleAssignment
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 RuleAssignment
impl Debug for RuleAssignment
Source§impl From<HashMap<char, DrawAction>> for RuleAssignment
impl From<HashMap<char, DrawAction>> for RuleAssignment
Source§impl PartialEq for RuleAssignment
impl PartialEq for RuleAssignment
impl StructuralPartialEq for RuleAssignment
Auto Trait Implementations§
impl Freeze for RuleAssignment
impl RefUnwindSafe for RuleAssignment
impl Send for RuleAssignment
impl Sync for RuleAssignment
impl Unpin for RuleAssignment
impl UnwindSafe for RuleAssignment
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