Skip to content

Commit 5c6f333

Browse files
committed
[clippy] needless_range_loop, too_many_arguments.
1 parent 9a4423f commit 5c6f333

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

.clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
single-char-binding-names-threshold = 10
2+
too-many-arguments-threshold = 15

src/accelerators/bvh.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,17 @@ impl BVHAccel {
233233
} else {
234234
// compute bound of primitive centroids, choose split dimension _dim_
235235
let mut centroid_bounds: Bounds3f = Bounds3f::default();
236-
for i in start..end {
237-
centroid_bounds = bnd3_union_pnt3(&centroid_bounds, &primitive_info[i].centroid);
236+
for item in primitive_info.iter().take(end).skip(start) {
237+
centroid_bounds = bnd3_union_pnt3(&centroid_bounds, &item.centroid);
238238
}
239239
let dim: u8 = centroid_bounds.maximum_extent();
240240
// partition primitives into two sets and build children
241241
let mut mid: usize = (start + end) / 2_usize;
242242
if centroid_bounds.p_max[dim] == centroid_bounds.p_min[dim] {
243243
// create leaf _BVHBuildNode_
244244
let first_prim_offset: usize = ordered_prims.len();
245-
for i in start..end {
246-
let prim_num: usize = primitive_info[i].primitive_number;
245+
for item in primitive_info.iter().take(end).skip(start) {
246+
let prim_num: usize = item.primitive_number;
247247
ordered_prims.push(bvh.primitives[prim_num].clone());
248248
}
249249
node.init_leaf(first_prim_offset, n_primitives, &bounds);
@@ -271,9 +271,9 @@ impl BVHAccel {
271271
let n_buckets: usize = 12;
272272
let mut buckets: [BucketInfo; 12] = [BucketInfo::default(); 12];
273273
// initialize _BucketInfo_ for SAH partition buckets
274-
for i in start..end {
274+
for item in primitive_info.iter().take(end).skip(start) {
275275
let mut b: usize = (n_buckets as Float
276-
* centroid_bounds.offset(&primitive_info[i].centroid)[dim])
276+
* centroid_bounds.offset(&item.centroid)[dim])
277277
as usize;
278278
if b == n_buckets {
279279
b = n_buckets - 1;
@@ -282,34 +282,34 @@ impl BVHAccel {
282282
assert!(b < n_buckets, "b < {}", n_buckets);
283283
buckets[b].count += 1;
284284
buckets[b].bounds =
285-
bnd3_union_bnd3(&buckets[b].bounds, &primitive_info[i].bounds);
285+
bnd3_union_bnd3(&buckets[b].bounds, &item.bounds);
286286
}
287287
// compute costs for splitting after each bucket
288288
let mut cost: [Float; 11] = [0.0; 11];
289-
for i in 0..(n_buckets - 1) {
289+
for (i, cost_item) in cost.iter_mut().enumerate().take(n_buckets - 1) {
290290
let mut b0: Bounds3f = Bounds3f::default();
291291
let mut b1: Bounds3f = Bounds3f::default();
292292
let mut count0: usize = 0;
293293
let mut count1: usize = 0;
294-
for j in 0..(i + 1) {
295-
b0 = bnd3_union_bnd3(&b0, &buckets[j].bounds);
296-
count0 += buckets[j].count;
294+
for item in buckets.iter().take(i + 1) {
295+
b0 = bnd3_union_bnd3(&b0, &item.bounds);
296+
count0 += item.count;
297297
}
298-
for j in (i + 1)..n_buckets {
299-
b1 = bnd3_union_bnd3(&b1, &buckets[j].bounds);
300-
count1 += buckets[j].count;
298+
for item in buckets.iter().take(n_buckets).skip(i + 1) {
299+
b1 = bnd3_union_bnd3(&b1, &item.bounds);
300+
count1 += item.count;
301301
}
302-
cost[i] = 1.0
302+
*cost_item = 1.0
303303
+ (count0 as Float * b0.surface_area()
304304
+ count1 as Float * b1.surface_area())
305305
/ bounds.surface_area();
306306
}
307307
// find bucket to split at that minimizes SAH metric
308308
let mut min_cost: Float = cost[0];
309309
let mut min_cost_split_bucket: usize = 0;
310-
for i in 0..(n_buckets - 1) {
311-
if cost[i] < min_cost {
312-
min_cost = cost[i];
310+
for (i, item) in cost.iter().enumerate().take(n_buckets - 1) {
311+
if item < &min_cost {
312+
min_cost = *item;
313313
min_cost_split_bucket = i;
314314
}
315315
}
@@ -344,8 +344,8 @@ impl BVHAccel {
344344
} else {
345345
// create leaf _BVHBuildNode_
346346
let first_prim_offset: usize = ordered_prims.len();
347-
for i in start..end {
348-
let prim_num: usize = primitive_info[i].primitive_number;
347+
for item in primitive_info.iter().take(end).skip(start) {
348+
let prim_num: usize = item.primitive_number;
349349
ordered_prims.push(bvh.primitives[prim_num].clone());
350350
}
351351
node.init_leaf(first_prim_offset, n_primitives, &bounds);

src/accelerators/kdtreeaccel.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl KdAccelNode {
5555
1 => self.priv_union.one_primitive = prim_nums[0] as i32,
5656
_ => {
5757
self.priv_union.primitive_indices_offset = primitive_indices.len() as i32;
58-
for i in 0..np {
59-
primitive_indices.push(prim_nums[i] as i32);
58+
for item in prim_nums.iter().take(np) {
59+
primitive_indices.push(*item as i32);
6060
}
6161
}
6262
}
@@ -179,8 +179,8 @@ impl KdTreeAccel {
179179
}
180180
// compute bounds for kd-tree construction
181181
let mut prim_bounds: Vec<Bounds3f> = Vec::with_capacity(p_len);
182-
for i in 0..p_len {
183-
let b: Bounds3f = p[i].world_bound();
182+
for item in p.iter().take(p_len) {
183+
let b: Bounds3f = item.world_bound();
184184
bounds = bnd3_union_bnd3(&bounds, &b);
185185
prim_bounds.push(b);
186186
}
@@ -255,7 +255,7 @@ impl KdTreeAccel {
255255
&mut self,
256256
node_num: i32,
257257
node_bounds: &Bounds3f,
258-
all_prim_bounds: &Vec<Bounds3f>,
258+
all_prim_bounds: &[Bounds3f],
259259
prim_nums: &[usize],
260260
n_primitives: usize,
261261
depth: i32,
@@ -316,8 +316,8 @@ impl KdTreeAccel {
316316
// trim edges to 2 * n_primitives
317317
edges[axis as usize].resize_with(2 * n_primitives, BoundEdge::default);
318318
// initialize edges for _axis_
319-
for i in 0..n_primitives {
320-
let pn: usize = prim_nums[i];
319+
for (i, item) in prim_nums.iter().enumerate().take(n_primitives) {
320+
let pn: usize = *item;
321321
let bounds: &Bounds3f = &all_prim_bounds[pn];
322322
edges[axis as usize][2 * i] = BoundEdge::new(bounds.p_min[axis], pn, true);
323323
edges[axis as usize][2 * i + 1] = BoundEdge::new(bounds.p_max[axis], pn, false);

0 commit comments

Comments
 (0)