fix non-macro clippy warnings

master
Sameer Puri 5 years ago
parent a9fe4f57ea
commit 869358aa2b

@ -95,7 +95,7 @@ pub fn svg2program(doc: &Document, options: ProgramOptions, mach: Machine) -> Ve
) )
} }
if transforms.len() != 0 { if !transforms.is_empty() {
let transform = transforms let transform = transforms
.iter() .iter()
.fold(Transform2D::identity(), |acc, t| acc.post_transform(t)); .fold(Transform2D::identity(), |acc, t| acc.post_transform(t));
@ -121,7 +121,7 @@ pub fn svg2program(doc: &Document, options: ProgramOptions, mach: Machine) -> Ve
if node.has_children() { if node.has_children() {
node_stack.push((node, node.children())); node_stack.push((node, node.children()));
name_stack.push(node_name(&node)); name_stack.push(node_name(&node));
} else if transforms.len() != 0 { } else if !transforms.is_empty() {
// Pop transform early, since this is the only element that has it // Pop transform early, since this is the only element that has it
turtle.pop_transform(); turtle.pop_transform();
} }

@ -66,7 +66,7 @@ pub fn parse_gcode(gcode: &str) -> Vec<Word> {
if let Some(l) = letter { if let Some(l) = letter {
vec.push(Word { vec.push(Word {
letter: l, letter: l,
value: parse_value(&gcode[value_range.clone()]), value: parse_value(&gcode[value_range]),
}); });
} }
vec vec
@ -78,7 +78,7 @@ fn parse_value(word: &str) -> Value {
} else { } else {
let index_of_dot = word.find('.'); let index_of_dot = word.find('.');
Value::Fractional( Value::Fractional(
word[..index_of_dot.unwrap_or(word.len())] word[..index_of_dot.unwrap_or_else(|| word.len())]
.parse::<u32>() .parse::<u32>()
.unwrap(), .unwrap(),
index_of_dot.map(|j| word[j + 1..].parse::<u32>().unwrap()), index_of_dot.map(|j| word[j + 1..].parse::<u32>().unwrap()),

@ -87,11 +87,11 @@ macro_rules! commands {
} }
} }
pub fn word<'a>(&'a self) -> &'a CommandWord { pub fn word(&'_ self) -> &'_ CommandWord {
&self.command_word &self.command_word
} }
pub fn get<'a>(&'a self, letter: char) -> Option<&'a Word> { pub fn get(&'_ self, letter: char) -> Option<&'_ Word> {
let letter = letter.to_ascii_uppercase(); let letter = letter.to_ascii_uppercase();
self.arguments.iter().find(|arg| arg.letter == letter) self.arguments.iter().find(|arg| arg.letter == letter)
} }

@ -22,7 +22,7 @@ mod postprocess;
mod turtle; mod turtle;
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
if let Err(_) = env::var("RUST_LOG") { if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", "svg2gcode=info") env::set_var("RUST_LOG", "svg2gcode=info")
} }
env_logger::init(); env_logger::init();

@ -8,17 +8,17 @@ pub fn set_origin(commands: &mut [Command], origin: F64Point) {
let mut is_relative = false; let mut is_relative = false;
let mut current_position = point(0f64, 0f64); let mut current_position = point(0f64, 0f64);
for i in 0..commands.len() { for command in commands {
match &commands[i].word() { match command.word() {
RapidPositioning | LinearInterpolation => { RapidPositioning | LinearInterpolation => {
let x: f64 = (&commands[i].get('X').unwrap().value).into(); let x: f64 = (&command.get('X').unwrap().value).into();
let y: f64 = (&commands[i].get('Y').unwrap().value).into(); let y: f64 = (&command.get('Y').unwrap().value).into();
if is_relative { if is_relative {
current_position += vector(x, y); current_position += vector(x, y);
} else { } else {
current_position = point(x, y); current_position = point(x, y);
commands[i].set('X', Value::Float((current_position + offset).x)); command.set('X', Value::Float((current_position + offset).x));
commands[i].set('Y', Value::Float((current_position + offset).y)); command.set('Y', Value::Float((current_position + offset).y));
} }
} }
AbsoluteDistanceMode => { AbsoluteDistanceMode => {
@ -36,8 +36,7 @@ fn get_bounding_box(commands: &[Command]) -> (F64Point, F64Point) {
let (mut minimum, mut maximum) = (point(0f64, 0f64), point(0f64, 0f64)); let (mut minimum, mut maximum) = (point(0f64, 0f64), point(0f64, 0f64));
let mut is_relative = false; let mut is_relative = false;
let mut current_position = point(0f64, 0f64); let mut current_position = point(0f64, 0f64);
for i in 0..commands.len() { for command in commands {
let command = &commands[i];
match command.word() { match command.word() {
AbsoluteDistanceMode => { AbsoluteDistanceMode => {
is_relative = false; is_relative = false;

@ -123,8 +123,8 @@ impl Turtle {
.iter() .iter()
.chain(self.machine.absolute().iter()) .chain(self.machine.absolute().iter())
.chain(std::iter::once(&Self::linear_interpolation( .chain(std::iter::once(&Self::linear_interpolation(
self.initial_position.x.into(), self.initial_position.x,
self.initial_position.y.into(), self.initial_position.y,
z.into(), z.into(),
f.into(), f.into(),
))) )))
@ -174,8 +174,8 @@ impl Turtle {
.iter() .iter()
.chain(self.machine.absolute().iter()) .chain(self.machine.absolute().iter())
.chain(std::iter::once(&Self::linear_interpolation( .chain(std::iter::once(&Self::linear_interpolation(
to.x.into(), to.x,
to.y.into(), to.y,
z.into(), z.into(),
f.into(), f.into(),
))) )))
@ -200,7 +200,7 @@ impl Turtle {
.flattened(tolerance) .flattened(tolerance)
.map(|point| { .map(|point| {
last_point.set(point); last_point.set(point);
Self::linear_interpolation(point.x.into(), point.y.into(), z.into(), f.into()) Self::linear_interpolation(point.x, point.y, z, f)
}) })
.collect(); .collect();
self.current_position = last_point.get(); self.current_position = last_point.get();
@ -419,10 +419,10 @@ impl Turtle {
let mut ellipse = vec![]; let mut ellipse = vec![];
arc.for_each_flattened(tolerance, &mut |point: F64Point| { arc.for_each_flattened(tolerance, &mut |point: F64Point| {
ellipse.push(Self::linear_interpolation( ellipse.push(Self::linear_interpolation(
point.x.into(), point.x,
point.y.into(), point.y,
z.into(), z,
f.into(), f,
)); ));
last_point.set(point); last_point.set(point);
}); });
@ -457,9 +457,7 @@ impl Turtle {
/// Remove all transforms, returning to true absolute coordinates /// Remove all transforms, returning to true absolute coordinates
pub fn pop_all_transforms(&mut self) { pub fn pop_all_transforms(&mut self) {
while self.transform_stack.len() != 0 { self.transform_stack.clear();
self.pop_transform();
}
self.current_transform = Transform2D::identity(); self.current_transform = Transform2D::identity();
} }

Loading…
Cancel
Save