Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ edition = "2024"
repository = "https://github.com/sameer/svg2gcode"
license = "MIT"

[workspace.lints.clippy]
pedantic = { level = "warn", priority = -1 }

similar_names = "allow"
doc_markdown = "allow"
must_use_candidate = "allow"
too_many_lines = "allow"
cast_possible_truncation = "allow"
cast_possible_wrap = "allow"
cast_precision_loss = "allow"
cast_sign_loss = "allow"
struct_excessive_bools = "allow"
return_self_not_must_use = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
items_after_statements = "allow"

[workspace.dependencies]
codespan-reporting = "0.13"
g-code = "0.6.0"
Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition.workspace = true
repository.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
svg2gcode = { path = "../g_code", version = "0.4.0", features = ["serde"] }
env_logger = "0.11"
Expand Down
29 changes: 13 additions & 16 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ fn main() -> io::Result<()> {
let config_json_bytes = serde_json::to_vec_pretty(&settings)?;
if export_path.to_string_lossy() == "-" {
return io::stdout().write_all(&config_json_bytes);
} else {
return File::create(export_path)?.write_all(&config_json_bytes);
}

return File::create(export_path)?.write_all(&config_json_bytes);
}

let options = {
Expand Down Expand Up @@ -266,20 +266,17 @@ fn main() -> io::Result<()> {
ConversionOptions { dimensions }
};

let input = match opt.file {
Some(filename) => {
let mut f = File::open(filename)?;
let len = f.metadata()?.len();
let mut input = String::with_capacity(len as usize + 1);
f.read_to_string(&mut input)?;
input
}
None => {
info!("Reading from standard input");
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
input
}
let input = if let Some(filename) = opt.file {
let mut f = File::open(filename)?;
let len = f.metadata()?.len();
let mut input = String::with_capacity(len as usize + 1);
f.read_to_string(&mut input)?;
input
} else {
info!("Reading from standard input");
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
input
};

let snippets = [
Expand Down
3 changes: 3 additions & 0 deletions g_code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition.workspace = true
repository.workspace = true
license.workspace = true

[lints]
workspace = true

[features]
default = ["image"]
serde = ["dep:serde", "g-code/serde", "svg2star/serde"]
Expand Down
8 changes: 4 additions & 4 deletions g_code/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct GCodeConfig {
impl Default for GCodeConfig {
fn default() -> Self {
Self {
inner: Default::default(),
inner: ConversionConfig::default(),
tolerance: 0.002,
feedrate: 300.0,
}
Expand All @@ -146,11 +146,11 @@ pub struct SupportedFunctionality {
#[derive(Debug, Default, Clone, PartialEq)]
/// Operations performed after G-Code generation.
pub struct PostprocessConfig {
/// Convenience field for [g_code::emit::FormatOptions] field
/// Convenience field for [`g_code::emit::FormatOptions`] field
pub checksums: bool,
/// Convenience field for [g_code::emit::FormatOptions] field
/// Convenience field for [`g_code::emit::FormatOptions`] field
pub line_numbers: bool,
/// Convenience field for [g_code::emit::FormatOptions] field
/// Convenience field for [`g_code::emit::FormatOptions`] field
pub newline_before_comment: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions g_code/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl<'input> Machine<'input> {
program_begin_sequence: program_begin_sequence.unwrap_or_else(|| empty_snippet.clone()),
program_end_sequence: program_end_sequence.unwrap_or_else(|| empty_snippet.clone()),
empty_snippet,
tool_state: Default::default(),
distance_mode: Default::default(),
tool_state: None,
distance_mode: None,
}
}

Expand Down
22 changes: 11 additions & 11 deletions g_code/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn get_actual(
circular_interpolation: bool,
dimensions: [Option<Length>; 2],
) -> Vec<Token<'_>> {
let gcode_config = Default::default();
let gcode_config = GCodeConfig::default();
let options = ConversionOptions { dimensions };
let document = roxmltree::Document::parse_with_options(
input,
Expand Down Expand Up @@ -115,7 +115,7 @@ fn square_transformed_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(square_transformed, false, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand All @@ -128,7 +128,7 @@ fn square_transformed_nested_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(square_transformed, false, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand All @@ -153,7 +153,7 @@ fn circular_interpolation_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(circular_interpolation, true, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand Down Expand Up @@ -191,7 +191,7 @@ fn shapes_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(shapes, false, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand All @@ -203,7 +203,7 @@ fn use_defs_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(svg, false, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand All @@ -215,7 +215,7 @@ fn use_xlink_href_produces_expected_gcode() {
.collect::<Vec<_>>();
let actual = get_actual(svg, false, [None; 2]);

assert_close(actual, expected)
assert_close(actual, expected);
}

#[test]
Expand All @@ -238,7 +238,7 @@ fn transform_origin_produces_expected_gcode() {
.iter_emit_tokens()
.collect::<Vec<_>>();
let actual = get_actual(svg, false, [None; 2]);
assert_close(actual, expected)
assert_close(actual, expected);
}

/// `transform-origin="5 5"` with `rotate(90)` should be identical to the
Expand All @@ -255,10 +255,10 @@ fn transform_origin_matches_manual_equivalent() {
false,
[None; 2],
);
assert_close(with_origin, manual)
assert_close(with_origin, manual);
}

/// Regression test for https://github.com/sameer/svg2gcode/issues/105
/// Regression test for <https://github.com/sameer/svg2gcode/issues/105>
#[test]
fn issue_105_optimize_path_order_does_not_shrink_output() {
let svg = include_str!("../tests/square.svg");
Expand All @@ -281,7 +281,7 @@ fn issue_105_optimize_path_order_does_not_shrink_output() {
);
let normal = svg_to_gcode(
&document,
&Default::default(),
&GCodeConfig::default(),
ConversionOptions::default(),
machine.clone(),
);
Expand Down
71 changes: 38 additions & 33 deletions g_code/src/turtle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'input> GCodeTurtle<'input> {
}
}

impl<'input> Turtle for GCodeTurtle<'input> {
impl Turtle for GCodeTurtle<'_> {
fn begin(&mut self) {
self.program
.append(&mut command!(UnitsMillimeters {}).into_token_vec());
Expand Down Expand Up @@ -181,67 +181,72 @@ impl<'input> Turtle for GCodeTurtle<'input> {
.supported_functionality()
.circular_interpolation
{
FlattenWithArcs::flattened(&svg_arc, self.arc_flattening_tolerance())
.into_iter()
.for_each(|segment| match segment {
for segment in
FlattenWithArcs::flattened(&svg_arc, self.arc_flattening_tolerance())
{
match segment {
ArcOrLineSegment::Arc(arc) => {
self.program.append(&mut self.circular_interpolation(arc))
self.program.append(&mut self.circular_interpolation(arc));
}
ArcOrLineSegment::Line(line) => {
self.line_to(line.to);
}
});
}
}
} else {
svg_arc
.to_arc()
.flattened(self.flattening_tolerance())
.for_each(|point| self.program.append(&mut self.line_to(point)));
};
for point in svg_arc.to_arc().flattened(self.flattening_tolerance()) {
self.program.append(&mut self.line_to(point));
}
}
}
DrawCommand::CubicBezier(cbs) => {
if self
.machine
.supported_functionality()
.circular_interpolation
{
FlattenWithArcs::<f64>::flattened(&cbs, self.arc_flattening_tolerance())
.into_iter()
.for_each(|segment| match segment {
for segment in
FlattenWithArcs::<f64>::flattened(&cbs, self.arc_flattening_tolerance())
{
match segment {
ArcOrLineSegment::Arc(arc) => {
self.program.append(&mut self.circular_interpolation(arc))
self.program.append(&mut self.circular_interpolation(arc));
}
ArcOrLineSegment::Line(line) => {
self.program.append(&mut self.line_to(line.to))
self.program.append(&mut self.line_to(line.to));
}
});
}
}
} else {
cbs.flattened(self.flattening_tolerance())
.for_each(|point| self.program.append(&mut self.line_to(point)));
};
for point in cbs.flattened(self.flattening_tolerance()) {
self.program.append(&mut self.line_to(point));
}
}
}
DrawCommand::QuadraticBezier(qbs) => {
if self
.machine
.supported_functionality()
.circular_interpolation
{
FlattenWithArcs::<f64>::flattened(
for segment in FlattenWithArcs::<f64>::flattened(
&qbs.to_cubic(),
self.arc_flattening_tolerance(),
)
.into_iter()
.for_each(|segment| match segment {
ArcOrLineSegment::Arc(arc) => {
self.program.append(&mut self.circular_interpolation(arc))
}
ArcOrLineSegment::Line(line) => {
self.program.append(&mut self.line_to(line.to))
) {
match segment {
ArcOrLineSegment::Arc(arc) => {
self.program.append(&mut self.circular_interpolation(arc));
}
ArcOrLineSegment::Line(line) => {
self.program.append(&mut self.line_to(line.to));
}
}
});
}
} else {
qbs.flattened(self.flattening_tolerance())
.for_each(|point| self.program.append(&mut self.line_to(point)));
};
for point in qbs.flattened(self.flattening_tolerance()) {
self.program.append(&mut self.line_to(point));
}
}
}
DrawCommand::Comment(comment) => {
self.program.push(Token::Comment {
Expand Down
3 changes: 3 additions & 0 deletions star/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition.workspace = true
repository.workspace = true
license.workspace = true

[lints]
workspace = true

[features]
serde = ["dep:serde"]
image = ["dep:image", "dep:base64"]
Expand Down
2 changes: 1 addition & 1 deletion star/src/lower/length_serde.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Makes it possible to serialize an array of two optional [`svgtypes::Length`]s,
//! used for [super::ConversionOptions::dimensions]
//! used for [`super::ConversionOptions::dimensions`]

use serde::{
Deserialize, Deserializer, Serialize, Serializer,
Expand Down
6 changes: 3 additions & 3 deletions star/src/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Default for ConversionConfig {

/// Options are specific to this conversion.
///
/// This is separate from [ConversionConfig] to support bulk processing in the web interface.
/// This is separate from [`ConversionConfig`] to support bulk processing in the web interface.
#[derive(Debug, Clone, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ConversionOptions {
Expand Down Expand Up @@ -96,7 +96,7 @@ struct ConversionVisitor<'a, 'input, T: Turtle> {
css_rules: HashMap<&'input str, HashMap<&'input str, &'input str>>,
}

impl<'a, 'input, T: Turtle> ConversionVisitor<'a, 'input, T> {
impl<T: Turtle> ConversionVisitor<'_, '_, T> {
fn comment(&mut self) {
let mut comment = String::new();
self.name_stack
Expand Down Expand Up @@ -269,7 +269,7 @@ fn svg_to_optimized_strokes(
minimize_travel_time(strokes, starting_point)
}

fn node_name(node: &Node, attr_to_print: &Option<String>) -> String {
fn node_name(node: &Node, attr_to_print: Option<&str>) -> String {
let mut name = node.tag_name().name().to_string();
if let Some(id) = node.attribute("id") {
name += "#";
Expand Down
Loading
Loading