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
.iter()
.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() {
node_stack.push((node, node.children()));
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
turtle.pop_transform();
}

@ -66,7 +66,7 @@ pub fn parse_gcode(gcode: &str) -> Vec<Word> {
if let Some(l) = letter {
vec.push(Word {
letter: l,
value: parse_value(&gcode[value_range.clone()]),
value: parse_value(&gcode[value_range]),
});
}
vec
@ -78,7 +78,7 @@ fn parse_value(word: &str) -> Value {
} else {
let index_of_dot = word.find('.');
Value::Fractional(
word[..index_of_dot.unwrap_or(word.len())]
word[..index_of_dot.unwrap_or_else(|| word.len())]
.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
}
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();
self.arguments.iter().find(|arg| arg.letter == letter)
}

@ -22,7 +22,7 @@ mod postprocess;
mod turtle;
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_logger::init();

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

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

Loading…
Cancel
Save