Skip to content

Commit e50e42b

Browse files
committed
v0.3.1: Fix origin override broken by 8f9db32
This now needs to be converted from mm into user units
1 parent 53c7c29 commit e50e42b

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "svg2gcode-cli"
3-
version = "0.0.13"
3+
version = "0.0.14"
44
authors = ["Sameer Puri <crates@purisa.me>"]
55
edition = "2021"
66
description = "Command line interface for svg2gcode"
77
repository = "https://github.com/sameer/svg2gcode"
88
license = "MIT"
99

1010
[dependencies]
11-
svg2gcode = { version = "0.3.0", features = ["serde"] }
11+
svg2gcode = { version = "0.3.1", features = ["serde"] }
1212
env_logger = { version = "0", default-features = false, features = [
1313
"atty",
1414
"termcolor",

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "svg2gcode"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Sameer Puri <crates@purisa.me>"]
55
edition = "2021"
66
description = "Convert paths in SVG files to GCode for a pen plotter, laser engraver, or other machine."

lib/src/converter/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use roxmltree::{Document, Node};
66
#[cfg(feature = "serde")]
77
use serde::{Deserialize, Serialize};
88
use svgtypes::Length;
9+
use uom::si::f64::Length as UomLength;
10+
use uom::si::length::{inch, millimeter};
911

1012
use crate::{turtle::*, Machine};
13+
use self::units::CSS_DEFAULT_DPI;
1114

1215
#[cfg(feature = "serde")]
1316
mod length_serde;
@@ -26,7 +29,7 @@ pub struct ConversionConfig {
2629
pub feedrate: f64,
2730
/// Dots per inch for pixels, picas, points, etc.
2831
pub dpi: f64,
29-
/// Set the origin point for this conversion
32+
/// Set the origin point in millimeters for this conversion
3033
#[cfg_attr(feature = "serde", serde(default = "zero_origin"))]
3134
pub origin: [Option<f64>; 2],
3235
}
@@ -119,7 +122,13 @@ pub fn svg2program<'a, 'input: 'a>(
119122

120123
visitor.terrarium.turtle.inner.bounding_box
121124
};
122-
let origin_transform = match config.origin {
125+
126+
// Convert from millimeters to user units
127+
let origin = config
128+
.origin
129+
.map(|dim| dim.map(|d| UomLength::new::<millimeter>(d).get::<inch>() * CSS_DEFAULT_DPI));
130+
131+
let origin_transform = match origin {
123132
[None, Some(origin_y)] => {
124133
let bb = bounding_box_generator();
125134
Transform2D::translation(0., origin_y - bb.min.y)

lib/src/converter/units.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ use crate::Turtle;
66

77
use super::ConversionVisitor;
88

9+
/// The DPI assumed by CSS is 96.
10+
///
11+
/// <https://www.w3.org/TR/css3-values/#absolute-lengths>
12+
pub const CSS_DEFAULT_DPI: f64 = 96.;
13+
914
/// Used to compute percentages correctly
1015
///
1116
/// <https://www.w3.org/TR/SVG/coords.html#Units>
@@ -47,8 +52,6 @@ impl<'a, T: Turtle> ConversionVisitor<'a, T> {
4752
use uom::si::f64::Length;
4853
use uom::si::length::*;
4954

50-
const CSS_DEFAULT_DPI: f64 = 96.;
51-
5255
match l.unit {
5356
Cm => Length::new::<centimeter>(l.number).get::<inch>() * CSS_DEFAULT_DPI,
5457
Mm => Length::new::<millimeter>(l.number).get::<inch>() * CSS_DEFAULT_DPI,

lib/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Settings {
3434
///
3535
/// - Settings version is [`Version::Unknown`].
3636
/// - There are breaking changes requiring manual intervention. In which case this does a partial update to that point.
37-
pub fn try_upgrade(&mut self) -> Result<(), ()> {
37+
pub fn try_upgrade(&mut self) -> Result<(), &'static str> {
3838
loop {
3939
match self.version {
4040
// Compatibility for M2 by default
@@ -46,7 +46,7 @@ impl Settings {
4646
self.version = Version::V5;
4747
}
4848
Version::V5 => break Ok(()),
49-
Version::Unknown(_) => break Err(()),
49+
Version::Unknown(_) => break Err("cannot upgrade unknown version"),
5050
}
5151
}
5252
}

web/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "svg2gcode-web"
3-
version = "0.0.14"
3+
version = "0.0.15"
44
authors = ["Sameer Puri <crates@purisa.me>"]
55
edition = "2021"
66
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
@@ -10,7 +10,7 @@ license = "MIT"
1010

1111
[dependencies]
1212
wasm-bindgen = "0.2"
13-
svg2gcode = { version = "0.3.0", features = ["serde"] }
13+
svg2gcode = { version = "0.3.1", features = ["serde"] }
1414
roxmltree = "0.19"
1515
g-code = "0.4.2"
1616
codespan-reporting = "0.11"

0 commit comments

Comments
 (0)