Skip to content

Commit 466957a

Browse files
committed
Formattage version 0.8.1 ! A moi le "passing" !
1 parent c6fd80f commit 466957a

File tree

12 files changed

+94
-84
lines changed

12 files changed

+94
-84
lines changed

bench/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn write_bench_to_file(name: &str, time: f64) {
2424
.open(&file_name)
2525
.expect(format!("Error : can't open {} for writing benchmarks results",
2626
file_name)
27-
.as_str());
27+
.as_str());
2828
file.write_all(format!("{} was executed in: {} \n", name, time).as_bytes())
2929
.expect(format!("Error while writing the benchmark results into {}",
3030
file_name)
31-
.as_str());
31+
.as_str());
3232

3333

3434
}

src/color.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub fn make_average_color(colors: &[RGBA32]) -> RGBA32 {
4040
// Calcul de la couleur moyenne
4141

4242
let number_of_colors = colors.len();
43-
let squared_colors: Vec<(u64, u64, u64)> = colors.into_iter()
43+
let squared_colors: Vec<(u64, u64, u64)> = colors
44+
.into_iter()
4445
.map(|color| (color.r as u64, color.g as u64, color.b as u64))
4546
.collect();
4647
let mut acc: (u64, u64, u64) = (0, 0, 0);

src/geometry/obj3d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ impl Object {
433433
format!("Warning, the object {} is not centered in (0,0,0) but in {}",
434434
self.name,
435435
&barycenter)
436-
.yellow()
437-
.dimmed());
436+
.yellow()
437+
.dimmed());
438438
// On centre l'objet à l'origine.
439439
self.position = -barycenter;
440440
self.apply_position();

src/geometry/obj_parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ pub fn open_obj(file: &str) -> Mesh {
4545
let mut tex: Option<Vec<Vector2f>> = None;
4646

4747
// We clean the reader of all useless lines before iterating over it.
48-
for line in &reader.lines()
49-
.map(|l| l.expect("Error while reading line"))
50-
.collect::<Vec<String>>() {
48+
for line in &reader
49+
.lines()
50+
.map(|l| l.expect("Error while reading line"))
51+
.collect::<Vec<String>>() {
5152
let parsed_line = match parse_line(line) {
5253
Ok(t) => t,
5354
Err(e) => panic!(e),

src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use lib_render::*;
88
// Generate a template file at the location [path]
99
fn generate_template(path: &str) {
1010
let mut scene = Scene::new_empty();
11-
scene.world
11+
scene
12+
.world
1213
.add_camera(Vector3::new(0_f32, 0_f32, 5_f32),
1314
Vector3::new(10_f32, 0_f32, 0_f32));
1415

15-
scene.world
16+
scene
17+
.world
1618
.add_object(Vector3::new(10_f32, 0.56_f32, 2_f32),
1719
"models/plane_no_uv.obj".to_string(),
1820
"Example".to_string());
@@ -82,9 +84,9 @@ fn parse_arg() {
8284
// Handling the template case
8385
if matches.opt_present("g") {
8486
generate_template(match matches.opt_str("g") {
85-
Some(ref path) => path,
86-
None => "template.json",
87-
});
87+
Some(ref path) => path,
88+
None => "template.json",
89+
});
8890
}
8991

9092
// Handling the case where we need to render

src/material/channel.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ impl Texture for TextureMap {
5252
texture_registry: Option<&HashMap<String, Image<RGBA8>>>)
5353
-> RGBA32 {
5454

55-
let texture = &texture_registry.unwrap()
56-
.get(self.map_path.as_str())
57-
.unwrap();
58-
texture.get_pixel_at(((u.unwrap() * self.tiling_x * texture.width() as f32) as u32 %
55+
let texture = &texture_registry
56+
.unwrap()
57+
.get(self.map_path.as_str())
58+
.unwrap();
59+
texture
60+
.get_pixel_at(((u.unwrap() * self.tiling_x * texture.width() as f32) as u32 %
5961
texture.width()),
6062
((v.unwrap() * self.tiling_y * texture.height() as f32) as u32 %
6163
texture.height()))

src/material/flat_material.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ impl Material for FlatMaterial {
9191
if !world.is_occluded(light_ray) {
9292
let ray_vect = -light_ray.slope() / light_ray.slope().norm();
9393
//let factor = cmp::max(&0.0, &ray_vect.dot_product(&frag.normal));
94-
let factor = ray_vect.dot_product(&(frag.normal / frag.normal.norm()))
94+
let factor = ray_vect
95+
.dot_product(&(frag.normal / frag.normal.norm()))
9596
.abs();
9697
intensity += factor / light_count as f32;
9798
}
@@ -126,8 +127,8 @@ impl Material for MatCap {
126127
_: Option<&TextureRegister>)
127128
-> RGBA32 {
128129
let coef = (frag.normal
129-
.dot_product(&(ray.slope() / ray.slope().norm()))
130-
.abs() * 255f32) as u8;
130+
.dot_product(&(ray.slope() / ray.slope().norm()))
131+
.abs() * 255f32) as u8;
131132

132133
RGBA8::new(&coef, &(255u8 - coef), &coef, &255u8).to_rgba32()
133134
}

src/math.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,15 @@ mod tests {
589589
};
590590

591591
assert!((v1 * v2).aeq(&Vector3 {
592-
x: 0_f32,
593-
y: 2_f32,
594-
z: 4_f32,
595-
}));
592+
x: 0_f32,
593+
y: 2_f32,
594+
z: 4_f32,
595+
}));
596596
assert!((&v1 * &v2).aeq(&Vector3 {
597-
x: 0_f32,
598-
y: 2_f32,
599-
z: 4_f32,
600-
}));
597+
x: 0_f32,
598+
y: 2_f32,
599+
z: 4_f32,
600+
}));
601601
}
602602

