pub trait TurtleTrait {
// Required methods
fn new() -> Turtle;
fn fwd(self, distance: f64) -> Self;
fn left(self, angle: f64) -> Self;
fn right(self, angle: f64) -> Self;
fn pen_up(self) -> Self;
fn pen_down(self) -> Self;
fn close(self) -> Self;
fn push(self) -> Self;
fn pop(self) -> Self;
fn walk_lpath(self, lpath: &String, angle: f64, distance: f64) -> Self;
fn to_multiline(&mut self) -> MultiLineString<f64>;
fn to_polygon(&mut self) -> Result<Polygon<f64>, Error>;
}
Expand description
TurtleTrait provides turtle related functions for the Turtle struct.
Provides 2D turtle actions, and a stack-based history for drawing 2D graphics.
§Example
use geo_types::MultiLineString;
use aoer_plotty_rs::turtle::{Turtle, TurtleTrait, degrees};
let mline_string: MultiLineString<f64> = Turtle::new()
.pen_down()
.fwd(100.0)
.right(degrees(90.0))
.fwd(100.0)
.right(degrees(90.0))
.fwd(100.0)
.right(degrees(90.0))
.fwd(100.0)
.right(degrees(90.0))
.to_multiline();
Required Methods§
fn new() -> Turtle
Sourcefn fwd(self, distance: f64) -> Self
fn fwd(self, distance: f64) -> Self
#fwd
Move forward @distance units (negative values are allowed)
Sourcefn pen_down(self) -> Self
fn pen_down(self) -> Self
#pen_down
Put the pen down so that we start drawing, and store the “start position” state for later closing the drawing.
Sourcefn close(self) -> Self
fn close(self) -> Self
#close
Automatically close the current line. Great for automagically closing Polygons.
Sourcefn push(self) -> Self
fn push(self) -> Self
#push
Pushes the current state onto the stack, including heading, position.
Sourcefn pop(self) -> Self
fn pop(self) -> Self
#pop
Pops the state back to the previously crate::turtle::TurtleTrait::push
’d state, but retains the line state
so that we can backtrack and continue drawing.
Sourcefn walk_lpath(self, lpath: &String, angle: f64, distance: f64) -> Self
fn walk_lpath(self, lpath: &String, angle: f64, distance: f64) -> Self
§walk_lpath (Walk L-system Path)
Used to take an existing expanded l-system path (see crate::l_system::LSystem
) for more
information on the expansion syntax. Walks the L-system, performing movements, stack
push/pop, and turns.
Sourcefn to_multiline(&mut self) -> MultiLineString<f64>
fn to_multiline(&mut self) -> MultiLineString<f64>
§to_multiline
Takes the lines recorded in the Turtle state and returns a geo_types::MultiLineString
Sourcefn to_polygon(&mut self) -> Result<Polygon<f64>, Error>
fn to_polygon(&mut self) -> Result<Polygon<f64>, Error>
§to_polygon
Returns a geo_types::Polygon
from the Turtle state. May return an error for turtles
which have self-intersecting lines, or zero-volume polygons.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.