Skip to content

Commit b112a6b

Browse files
committed
Clippy.
1 parent e74abf0 commit b112a6b

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

crates/processing_render/src/render/command.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,23 @@ pub enum DrawCommand {
1919
PushMatrix,
2020
PopMatrix,
2121
ResetMatrix,
22-
Translate { x: f32, y: f32 },
23-
Rotate { angle: f32 },
24-
Scale { x: f32, y: f32 },
25-
ShearX { angle: f32 },
26-
ShearY { angle: f32 },
22+
Translate {
23+
x: f32,
24+
y: f32,
25+
},
26+
Rotate {
27+
angle: f32,
28+
},
29+
Scale {
30+
x: f32,
31+
y: f32,
32+
},
33+
ShearX {
34+
angle: f32,
35+
},
36+
ShearY {
37+
angle: f32,
38+
},
2739
}
2840

2941
#[derive(Debug, Default, Component)]

crates/processing_render/src/render/mod.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pub mod mesh_builder;
44
pub mod primitive;
55
pub mod transform;
66

7-
use bevy::{camera::visibility::RenderLayers, ecs::system::SystemParam, math::Affine3A, prelude::*};
7+
use bevy::{
8+
camera::visibility::RenderLayers, ecs::system::SystemParam, math::Affine3A, prelude::*,
9+
};
810
use command::{CommandBuffer, DrawCommand};
911
use material::MaterialKey;
1012
use primitive::{TessellationMode, empty_mesh};
@@ -261,20 +263,18 @@ fn spawn_mesh(ctx: &mut RenderContext, mesh: Mesh, z_offset: f32) {
261263
));
262264
}
263265

264-
fn maybe_start_batch(ctx: &mut RenderContext, material_key: MaterialKey) -> bool {
266+
fn needs_batch(ctx: &RenderContext, material_key: &MaterialKey) -> bool {
265267
let current_transform = ctx.state.transform.current();
266-
let material_changed = ctx.batch.material_key.as_ref() != Some(&material_key);
268+
let material_changed = ctx.batch.material_key.as_ref() != Some(material_key);
267269
let transform_changed = ctx.batch.transform != current_transform;
270+
material_changed || transform_changed
271+
}
268272

269-
if material_changed || transform_changed {
270-
flush_batch(ctx);
271-
ctx.batch.material_key = Some(material_key);
272-
ctx.batch.transform = current_transform;
273-
ctx.batch.current_mesh = Some(empty_mesh());
274-
true
275-
} else {
276-
false
277-
}
273+
fn start_batch(ctx: &mut RenderContext, material_key: MaterialKey) {
274+
flush_batch(ctx);
275+
ctx.batch.material_key = Some(material_key);
276+
ctx.batch.transform = ctx.state.transform.current();
277+
ctx.batch.current_mesh = Some(empty_mesh());
278278
}
279279

280280
fn add_fill(ctx: &mut RenderContext, tessellate: impl FnOnce(&mut Mesh, Color)) {
@@ -286,9 +286,10 @@ fn add_fill(ctx: &mut RenderContext, tessellate: impl FnOnce(&mut Mesh, Color))
286286
background_image: None,
287287
};
288288

289-
maybe_start_batch(ctx, material_key);
289+
if needs_batch(ctx, &material_key) {
290+
start_batch(ctx, material_key);
291+
}
290292

291-
// accumulate geometry into the current mega mesh
292293
if let Some(ref mut mesh) = ctx.batch.current_mesh {
293294
tessellate(mesh, color);
294295
}
@@ -304,9 +305,10 @@ fn add_stroke(ctx: &mut RenderContext, tessellate: impl FnOnce(&mut Mesh, Color,
304305
background_image: None,
305306
};
306307

307-
maybe_start_batch(ctx, material_key);
308+
if needs_batch(ctx, &material_key) {
309+
start_batch(ctx, material_key);
310+
}
308311

309-
// accumulate geometry into the current mega mesh
310312
if let Some(ref mut mesh) = ctx.batch.current_mesh {
311313
tessellate(mesh, color, stroke_weight);
312314
}

crates/processing_render/src/render/transform.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl TransformStack {
5151
Vec3::new(angle.tan(), 1.0, 0.0),
5252
Vec3::new(0.0, 0.0, 1.0),
5353
));
54-
self.current = self.current * shear;
54+
self.current *= shear;
5555
}
5656

5757
pub fn shear_y(&mut self, angle: f32) {
@@ -60,41 +60,41 @@ impl TransformStack {
6060
Vec3::new(0.0, 1.0, 0.0),
6161
Vec3::new(0.0, 0.0, 1.0),
6262
));
63-
self.current = self.current * shear;
63+
self.current *= shear;
6464
}
6565

6666
pub fn translate_3d(&mut self, x: f32, y: f32, z: f32) {
6767
let t = Affine3A::from_translation(Vec3::new(x, y, z));
68-
self.current = self.current * t;
68+
self.current *= t;
6969
}
7070

7171
pub fn rotate_x(&mut self, angle: f32) {
7272
let r = Affine3A::from_quat(Quat::from_rotation_x(angle));
73-
self.current = self.current * r;
73+
self.current *= r;
7474
}
7575

7676
pub fn rotate_y(&mut self, angle: f32) {
7777
let r = Affine3A::from_quat(Quat::from_rotation_y(angle));
78-
self.current = self.current * r;
78+
self.current *= r;
7979
}
8080

8181
pub fn rotate_z(&mut self, angle: f32) {
8282
let r = Affine3A::from_quat(Quat::from_rotation_z(angle));
83-
self.current = self.current * r;
83+
self.current *= r;
8484
}
8585

8686
pub fn rotate_axis(&mut self, angle: f32, axis: Vec3) {
8787
let r = Affine3A::from_quat(Quat::from_axis_angle(axis.normalize(), angle));
88-
self.current = self.current * r;
88+
self.current *= r;
8989
}
9090

9191
pub fn scale_3d(&mut self, sx: f32, sy: f32, sz: f32) {
9292
let s = Affine3A::from_scale(Vec3::new(sx, sy, sz));
93-
self.current = self.current * s;
93+
self.current *= s;
9494
}
9595

9696
pub fn apply(&mut self, transform: Affine3A) {
97-
self.current = self.current * transform;
97+
self.current *= transform;
9898
}
9999

100100
pub fn to_bevy_transform(&self) -> bevy::prelude::Transform {
@@ -118,9 +118,10 @@ impl TransformStack {
118118

119119
#[cfg(test)]
120120
mod tests {
121-
use super::*;
122121
use std::f32::consts::PI;
123122

123+
use super::*;
124+
124125
static EPSILON: f32 = 1e-5;
125126

126127
fn approx_eq(a: f32, b: f32) -> bool {

examples/transforms.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
mod glfw;
22

3+
use std::f32::consts::PI;
4+
35
use glfw::GlfwContext;
46
use processing::prelude::*;
57
use processing_render::render::command::DrawCommand;
6-
use std::f32::consts::PI;
78

89
fn main() {
910
sketch().unwrap();

0 commit comments

Comments
 (0)