603603
#[test]

src/ray.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ mod tests {
237237
});
238238

239239
assert!(match plane.get_intersection_fragment(&mut ray) {
240-
None => true,
241-
_ => false,
242-
});
240+
None => true,
241+
_ => false,
242+
});
243243
}
244244

245245
#[test]
@@ -264,9 +264,9 @@ mod tests {
264264

265265
let intersection = plane.get_intersection_fragment(&mut ray);
266266
assert!(match intersection {
267-
None => true,
268-
Some(_) => false,
269-
});
267+
None => true,
268+
Some(_) => false,
269+
});
270270
}
271271

272272
#[test]
@@ -291,17 +291,17 @@ mod tests {
291291

292292
let intersection = plane.get_intersection_fragment(&mut ray);
293293
assert!(match intersection {
294-
None => false,
295-
Some(point) => {
296-
(point.position -
297-
Vector3f {
298-
x: 0.0,
299-
y: -35.0,
300-
z: 0.0,
301-
})
302-
.norm() < 0.00001
303-
}
304-
});
294+
None => false,
295+
Some(point) => {
296+
(point.position -
297+
Vector3f {
298+
x: 0.0,
299+
y: -35.0,
300+
z: 0.0,
301+
})
302+
.norm() < 0.00001
303+
}
304+
});
305305
}
306306

307307
}

src/renderer/render.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ impl Renderer {
8080
for path in texture_paths {
8181
let path_str = String::from(path.as_str());
8282
println!("Ajout de la texture {}", path);
83-
textures.entry(path)
83+
textures
84+
.entry(path)
8485
.or_insert_with(|| Image::<RGBA8>::read_from_file(path_str.as_str()));
8586
}
8687
}
@@ -124,18 +125,18 @@ impl Renderer {
124125
le canvas passé en paramètres. */
125126
pub fn calculate_rays(&self, world: &scene::World, camera: &scene::Camera, pixel: &mut Pixel) {
126127

127-
let objects = world.objects()
128+
let objects = world
129+
.objects()
128130
.iter()
129131
.filter(|bbox| bbox.is_visible())
130132
.collect::<Vec<&Object>>();
131133

132134
for sample in &mut pixel.samples {
133135
// On récupère le rayon à partir du sample
134-
let mut ray: Ray =
135-
camera.create_ray_from_sample(sample,
136-
self.ratio,
137-
self.res_x as f32,
138-
self.res_y as f32);
136+
let mut ray: Ray = camera.create_ray_from_sample(sample,
137+
self.ratio,
138+
self.res_x as f32,
139+
self.res_y as f32);
139140

140141
// CALCUL DE LA COULEUR DU RAYON (TODO à mettre ailleurs)
141142

@@ -235,12 +236,12 @@ impl Renderer {
235236

236237
// On passe les blocs aux threads
237238
pool.scoped(|scope| while !blocks.is_empty() {
238-
let block = blocks.pop().unwrap();
239-
scope.execute(|| {
240-
self.render_block(block, world, camera, &shared_image);
241-
progress_bar.lock().unwrap().inc();
242-
});
243-
});
239+
let block = blocks.pop().unwrap();
240+
scope.execute(|| {
241+
self.render_block(block, world, camera, &shared_image);
242+
progress_bar.lock().unwrap().inc();
243+
});
244+
});
244245

245246
progress_bar.lock().unwrap().finish();
246247

@@ -261,7 +262,8 @@ impl Renderer {
261262
.create_sampler()
262263
.create_samples(&mut block);
263264

264-
let filter = self.filter_factory.create_filter(self.res_x as u32, self.res_y as u32);
265+
let filter = self.filter_factory
266+
.create_filter(self.res_x as u32, self.res_y as u32);
265267

266268
// Emission des rayons
267269
for pixel in block.pixels_mut() {
@@ -283,7 +285,8 @@ impl Renderer {
283285
}
284286

285287
// Superposition de l'image rendue à l'image finale
286-
shared_image.lock()
288+
shared_image
289+
.lock()
287290
.unwrap()
288291
.deref_mut()
289292
.superpose_sub_image(Image::<RGBA32>::from_vec_vec(&temp_result),

0 commit comments

Comments
 (0)