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
16 changes: 8 additions & 8 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use clap::Parser;
use g_code::{
emit::{FormatOptions, format_gcode_io},
parse::snippet_parser,
};
use log::{error, info};
use roxmltree::ParsingOptions;
use std::{
env,
fs::File,
io::{self, Read, Write},
path::PathBuf,
};
use svgtypes::LengthListParser;

use clap::Parser;
use g_code::{
emit::{FormatOptions, format_gcode_io},
parse::snippet_parser,
};
use log::{error, info};
use roxmltree::ParsingOptions;
use svg2gcode::{
ConversionOptions, Machine, Settings, SupportedFunctionality, Version, svg2program,
};
use svgtypes::LengthListParser;

#[derive(Debug, Parser)]
#[command(name = "svg2gcode", version, author, about)]
Expand Down
4 changes: 2 additions & 2 deletions lib/src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ where
/// There are some slight deviations like using monotonic ranges instead of bounding by inflection points.
///
/// Kaewsaiha, P., & Dejdumrong, N. (2012). Modeling of Bézier Curves Using a Combination of Linear and Circular Arc Approximations. 2012 Ninth International Conference on Computer Graphics, Imaging and Visualization. doi:10.1109/cgiv.2012.20
///
fn flattened(&self, tolerance: S) -> Vec<ArcOrLineSegment<S>> {
if (self.to - self.from).square_length() < S::EPSILON {
return vec![];
Expand Down Expand Up @@ -277,9 +276,10 @@ impl<S: Scalar> Transformed<S> for SvgArc<S> {

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use cairo::{Context, SvgSurface};
use lyon_geom::{CubicBezierSegment, Point, Vector, point, vector};
use std::path::PathBuf;
use svgtypes::PathParser;

use crate::arc::{ArcOrLineSegment, FlattenWithArcs};
Expand Down
9 changes: 6 additions & 3 deletions lib/src/converter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use roxmltree::{Document, Node};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use svgtypes::Length;
use uom::si::f64::Length as UomLength;
use uom::si::length::{inch, millimeter};
use uom::si::{
f64::Length as UomLength,
length::{inch, millimeter},
};

use self::units::CSS_DEFAULT_DPI;
use crate::{Machine, turtle::*};
Expand Down Expand Up @@ -194,9 +196,10 @@ fn node_name(node: &Node, attr_to_print: &Option<String>) -> String {

#[cfg(all(test, feature = "serde"))]
mod test {
use super::*;
use svgtypes::LengthUnit;

use super::*;

#[test]
fn serde_conversion_options_is_correct() {
let default_struct = ConversionOptions::default();
Expand Down
3 changes: 1 addition & 2 deletions lib/src/converter/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use log::debug;
use lyon_geom::{ArcFlags, point, vector};
use svgtypes::PathSegment;

use crate::Turtle;

use super::Terrarium;
use crate::Turtle;

/// Maps [`PathSegment`]s into concrete operations on the [`Terrarium`]
///
Expand Down
6 changes: 2 additions & 4 deletions lib/src/converter/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use log::warn;
use roxmltree::Node;
use svgtypes::{Length, LengthListParser};

use crate::Turtle;

use super::ConversionVisitor;
use crate::Turtle;

/// The DPI assumed by CSS is 96.
///
Expand Down Expand Up @@ -49,8 +48,7 @@ impl<'a, T: Turtle> ConversionVisitor<'a, T> {
/// A default DPI of 96 is used as per [CSS 4 §7.4](https://www.w3.org/TR/css-values/#resolution)
pub fn length_to_user_units(&self, l: Length, hint: DimensionHint) -> f64 {
use svgtypes::LengthUnit::*;
use uom::si::f64::Length;
use uom::si::length::*;
use uom::si::{f64::Length, length::*};

match l.unit {
Cm => Length::new::<centimeter>(l.number).get::<inch>() * CSS_DEFAULT_DPI,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ impl Default for Version {

#[cfg(test)]
mod test {
use super::*;
use g_code::emit::{FormatOptions, Token};
use pretty_assertions::assert_eq;
use roxmltree::ParsingOptions;
use svgtypes::{Length, LengthUnit};

use super::*;

/// The values change between debug and release builds for circular interpolation,
/// so only check within a rough tolerance
const TOLERANCE: f64 = 1E-10;
Expand Down
9 changes: 5 additions & 4 deletions lib/src/turtle/g_code.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::borrow::Cow;
use std::fmt::Debug;
use std::{borrow::Cow, fmt::Debug};

use ::g_code::{command, emit::Token};
use lyon_geom::{CubicBezierSegment, Point, QuadraticBezierSegment, SvgArc};

use super::Turtle;
use crate::arc::{ArcOrLineSegment, FlattenWithArcs};
use crate::machine::Machine;
use crate::{
arc::{ArcOrLineSegment, FlattenWithArcs},
machine::Machine,
};

/// Maps path segments into g-code operations
#[derive(Debug)]
Expand Down
4 changes: 1 addition & 3 deletions lib/src/turtle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use crate::arc::Transformed;
mod dpi;
mod g_code;
mod preprocess;
pub use self::dpi::DpiConvertingTurtle;
pub use self::g_code::GCodeTurtle;
pub use self::preprocess::PreprocessTurtle;
pub use self::{dpi::DpiConvertingTurtle, g_code::GCodeTurtle, preprocess::PreprocessTurtle};

/// Abstraction for drawing paths based on [Turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics)
pub trait Turtle: Debug {
Expand Down
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
format_code_in_doc_comments = true
3 changes: 2 additions & 1 deletion web/src/forms/inputs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use paste::paste;
use std::num::ParseFloatError;

use paste::paste;
use yew::prelude::*;
use yewdux::functional::{use_store, use_store_value};

Expand Down
3 changes: 2 additions & 1 deletion web/src/forms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{convert::TryInto, path::Path};

use gloo_file::{
callbacks::{FileReader, read_as_bytes},
futures::read_as_text,
};
use js_sys::TypeError;
use roxmltree::{Document, ParsingOptions};
use std::{convert::TryInto, path::Path};
use svg2gcode::{Settings, Version};
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
Expand Down
3 changes: 2 additions & 1 deletion web/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};
use std::{convert::TryInto, num::ParseFloatError};

use serde::{Deserialize, Serialize};
use svg2gcode::{
ConversionConfig, MachineConfig, PostprocessConfig, Settings, SupportedFunctionality, Version,
};
Expand Down
1 change: 1 addition & 0 deletions web/src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Display;

use web_sys::{Event, FileList, HtmlInputElement, InputEvent, InputEventInit, MouseEvent};
use yew::{
AttrValue, Callback, Children, Html, NodeRef, Properties, TargetCast, ToHtml, classes,
Expand Down
3 changes: 2 additions & 1 deletion web/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use base64::Engine;
use std::path::Path;

use base64::Engine;
use wasm_bindgen::JsCast;
use web_sys::{HtmlElement, window};

Expand Down