Adds placeholders for documentation

master
Loren Rogers 5 years ago
parent d5cb2e0306
commit b88f7614e7

@ -1,53 +1,65 @@
/// TODO: Documentation
use std::io::{self, Write}; use std::io::{self, Write};
use std::ops::AddAssign; use std::ops::AddAssign;
// TODO: Documentation
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
pub enum Direction { pub enum Direction {
Clockwise, Clockwise,
AntiClockwise, AntiClockwise,
} }
// TODO: Documentation
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub enum Tool { pub enum Tool {
Off, Off,
On, On,
} }
// TODO: Documentation
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub enum Distance { pub enum Distance {
Absolute, Absolute,
Incremental, Incremental,
} }
// TODO: Documentation
#[derive(Default, PartialEq, Clone)] #[derive(Default, PartialEq, Clone)]
pub struct Program(Vec<GCode>); pub struct Program(Vec<GCode>);
// TODO: Documentation
impl std::ops::Deref for Program { impl std::ops::Deref for Program {
type Target = [GCode]; type Target = [GCode];
// TODO: Documentation
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.0.deref() self.0.deref()
} }
} }
// TODO: Documentation
impl AddAssign for Program { impl AddAssign for Program {
fn add_assign(&mut self, mut other: Program) { fn add_assign(&mut self, mut other: Program) {
self.0.extend(other.0.drain(..)); self.0.extend(other.0.drain(..));
} }
} }
// TODO: Documentation
impl From<Vec<GCode>> for Program { impl From<Vec<GCode>> for Program {
fn from(v: Vec<GCode>) -> Self { fn from(v: Vec<GCode>) -> Self {
Self(v) Self(v)
} }
} }
// TODO: Documentation
impl Program { impl Program {
pub fn push(&mut self, g: GCode) { pub fn push(&mut self, g: GCode) {
self.0.push(g) self.0.push(g)
} }
} }
// TODO: Documentation
macro_rules! write_if_some { macro_rules! write_if_some {
($w:expr, $s:expr, $v:ident) => { ($w:expr, $s:expr, $v:ident) => {
if let Some(v) = $v { if let Some(v) = $v {
@ -58,6 +70,7 @@ macro_rules! write_if_some {
}; };
} }
// TODO: Documentation
// Rudimentary regular expression GCode validator. // Rudimentary regular expression GCode validator.
pub fn validate_gcode(gcode: &&str) -> bool { pub fn validate_gcode(gcode: &&str) -> bool {
use regex::Regex; use regex::Regex;
@ -65,6 +78,7 @@ pub fn validate_gcode(gcode: &&str) -> bool {
gcode.lines().all(|line| re.is_match(line)) gcode.lines().all(|line| re.is_match(line))
} }
// TODO: Documentation
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub enum GCode { pub enum GCode {
RapidPositioning { RapidPositioning {
@ -93,6 +107,8 @@ pub enum GCode {
Raw(Box<String>), Raw(Box<String>),
} }
// TODO: Documentation
// TODO: This function is too large
pub fn program2gcode<W: Write>(p: &Program, mut w: W) -> io::Result<()> { pub fn program2gcode<W: Write>(p: &Program, mut w: W) -> io::Result<()> {
use GCode::*; use GCode::*;
let mut last_feedrate: Option<f64> = None; let mut last_feedrate: Option<f64> = None;

@ -4,6 +4,7 @@
use crate::code::*; use crate::code::*;
// TODO: Documentation
// Generic machine state simulation, assuming nothing is known about the machine when initialized. // Generic machine state simulation, assuming nothing is known about the machine when initialized.
pub struct Machine { pub struct Machine {
tool_state: Option<Tool>, tool_state: Option<Tool>,
@ -12,6 +13,7 @@ pub struct Machine {
pub tool_off_action: Vec<GCode>, pub tool_off_action: Vec<GCode>,
} }
// TODO: Documentation
// Assigns reasonable default settings that apply to most gcode applications. // Assigns reasonable default settings that apply to most gcode applications.
impl Default for Machine { impl Default for Machine {
fn default() -> Self { fn default() -> Self {
@ -38,7 +40,8 @@ impl Default for Machine {
} }
} }
// Implements the state machine functions // TODO: Documentation
// Implements the state machine functions to export Gcode.
impl Machine { impl Machine {
// Outputs gcode to turn the tool on. // Outputs gcode to turn the tool on.
pub fn tool_on(&mut self) -> Vec<GCode> { pub fn tool_on(&mut self) -> Vec<GCode> {

@ -1,3 +1,5 @@
/// TODO: documentation
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate env_logger; extern crate env_logger;
@ -23,6 +25,7 @@ use code::*;
use machine::*; use machine::*;
use turtle::*; use turtle::*;
// TODO: Documentation
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
if env::var("RUST_LOG").is_err() { if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", "svg2gcode=info") env::set_var("RUST_LOG", "svg2gcode=info")
@ -82,12 +85,14 @@ fn main() -> io::Result<()> {
program2gcode(&prog, File::create("out.gcode")?) program2gcode(&prog, File::create("out.gcode")?)
} }
// TODO: Documentation
struct ProgramOptions { struct ProgramOptions {
tolerance: f64, tolerance: f64,
feedrate: f64, feedrate: f64,
dpi: f64, dpi: f64,
} }
// Sets the baseline options for the machine.
impl Default for ProgramOptions { impl Default for ProgramOptions {
fn default() -> Self { fn default() -> Self {
ProgramOptions { ProgramOptions {
@ -98,6 +103,8 @@ impl Default for ProgramOptions {
} }
} }
// TODO: Documentation
// TODO: This function is much too large
fn svg2program(doc: &svgdom::Document, opts: ProgramOptions, mach: Machine) -> Program { fn svg2program(doc: &svgdom::Document, opts: ProgramOptions, mach: Machine) -> Program {
let mut p = Program::default(); let mut p = Program::default();
let mut t = Turtle::from(mach); let mut t = Turtle::from(mach);
@ -289,6 +296,7 @@ fn svg2program(doc: &svgdom::Document, opts: ProgramOptions, mach: Machine) -> P
p p
} }
// TODO: Documentation
fn length_to_mm(l: svgdom::Length, dpi: f64) -> f64 { fn length_to_mm(l: svgdom::Length, dpi: f64) -> f64 {
use svgdom::LengthUnit::*; use svgdom::LengthUnit::*;
use uom::si::f64::Length; use uom::si::f64::Length;

@ -1,12 +1,14 @@
/// TODO: Documentation
use crate::code::GCode; use crate::code::GCode;
use crate::machine::Machine; use crate::machine::Machine;
use lyon_geom::euclid::{Angle, default::Transform2D}; use lyon_geom::euclid::{Angle, default::Transform2D};
use lyon_geom::math::{point, vector, F64Point}; use lyon_geom::math::{point, vector, F64Point};
use lyon_geom::{ArcFlags, CubicBezierSegment, QuadraticBezierSegment, SvgArc}; use lyon_geom::{ArcFlags, CubicBezierSegment, QuadraticBezierSegment, SvgArc};
/// Turtle graphics simulator for paths that outputs the GCode enum representation for each operation. /// Turtle graphics simulator for paths that outputs the GCode enum
/// Handles trasforms, scaling, position offsets, etc. /// representation for each operation. Handles trasforms, scaling, position
/// See https://www.w3.org/TR/SVG/paths.html /// offsets, etc. See https://www.w3.org/TR/SVG/paths.html
pub struct Turtle { pub struct Turtle {
curpos: F64Point, curpos: F64Point,
initpos: F64Point, initpos: F64Point,
@ -17,6 +19,7 @@ pub struct Turtle {
prev_ctrl: Option<F64Point>, prev_ctrl: Option<F64Point>,
} }
// TODO: Documentation
impl Default for Turtle { impl Default for Turtle {
fn default() -> Self { fn default() -> Self {
Self { Self {
@ -31,6 +34,7 @@ impl Default for Turtle {
} }
} }
// TODO: Documentation
impl From<Machine> for Turtle { impl From<Machine> for Turtle {
fn from(m: Machine) -> Self { fn from(m: Machine) -> Self {
let mut t = Self::default(); let mut t = Self::default();
@ -39,6 +43,7 @@ impl From<Machine> for Turtle {
} }
} }
// TODO: Documentation
impl Turtle { impl Turtle {
pub fn move_to<X, Y>(&mut self, abs: bool, x: X, y: Y) -> Vec<GCode> pub fn move_to<X, Y>(&mut self, abs: bool, x: X, y: Y) -> Vec<GCode>
where where
@ -75,12 +80,14 @@ impl Turtle {
.collect() .collect()
} }
// TODO: Documentation
pub fn close<Z, F>(&mut self, z: Z, f: F) -> Vec<GCode> pub fn close<Z, F>(&mut self, z: Z, f: F) -> Vec<GCode>
where where
Z: Into<Option<f64>>, Z: Into<Option<f64>>,
F: Into<Option<f64>>, F: Into<Option<f64>>,
{ {
// See https://www.w3.org/TR/SVG/paths.html#Segment-CompletingClosePath which could result in a G91 G1 X0 Y0 // See https://www.w3.org/TR/SVG/paths.html#Segment-CompletingClosePath
// which could result in a G91 G1 X0 Y0
if (self.curpos - self.initpos) if (self.curpos - self.initpos)
.abs() .abs()
.lower_than(vector(std::f64::EPSILON, std::f64::EPSILON)) .lower_than(vector(std::f64::EPSILON, std::f64::EPSILON))
@ -104,6 +111,7 @@ impl Turtle {
.collect() .collect()
} }
// TODO: Documentation
pub fn line<X, Y, Z, F>(&mut self, abs: bool, x: X, y: Y, z: Z, f: F) -> Vec<GCode> pub fn line<X, Y, Z, F>(&mut self, abs: bool, x: X, y: Y, z: Z, f: F) -> Vec<GCode>
where where
X: Into<Option<f64>>, X: Into<Option<f64>>,
@ -176,6 +184,7 @@ impl Turtle {
.collect() .collect()
} }
// TODO: Documentation
pub fn cubic_bezier<Z, F>( pub fn cubic_bezier<Z, F>(
&mut self, &mut self,
abs: bool, abs: bool,
@ -217,6 +226,7 @@ impl Turtle {
self.bezier(cbs, tolerance, z, f) self.bezier(cbs, tolerance, z, f)
} }
// TODO: Documentation
pub fn smooth_cubic_bezier<Z, F>( pub fn smooth_cubic_bezier<Z, F>(
&mut self, &mut self,
abs: bool, abs: bool,
@ -254,6 +264,7 @@ impl Turtle {
self.bezier(cbs, tolerance, z, f) self.bezier(cbs, tolerance, z, f)
} }
// TODO: Documentation
pub fn smooth_quadratic_bezier<Z, F>( pub fn smooth_quadratic_bezier<Z, F>(
&mut self, &mut self,
abs: bool, abs: bool,
@ -281,6 +292,7 @@ impl Turtle {
self.bezier(qbs.to_cubic(), tolerance, z, f) self.bezier(qbs.to_cubic(), tolerance, z, f)
} }
// TODO: Documentation
pub fn quadratic_bezier<Z, F>( pub fn quadratic_bezier<Z, F>(
&mut self, &mut self,
abs: bool, abs: bool,
@ -312,6 +324,7 @@ impl Turtle {
self.bezier(qbs.to_cubic(), tolerance, z, f) self.bezier(qbs.to_cubic(), tolerance, z, f)
} }
// TODO: Documentation
pub fn elliptical<Z, F>( pub fn elliptical<Z, F>(
&mut self, &mut self,
abs: bool, abs: bool,
@ -377,6 +390,7 @@ impl Turtle {
.collect() .collect()
} }
// TODO: Documentation
pub fn stack_scaling(&mut self, scaling: Transform2D<f64>) { pub fn stack_scaling(&mut self, scaling: Transform2D<f64>) {
self.curtran = self.curtran.post_transform(&scaling); self.curtran = self.curtran.post_transform(&scaling);
if let Some(ref current_scaling) = self.scaling { if let Some(ref current_scaling) = self.scaling {
@ -386,6 +400,7 @@ impl Turtle {
} }
} }
// TODO: Documentation
pub fn push_transform(&mut self, trans: Transform2D<f64>) { pub fn push_transform(&mut self, trans: Transform2D<f64>) {
self.transtack.push(self.curtran); self.transtack.push(self.curtran);
if let Some(ref scaling) = self.scaling { if let Some(ref scaling) = self.scaling {
@ -399,6 +414,7 @@ impl Turtle {
} }
} }
// TODO: Documentation
pub fn pop_transform(&mut self) { pub fn pop_transform(&mut self) {
self.curtran = self self.curtran = self
.transtack .transtack
@ -406,6 +422,7 @@ impl Turtle {
.expect("popped when no transforms left"); .expect("popped when no transforms left");
} }
// TODO: Documentation
pub fn reset(&mut self) { pub fn reset(&mut self) {
self.curpos = point(0.0, 0.0); self.curpos = point(0.0, 0.0);
self.curpos = self.curtran.transform_point(self.curpos); self.curpos = self.curtran.transform_point(self.curpos);

Loading…
Cancel
Save