Fix/silence a bunch of clippy warnings in the main crate.

This commit is contained in:
Nathan Vegdahl 2018-12-15 23:26:12 -08:00
parent d57c896151
commit c73db2edbe
21 changed files with 84 additions and 79 deletions

View File

@ -160,7 +160,7 @@ impl<'a> BVH<'a> {
});
}
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))]
#[allow(clippy::mut_from_ref)]
fn construct_from_base(
arena: &'a MemArena,
base: &BVHBase,

View File

@ -135,10 +135,6 @@ impl<'a> LightAccel for LightTree<'a> {
time: f32,
n: f32,
) -> Option<(usize, f32, f32)> {
if self.root.is_none() {
return None;
}
// Calculates the selection probability for a node
let node_prob = |node_ref: &Node| {
let bbox = lerp_slice(node_ref.bounds(), time);
@ -153,7 +149,7 @@ impl<'a> LightAccel for LightTree<'a> {
};
// Traverse down the tree, keeping track of the relative probabilities
let mut node = self.root.unwrap();
let mut node = self.root?;
let mut tot_prob = 1.0;
let mut n = n;
while let Node::Inner { children, .. } = *node {

View File

@ -46,7 +46,7 @@ where
// performance out of the code.
unsafe {
let mut a = slc.as_mut_ptr();
let mut b = a.offset(slc.len() as isize);
let mut b = a.add(slc.len());
let start = a as usize;
loop {
@ -96,7 +96,7 @@ where
// performance out of the code.
unsafe {
let mut a = slc.as_mut_ptr();
let mut b = a.offset(slc.len() as isize);
let mut b = a.add(slc.len());
let start = a as usize;
loop {
@ -151,8 +151,8 @@ where
unsafe {
let mut a1 = slc1.as_mut_ptr();
let mut a2 = slc2.as_mut_ptr();
let mut b1 = a1.offset(slc1.len() as isize);
let mut b2 = a2.offset(slc2.len() as isize);
let mut b1 = a1.add(slc1.len());
let mut b2 = a2.add(slc2.len());
let start = a1 as usize;
loop {

View File

@ -8,7 +8,7 @@ use lerp::{lerp, lerp_slice, Lerp};
use math::{fast_minf32, Matrix4x4, Point};
use ray::AccelRay;
const BBOX_MAXT_ADJUST: f32 = 1.00000024;
const BBOX_MAXT_ADJUST: f32 = 1.000_000_24;
/// A 3D axis-aligned bounding box.
#[derive(Debug, Copy, Clone)]

View File

@ -19,18 +19,18 @@ pub struct Camera<'a> {
impl<'a> Camera<'a> {
pub fn new(
arena: &'a MemArena,
transforms: Vec<Matrix4x4>,
fovs: Vec<f32>,
mut aperture_radii: Vec<f32>,
mut focus_distances: Vec<f32>,
transforms: &[Matrix4x4],
fovs: &[f32],
mut aperture_radii: &[f32],
mut focus_distances: &[f32],
) -> Camera<'a> {
assert!(!transforms.is_empty(), "Camera has no transform(s)!");
assert!(!fovs.is_empty(), "Camera has no fov(s)!");
// Aperture needs focus distance and vice-versa.
if aperture_radii.is_empty() || focus_distances.is_empty() {
aperture_radii = vec![0.0];
focus_distances = vec![1.0];
aperture_radii = &[0.0];
focus_distances = &[1.0];
if aperture_radii.is_empty() && !focus_distances.is_empty() {
println!(
@ -50,8 +50,8 @@ impl<'a> Camera<'a> {
if aperture_radii.iter().any(|a| *a > 0.0) {
println!("WARNING: camera focal distance is zero or less. Disabling focal blur.");
}
aperture_radii = vec![0.0];
focus_distances = vec![1.0];
aperture_radii = &[0.0];
focus_distances = &[1.0];
}
// Convert angle fov into linear fov.

View File

@ -3,7 +3,7 @@ use std;
pub fn hash_u32(n: u32, seed: u32) -> u32 {
let mut hash = n;
for _ in 0..3 {
hash = hash.wrapping_mul(1936502639);
hash = hash.wrapping_mul(1_936_502_639);
hash ^= hash.wrapping_shr(16);
hash = hash.wrapping_add(seed);
}
@ -14,7 +14,7 @@ pub fn hash_u32(n: u32, seed: u32) -> u32 {
pub fn hash_u64(n: u64, seed: u64) -> u64 {
let mut hash = n;
for _ in 0..4 {
hash = hash.wrapping_mul(32416190071 * 314604959);
hash = hash.wrapping_mul(32_416_190_071 * 314_604_959);
hash ^= hash.wrapping_shr(32);
hash = hash.wrapping_add(seed);
}
@ -28,7 +28,7 @@ pub fn hash_u64(n: u64, seed: u64) -> u64 {
pub fn hash_u32_to_f32(n: u32, seed: u32) -> f32 {
let mut hash = n;
for _ in 0..3 {
hash = hash.wrapping_mul(1936502639);
hash = hash.wrapping_mul(1_936_502_639);
hash ^= hash.wrapping_shr(16);
hash = hash.wrapping_add(seed);
}

View File

@ -271,7 +271,7 @@ impl<'a> Drop for Bucket<'a> {
}
fn srgb_gamma(n: f32) -> f32 {
if n < 0.0031308 {
if n < 0.003_130_8 {
n * 12.92
} else {
(1.055 * n.powf(1.0 / 2.4)) - 0.055

View File

@ -21,9 +21,9 @@ pub struct DistantDiskLight<'a> {
impl<'a> DistantDiskLight<'a> {
pub fn new(
arena: &'a MemArena,
radii: Vec<f32>,
directions: Vec<Vector>,
colors: Vec<XYZ>,
radii: &[f32],
directions: &[Vector],
colors: &[XYZ],
) -> DistantDiskLight<'a> {
DistantDiskLight {
radii: arena.copy_slice(&radii),

View File

@ -28,8 +28,8 @@ pub struct RectangleLight<'a> {
impl<'a> RectangleLight<'a> {
pub fn new<'b>(
arena: &'b MemArena,
dimensions: Vec<(f32, f32)>,
colors: Vec<XYZ>,
dimensions: &[(f32, f32)],
colors: &[XYZ],
) -> RectangleLight<'b> {
let bbs: Vec<_> = dimensions
.iter()

View File

@ -29,7 +29,7 @@ pub struct SphereLight<'a> {
}
impl<'a> SphereLight<'a> {
pub fn new<'b>(arena: &'b MemArena, radii: Vec<f32>, colors: Vec<XYZ>) -> SphereLight<'b> {
pub fn new<'b>(arena: &'b MemArena, radii: &[f32], colors: &[XYZ]) -> SphereLight<'b> {
let bbs: Vec<_> = radii
.iter()
.map(|r| BBox {

View File

@ -1,10 +1,15 @@
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
#![cfg_attr(feature = "cargo-clippy", allow(inline_always))]
#![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
#![cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
#![cfg_attr(feature = "cargo-clippy", allow(needless_return))]
#![cfg_attr(feature = "cargo-clippy", allow(or_fun_call))]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#![allow(clippy::float_cmp)]
#![allow(clippy::inline_always)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::needless_lifetimes)]
#![allow(clippy::needless_return)]
#![allow(clippy::or_fun_call)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::redundant_field_names)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::cast_lossless)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::excessive_precision)]
extern crate bvh_order;
extern crate color as color_util;
extern crate float4;
@ -74,7 +79,7 @@ use renderer::LightPath;
use surface::SurfaceIntersection;
use timer::Timer;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() {
let mut t = Timer::new();
@ -349,8 +354,8 @@ fn main() {
// Print memory stats if stats are wanted.
if args.is_present("stats") {
let arena_stats = arena.stats();
let mib_occupied = arena_stats.0 as f64 / 1048576.0;
let mib_allocated = arena_stats.1 as f64 / 1048576.0;
let mib_occupied = arena_stats.0 as f64 / 1_048_576.0;
let mib_allocated = arena_stats.1 as f64 / 1_048_576.0;
println!("MemArena stats:");
@ -373,5 +378,5 @@ fn main() {
}
// End with blank line
println!("");
println!();
}

View File

@ -133,8 +133,8 @@ pub fn fast_ln(x: f32) -> f32 {
use std::mem::transmute_copy;
let mut y = unsafe { transmute_copy::<f32, u32>(&x) as f32 };
y *= 8.2629582881927490e-8;
y - 87.989971088
y *= 8.262_958_288_192_749_0e-8;
y - 87.989_971_088
}
pub fn fast_pow2(p: f32) -> f32 {
@ -146,7 +146,7 @@ pub fn fast_pow2(p: f32) -> f32 {
let z: f32 = clipp - w as f32 + offset;
let i: u32 = ((1 << 23) as f32
* (clipp + 121.2740575 + 27.7280233 / (4.84252568 - z) - 1.49012907 * z))
* (clipp + 121.274_057_5 + 27.728_023_3 / (4.842_525_68 - z) - 1.490_129_07 * z))
as u32;
unsafe { transmute_copy::<u32, f32>(&i) }
@ -156,10 +156,10 @@ pub fn fast_log2(x: f32) -> f32 {
use std::mem::transmute_copy;
let xi = unsafe { transmute_copy::<f32, u32>(&x) };
let y = xi as f32 * 1.1920928955078125e-7;
let mx = unsafe { transmute_copy::<u32, f32>(&((xi & 0x007FFFFF) | 0x3f000000)) };
let y = xi as f32 * 1.192_092_895_507_812_5e-7;
let mx = unsafe { transmute_copy::<u32, f32>(&((xi & 0x007F_FFFF) | 0x3f00_0000)) };
y - 124.22551499 - 1.498030302 * mx - 1.72587999 / (0.3520887068 + mx)
y - 124.225_514_99 - 1.498_030_302 * mx - 1.725_879_99 / (0.352_088_706_8 + mx)
}
pub fn fast_exp(p: f32) -> f32 {
@ -174,7 +174,7 @@ pub fn faster_pow2(p: f32) -> f32 {
use std::mem::transmute_copy;
let clipp: f32 = if p < -126.0 { -126.0 } else { p };
let i: u32 = ((1 << 23) as f32 * (clipp + 126.94269504)) as u32;
let i: u32 = ((1 << 23) as f32 * (clipp + 126.942_695_04)) as u32;
unsafe { transmute_copy::<u32, f32>(&i) }
}

View File

@ -142,7 +142,7 @@ impl<'a> DataTree<'a> {
type_name,
ident,
ref children,
byte_offset: _,
..
} = *self
{
(type_name, ident, children)
@ -154,7 +154,7 @@ impl<'a> DataTree<'a> {
if let DataTree::Leaf {
type_name,
contents,
byte_offset: _,
..
} = *self
{
(type_name, contents)

View File

@ -217,7 +217,7 @@ fn parse_output_info(tree: &DataTree) -> Result<String, PsyParseError> {
incorrect.",
));
}
if tc.chars().nth(0).unwrap() != '"' || tc.chars().last().unwrap() != '"' {
if tc.chars().nth(0).unwrap() != '"' || !tc.ends_with('"') {
return Err(PsyParseError::IncorrectLeafData(
byte_offset,
"File paths must be \
@ -434,10 +434,10 @@ fn parse_camera<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result<Camera<'a
return Ok(Camera::new(
arena,
mats,
fovs,
aperture_radii,
focus_distances,
&mats,
&fovs,
&aperture_radii,
&focus_distances,
));
} else {
return Err(PsyParseError::ExpectedInternalNode(

View File

@ -79,7 +79,7 @@ pub fn parse_distant_disk_light<'a>(
}
}
return Ok(DistantDiskLight::new(arena, radii, directions, colors));
return Ok(DistantDiskLight::new(arena, &radii, &directions, &colors));
} else {
return Err(PsyParseError::UnknownError(tree.byte_offset()));
}
@ -133,7 +133,7 @@ pub fn parse_sphere_light<'a>(
}
}
return Ok(SphereLight::new(arena, radii, colors));
return Ok(SphereLight::new(arena, &radii, &colors));
} else {
return Err(PsyParseError::UnknownError(tree.byte_offset()));
}
@ -189,7 +189,7 @@ pub fn parse_rectangle_light<'a>(
}
}
return Ok(RectangleLight::new(arena, dimensions, colors));
return Ok(RectangleLight::new(arena, &dimensions, &colors));
} else {
return Err(PsyParseError::UnknownError(tree.byte_offset()));
}

View File

@ -123,12 +123,12 @@ pub fn parse_mesh_surface<'a>(
Ok(TriangleMesh::from_verts_and_indices(
arena,
verts,
if normals.is_empty() {
&verts,
&if normals.is_empty() {
None
} else {
Some(normals)
},
tri_vert_indices,
&tri_vert_indices,
))
}

View File

@ -445,7 +445,7 @@ impl LightPath {
// - Collect light from the emission.
// - Terminate the path.
use shading::surface_closure::SurfaceClosureUnion;
if let &SurfaceClosureUnion::EmitClosure(ref clsr) = closure {
if let SurfaceClosureUnion::EmitClosure(ref clsr) = *closure {
if let LightPathEvent::CameraRay = self.event {
self.color += clsr.emitted_color().e;
} else {

View File

@ -141,7 +141,7 @@ fn dielectric_fresnel_from_fac(fresnel_fac: f32, c: f32) -> f32 {
let tmp1 = fresnel_fac.sqrt() - 1.0;
// Protect against divide by zero.
if tmp1.abs() < 0.000001 {
if tmp1.abs() < 0.000_001 {
return 1.0;
}
@ -410,7 +410,7 @@ impl GTRClosure {
self.tail_shape = (0.0001f32).max(self.tail_shape);
// When roughness is too small, but not zero, there are floating point accuracy issues
if self.roughness < 0.000244140625 {
if self.roughness < 0.000_244_140_625 {
// (2^-12)
self.roughness = 0.0;
}

View File

@ -27,9 +27,9 @@ pub struct TriangleMesh<'a> {
impl<'a> TriangleMesh<'a> {
pub fn from_verts_and_indices<'b>(
arena: &'b MemArena,
verts: Vec<Vec<Point>>,
vert_normals: Option<Vec<Vec<Normal>>>,
tri_indices: Vec<(usize, usize, usize)>,
verts: &[Vec<Point>],
vert_normals: &Option<Vec<Vec<Normal>>>,
tri_indices: &[(usize, usize, usize)],
) -> TriangleMesh<'b> {
let vert_count = verts[0].len();
let time_sample_count = verts.len();
@ -80,7 +80,7 @@ impl<'a> TriangleMesh<'a> {
// Create bounds array for use during BVH construction
let bounds = {
let mut bounds = Vec::with_capacity(indices.len() * time_sample_count);
for tri in &tri_indices {
for tri in tri_indices {
for ti in 0..time_sample_count {
let p0 = verts[ti][tri.0];
let p1 = verts[ti][tri.1];

View File

@ -24,23 +24,23 @@ impl Timer {
let dt = n - self.last_time;
self.last_time = n;
dt as f32 / 1000000000.0
dt as f32 / 1_000_000_000.0
}
/// Returns the time elapsed in seconds since the last call to tick().
pub fn elapsed(&self) -> f32 {
pub fn elapsed(self) -> f32 {
let dt = time::precise_time_ns() - self.last_time;
dt as f32 / 1000000000.0
dt as f32 / 1_000_000_000.0
}
/// Sleeps the current thread until n seconds after the last tick.
pub fn sleep_until(&self, n: f32) {
pub fn sleep_until(self, n: f32) {
let dt = time::precise_time_ns() - self.last_time;
let target_dt = ((n as f64) * 1000000000.0) as u64;
let target_dt = ((n as f64) * 1_000_000_000.0) as u64;
if dt < target_dt {
let delay = target_dt - dt;
let seconds = delay / 1000000000;
let nanoseconds = delay % 1000000000;
let seconds = delay / 1_000_000_000;
let nanoseconds = delay % 1_000_000_000;
thread::sleep(Duration::new(seconds, nanoseconds as u32));
}
}

View File

@ -14,13 +14,17 @@ pub fn encode(vec: (f32, f32, f32)) -> u32 {
let (u, v) = if vec.2 < 0.0 {
(
to_snorm_16((1.0 - (vec.1 * inv_l1_norm).abs()) * sign(vec.0)) as u32,
to_snorm_16((1.0 - (vec.0 * inv_l1_norm).abs()) * sign(vec.1)) as u32,
u32::from(to_snorm_16(
(1.0 - (vec.1 * inv_l1_norm).abs()) * sign(vec.0),
)),
u32::from(to_snorm_16(
(1.0 - (vec.0 * inv_l1_norm).abs()) * sign(vec.1),
)),
)
} else {
(
to_snorm_16(vec.0 * inv_l1_norm) as u32,
to_snorm_16(vec.1 * inv_l1_norm) as u32,
u32::from(to_snorm_16(vec.0 * inv_l1_norm)),
u32::from(to_snorm_16(vec.1 * inv_l1_norm)),
)
};
@ -53,7 +57,7 @@ fn to_snorm_16(n: f32) -> u16 {
#[inline(always)]
fn from_snorm_16(n: u16) -> f32 {
(n as i16 as f32)
f32::from(n as i16)
* (1.0f32 / ((1u32 << (16 - 1)) - 1) as f32)
.max(-1.0)
.min(1.0)