Add initial position handling for close path

master
Sameer Puri 6 years ago
parent 5e7adcc2a8
commit b774e63c8a

@ -12,3 +12,4 @@ Convert any SVG 1.1 path to gcode for a pen plotter, laser engraver, etc.
## Known bugs & whether fixed
- [ ] Smooth curves should not use the control point when the previous curve is not of the same type (quadratic -> smooth cubic, cubic -> smooth quadratic)
- [x] Image coordinates mirrored in the y-axis because SVGs uses upper left corner as (0,0) while GCode uses lower left as (0,0)
- [x] Close path command connects back to (0.0, 0.0) instead of the last move

@ -164,7 +164,7 @@ fn svg2program(doc: &svgdom::Document, opts: ProgramOptions, mach: Machine) -> P
}
PathSegment::ClosePath { abs } => {
// Ignore abs, should have identical effect: https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand
p.extend(t.line(true, 0.0, 0.0, None, opts.feedrate))
p.extend(t.close(None, opts.feedrate))
}
PathSegment::LineTo { abs, x, y } => {
p.extend(t.line(*abs, *x, *y, None, opts.feedrate));

@ -6,6 +6,7 @@ use lyon_geom::{ArcFlags, CubicBezierSegment, QuadraticBezierSegment, SvgArc};
pub struct Turtle {
curpos: F64Point,
initpos: F64Point,
curtran: Transform2D<f64>,
scaling: Option<Transform2D<f64>>,
transtack: Vec<Transform2D<f64>>,
@ -17,6 +18,7 @@ impl Default for Turtle {
fn default() -> Self {
Self {
curpos: point(0.0, 0.0),
initpos: point(0.0, 0.0),
curtran: Transform2D::identity(),
scaling: None,
transtack: vec![],
@ -46,7 +48,8 @@ impl Turtle {
let mut to = point(x, y);
to = self.curtran.transform_point(&to);
self.curpos = to;
self.prev_ctrl = self.curpos;
self.initpos = to;
self.prev_ctrl = to;
vec![
self.mach.tool_off(),
@ -61,6 +64,27 @@ impl Turtle {
.collect()
}
pub fn close<Z, F>(&mut self, z: Z, f: F) -> Program
where
Z: Into<Option<f64>>,
F: Into<Option<f64>>,
{
self.curpos = self.initpos;
vec![
self.mach.tool_on(),
self.mach.absolute(),
vec![GCode::LinearInterpolation {
x: self.initpos.x.into(),
y: self.initpos.y.into(),
z: z.into(),
f: f.into(),
}],
]
.drain(..)
.flatten()
.collect()
}
pub fn line<X, Y, Z, F>(&mut self, abs: bool, x: X, y: Y, z: Z, f: F) -> Program
where
X: Into<Option<f64>>,
@ -334,9 +358,7 @@ impl Turtle {
self.curtran = self.curtran.post_mul(&old_scaling.inverse().unwrap());
}
self.scaling = Some(scaling);
self.curtran = self
.curtran
.post_mul(&scaling);
self.curtran = self.curtran.post_mul(&scaling);
}
pub fn push_transform(&mut self, trans: Transform2D<f64>) {

Loading…
Cancel
Save