Skip to content

Commit feb0678

Browse files
committed
Clippy lints and code quality.
1 parent 443de13 commit feb0678

23 files changed

+158
-204
lines changed

shaders/src/shaders/a_lot_of_spheres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn intersect_plane(ro: Vec3, rd: Vec3, height: f32, dist: &mut f32) -> bool {
7777
}
7878

7979
let mut d: f32 = -(ro.y - height) / rd.y;
80-
d = d.min(100000.0);
80+
d = d.min(100_000.0);
8181
if d > 0.0 {
8282
*dist = d;
8383
return true;

shaders/src/shaders/a_question_of_time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn stroke(d: f32, w: f32, s: f32, i: f32) -> f32 {
7575
}
7676
// a simple palette
7777
fn pal(d: f32) -> Vec3 {
78-
0.5 * ((6.283 * d * vec3(2.0, 2.0, 1.0) + vec3(0.0, 1.4, 0.0)).cos() + Vec3::ONE)
78+
0.5 * ((TAU * d * vec3(2.0, 2.0, 1.0) + vec3(0.0, 1.4, 0.0)).cos() + Vec3::ONE)
7979
}
8080
// 2d rotation matrix
8181
fn uvr_rotate(a: f32) -> Mat2 {
@@ -100,7 +100,7 @@ fn apollonian(uv: Vec2) -> Vec3 {
100100
// a DEC is a configuration of 4 circles tangent to each other
101101
// the easiest way to build the initial one it to construct a symetric Steiner Chain.
102102
// http://mathworld.wolfram.com/SteinerChain.html
103-
let a: f32 = 6.283 / 3.;
103+
let a: f32 = TAU / 3.;
104104
let ra: f32 = 1.0 + (a * 0.5).sin();
105105
let rb: f32 = 1.0 - (a * 0.5).sin();
106106
dec[0] = vec3(0.0, 0.0, -1.0 / ra);

shaders/src/shaders/apollonian.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl State {
180180
}
181181
}
182182

183-
tot = tot / (AA * AA) as f32;
183+
tot /= (AA * AA) as f32;
184184

185185
*frag_color = tot.extend(1.0);
186186
}

shaders/src/shaders/atmosphere_system_test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ struct _Plane {
7777

7878
fn rotate_around_x(angle_degrees: f32) -> Mat3 {
7979
let angle: f32 = angle_degrees.to_radians();
80-
let _sin: f32 = angle.sin();
81-
let _cos: f32 = angle.cos();
82-
Mat3::from_cols_array(&[1.0, 0.0, 0.0, 0.0, _cos, -_sin, 0.0, _sin, _cos])
80+
let sin: f32 = angle.sin();
81+
let cos: f32 = angle.cos();
82+
Mat3::from_cols_array(&[1.0, 0.0, 0.0, 0.0, cos, -sin, 0.0, sin, cos])
8383
}
8484

85-
fn get_primary_ray(cam_local_point: Vec3, cam_origin: &mut Vec3, cam_look_at: &mut Vec3) -> Ray {
85+
fn get_primary_ray(cam_local_point: Vec3, cam_origin: &Vec3, cam_look_at: &Vec3) -> Ray {
8686
let fwd: Vec3 = (*cam_look_at - *cam_origin).normalize();
8787
let mut up: Vec3 = vec3(0.0, 1.0, 0.0);
8888
let right: Vec3 = up.cross(fwd);
@@ -94,7 +94,7 @@ fn get_primary_ray(cam_local_point: Vec3, cam_origin: &mut Vec3, cam_look_at: &m
9494
}
9595
}
9696

97-
fn isect_sphere(ray: Ray, sphere: Sphere, t0: &mut f32, t1: &mut f32) -> bool {
97+
fn isect_sphere(ray: Ray, sphere: &Sphere, t0: &mut f32, t1: &mut f32) -> bool {
9898
let rc: Vec3 = sphere.origin - ray.origin;
9999
let radius2: f32 = sphere.radius * sphere.radius;
100100
let tca: f32 = rc.dot(ray.direction);
@@ -160,7 +160,7 @@ const NUM_SAMPLES_LIGHT: i32 = 8;
160160
fn get_sun_light(ray: Ray, optical_depth_r: &mut f32, optical_depth_m: &mut f32) -> bool {
161161
let mut t0: f32 = 0.0;
162162
let mut t1: f32 = 0.0;
163-
isect_sphere(ray, ATMOSPHERE, &mut t0, &mut t1);
163+
isect_sphere(ray, &ATMOSPHERE, &mut t0, &mut t1);
164164

165165
let mut march_pos: f32 = 0.0;
166166
let march_step: f32 = t1 / NUM_SAMPLES_LIGHT as f32;
@@ -185,7 +185,7 @@ impl State {
185185
// "pierce" the atmosphere with the viewing ray
186186
let mut t0: f32 = 0.0;
187187
let mut t1: f32 = 0.0;
188-
if !isect_sphere(ray, ATMOSPHERE, &mut t0, &mut t1) {
188+
if !isect_sphere(ray, &ATMOSPHERE, &mut t0, &mut t1) {
189189
return Vec3::ZERO;
190190
}
191191

@@ -286,10 +286,10 @@ impl State {
286286

287287
col = self.get_incident_light(ray);
288288
} else {
289-
let mut eye: Vec3 = vec3(0.0, EARTH_RADIUS + 1.0, 0.0);
290-
let mut look_at: Vec3 = vec3(0.0, EARTH_RADIUS + 1.5, -1.0);
289+
let eye: Vec3 = vec3(0.0, EARTH_RADIUS + 1.0, 0.0);
290+
let look_at: Vec3 = vec3(0.0, EARTH_RADIUS + 1.5, -1.0);
291291

292-
let ray: Ray = get_primary_ray(point_cam, &mut eye, &mut look_at);
292+
let ray: Ray = get_primary_ray(point_cam, &eye, &look_at);
293293

294294
if ray.direction.dot(vec3(0.0, 1.0, 0.0)) > 0.0 {
295295
col = self.get_incident_light(ray);

shaders/src/shaders/bubble_buckey_balls.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ impl<C0, C1> State<C0, C1> {
6969
// **************************************************************************
7070
// CONSTANTS
7171

72-
const PI: f32 = 3.14159;
73-
const TWO_PI: f32 = 6.28318;
74-
const _PI_OVER_TWO: f32 = 1.570796;
75-
const ONE_OVER_PI: f32 = 0.318310;
7672
const GR: f32 = 1.61803398;
7773

7874
const SMALL_FLOAT: f32 = 0.0001;
@@ -94,11 +90,11 @@ const BOND_MATL: f32 = 3.0;
9490
// Range of outputs := ([-1.,-1.,-1.] -> [1.,1.,1.])
9591

9692
fn rotate_around_y_axis(point: Vec3, cosangle: f32, sinangle: f32) -> Vec3 {
97-
return vec3(
93+
vec3(
9894
point.x * cosangle + point.z * sinangle,
9995
point.y,
10096
point.x * -sinangle + point.z * cosangle,
101-
);
97+
)
10298
}
10399

104100
// Rotate the input point around the x-axis by the angle given as a
@@ -129,9 +125,9 @@ fn _cartesian_to_polar(p: Vec3) -> Vec2 {
129125

130126
fn mergeobjs(a: Vec2, b: Vec2) -> Vec2 {
131127
if a.x < b.x {
132-
return a;
128+
a
133129
} else {
134-
return b;
130+
b
135131
}
136132

137133
// XXX: Some architectures have bad optimization paths
@@ -152,7 +148,7 @@ fn segmentdf(p: Vec3, a: Vec3, b: Vec3, r: f32) -> f32 {
152148
let ba: Vec3 = b - a;
153149
let mut t: f32 = ba.dot(p - a) / SMALL_FLOAT.max(ba.dot(ba));
154150
t = t.clamp(0., 1.);
155-
return (ba * t + a - p).length() - r;
151+
(ba * t + a - p).length() - r
156152
}
157153

158154
// **************************************************************************
@@ -277,7 +273,7 @@ impl<C0, C1> State<C0, C1> {
277273
if t > maxd {
278274
material = -1.0;
279275
}
280-
return vec2(t, material);
276+
vec2(t, material)
281277
}
282278
}
283279

@@ -341,7 +337,7 @@ impl<C0, C1> State<C0, C1> {
341337
let cosrotx: f32 = rotx.cos();
342338
let sinrotx: f32 = rotx.sin();
343339

344-
let roty: f32 = TWO_PI * click.x + 0.05 * self.time;
340+
let roty: f32 = TAU * click.x + 0.05 * self.time;
345341
let cosroty: f32 = roty.cos();
346342
let sinroty: f32 = roty.sin();
347343

@@ -465,10 +461,10 @@ impl<C0: SampleCube, C1: SampleCube> State<C0, C1> {
465461
if ndl > 0. {
466462
let frk: f32 = 0.5 + 2.0 * costd * costd * surf.roughness;
467463
let diff: Vec3 = surf.basecolor
468-
* ONE_OVER_PI
464+
* FRAC_1_PI
469465
* (1. + (frk - 1.) * pow5(1. - costl))
470466
* (1. + (frk - 1.) * pow5(1. - costv));
471-
//let diff: Vec3 = surf.basecolor * ONE_OVER_PI; // lambert
467+
//let diff: Vec3 = surf.basecolor * FRAC_1_PI; // lambert
472468

473469
// D(h) factor
474470
// using the GGX approximation where the gamma factor is 2.

shaders/src/shaders/filtering_procedurals.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,12 @@ impl Inputs {
411411
ddy_uvw = uvw + uvw.dfdy();
412412
}
413413
// shading
414-
let mate: Vec3;
415414

416-
if p.x > th {
417-
mate = sample_texture(uvw, nor, mid);
415+
let mate = if p.x > th {
416+
sample_texture(uvw, nor, mid)
418417
} else {
419-
mate = sample_texture_with_filter(uvw, ddx_uvw, ddy_uvw, nor, mid);
420-
}
418+
sample_texture_with_filter(uvw, ddx_uvw, ddy_uvw, nor, mid)
419+
};
421420

422421
// lighting
423422
let lin: Vec3 = do_lighting(pos, nor, occ, rd);

shaders/src/shaders/flappy_bird.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const PIPE_BOTTOM: f32 = 39.0; // px
102102
const PIPE_HOLE_HEIGHT: f32 = 12.0; // px
103103

104104
// const PIPE_OUTLINE_COLOR: Vec4 = RGB(84, 56, 71);
105-
const PIPE_OUTLINE_COLOR: Vec4 = vec4(84 as f32 / 255.0, 56 as f32 / 255.0, 71 as f32 / 255.0, 1.0);
105+
const PIPE_OUTLINE_COLOR: Vec4 = vec4(84.0 / 255.0, 56.0 / 255.0, 71.0 / 255.0, 1.0);
106106

107107
// gameplay consts
108108
const HORZ_PIPE_DISTANCE: f32 = 100.0; // px;
@@ -1237,7 +1237,7 @@ impl State {
12371237
}
12381238
}
12391239

1240-
pub fn main_image(&mut self, frag_color: &mut Vec4, frag_coord: Vec2) {
1240+
fn main_image(&mut self, frag_color: &mut Vec4, frag_coord: Vec2) {
12411241
let level_pixel: Vec2 = self.get_level_pixel(frag_coord);
12421242

12431243
self.frag_color = rgb(113, 197, 207); // draw the blue sky background

shaders/src/shaders/geodesic_tiling.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ fn p_r(p: &mut Vec2, a: f32) {
8686
fn p_reflect(p: &mut Vec3, plane_normal: Vec3, offset: f32) -> f32 {
8787
let t: f32 = p.dot(plane_normal) + offset;
8888
if t < 0.0 {
89-
*p = *p - (2. * t) * plane_normal;
89+
*p -= (2. * t) * plane_normal;
9090
}
9191
t.sign_gl()
9292
}
9393

9494
fn smax(a: f32, b: f32, r: f32) -> f32 {
9595
let m: f32 = a.max(b);
9696
if (-a < r) && (-b < r) {
97+
#[expect(
98+
clippy::imprecise_flops,
99+
reason = "Rust GPU does not yet support hypot from libm"
100+
)]
97101
m.max(-(r - ((r + a) * (r + a) + (r + b) * (r + b)).sqrt()))
98102
} else {
99103
m
@@ -141,14 +145,10 @@ impl State {
141145
// Adapted from mattz https://www.shadertoy.com/view/4d2GzV
142146
// --------------------------------------------------------
143147

144-
const SQRT3: f32 = 1.7320508075688772;
145148
const I3: f32 = 0.5773502691896258;
146149

147150
const CART2HEX: Mat2 = mat2(vec2(1.0, 0.0), vec2(I3, 2.0 * I3));
148-
const HEX2CART: Mat2 = mat2(vec2(1.0, 0.0), vec2(-0.5, 0.5 * SQRT3));
149-
150-
const _PHI: f32 = 1.618033988749895;
151-
const _TAU: f32 = 6.283185307179586;
151+
const HEX2CART: Mat2 = mat2(vec2(1.0, 0.0), vec2(-0.5, 0.5 * SQRT_3));
152152

153153
struct TriPoints {
154154
a: Vec2,
@@ -272,7 +272,7 @@ impl State {
272272
// --------------------------------------------------------
273273

274274
fn pal(t: f32, a: Vec3, b: Vec3, c: Vec3, d: Vec3) -> Vec3 {
275-
a + b * (6.28318 * (c * t + d)).cos()
275+
a + b * (TAU * (c * t + d)).cos()
276276
}
277277

278278
fn spectrum(n: f32) -> Vec3 {
@@ -307,11 +307,9 @@ impl State {
307307
xy.y = mouse.y;
308308
}
309309
}
310-
let rx: f32;
311-
let ry: f32;
312310

313-
rx = (xy.y + 0.5) * PI;
314-
ry = (-xy.x) * 2.0 * PI;
311+
let rx = (xy.y + 0.5) * PI;
312+
let ry = (-xy.x) * 2.0 * PI;
315313

316314
spherical_matrix(rx, ry)
317315
}

shaders/src/shaders/heart.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ struct Inputs {
2929
impl Inputs {
3030
fn main_image(&self, frag_color: &mut Vec4, frag_coord: Vec2) {
3131
let mut p: Vec2 =
32-
(2.0 * frag_coord - self.resolution.xy()) / (self.resolution.y.min(self.resolution.x));
32+
(2.0 * frag_coord - self.resolution.xy()) / (self.resolution.xy().min_element());
3333

3434
// background color
3535
let bcol: Vec3 = vec3(1.0, 0.8, 0.7 - 0.07 * p.y) * (1.0 - 0.25 * p.length());
3636

3737
// animate
3838
let tt: f32 = self.time.rem_euclid(1.5) / 1.5;
3939
let mut ss: f32 = tt.powf(0.2) * 0.5 + 0.5;
40-
ss = 1.0 + ss * 0.5 * (tt * 6.2831 * 3.0 + p.y * 0.5).sin() * (-tt * 4.0).exp();
40+
ss = 1.0 + ss * 0.5 * (tt * TAU * 3.0 + p.y * 0.5).sin() * (-tt * 4.0).exp();
4141
p *= vec2(0.5, 1.5) + ss * vec2(0.5, -0.5);
4242

4343
// shape
@@ -51,7 +51,7 @@ impl Inputs {
5151
d = 0.5;
5252
} else {
5353
p.y -= 0.25;
54-
let a: f32 = p.x.atan2(p.y) / 3.141593;
54+
let a: f32 = p.x.atan2(p.y) / PI;
5555
r = p.length();
5656
let h: f32 = a.abs();
5757
d = (13.0 * h - 22.0 * h * h + 10.0 * h * h * h) / (6.0 - 5.0 * h);

shaders/src/shaders/luminescence.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ const _LF: Vec3 = vec3(1.0, 0.0, 0.0);
9393
const UP: Vec3 = vec3(0.0, 1.0, 0.0);
9494
const _FW: Vec3 = vec3(0.0, 0.0, 1.0);
9595

96-
const _HALF_PI: f32 = 1.570796326794896619;
97-
const PI: f32 = 3.141592653589793238;
98-
const TWO_PI: f32 = 6.283185307179586;
99-
10096
const ACCENT_COLOR1: Vec3 = vec3(1.0, 0.1, 0.5);
10197
const SECOND_COLOR1: Vec3 = vec3(0.1, 0.5, 1.0);
10298
const ACCENT_COLOR2: Vec3 = vec3(1.0, 0.5, 0.1);
@@ -110,7 +106,7 @@ fn _n2(x: f32, y: f32) -> f32 {
110106
}
111107

112108
fn n3(mut p: Vec3) -> f32 {
113-
p = (p * 0.3183099 + Vec3::splat(0.1)).fract_gl();
109+
p = (p * FRAC_1_PI + Vec3::splat(0.1)).fract_gl();
114110
p *= 17.0;
115111
(p.x * p.y * p.z * (p.x + p.y + p.z)).fract_gl()
116112
}
@@ -215,7 +211,7 @@ fn sd_sphere(p: Vec3, pos: Vec3, s: f32) -> f32 {
215211

216212
// From http://mercury.sexy/hg_sdf
217213
fn p_mod_polar(p: &mut Vec2, repetitions: f32, fix: f32) -> Vec2 {
218-
let angle: f32 = TWO_PI / repetitions;
214+
let angle: f32 = TAU / repetitions;
219215
let mut a: f32 = p.y.atan2(p.x) + angle / 2.;
220216
let r: f32 = p.length();
221217
let _c: f32 = (a / angle).floor();
@@ -332,14 +328,13 @@ impl State {
332328
let n: f32 = n3(id);
333329

334330
let mut o: De = De::default();
335-
o.m = 0.0;
336331

337-
let mut x: f32 = (p.y + n * TWO_PI) * 1. + t;
332+
let mut x: f32 = (p.y + n * TAU) * 1. + t;
338333
let r: f32 = 1.;
339334

340335
let pump: f32 = (x + x.cos()).cos() + (2.0 * x).sin() * 0.2 + (4.0 * x).sin() * 0.02;
341336

342-
x = t + n * TWO_PI;
337+
x = t + n * TAU;
343338
p.y -= ((x + x.cos()).cos() + (2.0 * x).sin() * 0.2) * 0.6;
344339
p = (p.xz() * (1.0 + pump * 0.2)).extend(p.y).xzy();
345340

@@ -350,7 +345,7 @@ impl State {
350345
o.m = 1.0;
351346

352347
if p.y < 0.5 {
353-
let sway: f32 = (t + p.y + n * TWO_PI).sin() * smoothstep(0.5, -3.0, p.y) * n * 0.3;
348+
let sway: f32 = (t + p.y + n * TAU).sin() * smoothstep(0.5, -3.0, p.y) * n * 0.3;
354349
p.x += sway * n; // add some sway to the tentacles
355350
p.z += sway * (1. - n);
356351

@@ -466,21 +461,21 @@ impl State {
466461

467462
p.y *= scale;
468463

469-
let mut s2: f32 = 5. * p.x / TWO_PI;
464+
let mut s2: f32 = 5. * p.x / TAU;
470465
let _id: f32 = s2.floor();
471466
s2 = s2.fract_gl();
472467
let ep: Vec2 = vec2(s2 - 0.5, p.y - 0.6);
473468
let ed: f32 = ep.length();
474469
let e: f32 = b(0.35, 0.45, 0.05, ed);
475470

476-
let mut s: f32 = sin(s2 * TWO_PI * 15.0);
471+
let mut s: f32 = sin(s2 * TAU * 15.0);
477472
s = s * s;
478473
s = s * s;
479-
s *= smoothstep(1.4, -0.3, uv.y - (s2 * TWO_PI).cos() * 0.2 + 0.3)
474+
s *= smoothstep(1.4, -0.3, uv.y - (s2 * TAU).cos() * 0.2 + 0.3)
480475
* smoothstep(-0.6, -0.3, uv.y);
481476

482477
let t: f32 = self.inputs.time * 5.0;
483-
let mask: f32 = sin(p.x * TWO_PI * 2.0 + t);
478+
let mask: f32 = sin(p.x * TAU * 2.0 + t);
484479
s *= mask * mask * 2.0;
485480

486481
s + e * pump * 2.0
@@ -595,7 +590,7 @@ impl State {
595590
self.accent = mix(ACCENT_COLOR1, ACCENT_COLOR2, sin(t * 15.456));
596591
self.bg = mix(SECOND_COLOR1, SECOND_COLOR2, sin(t * 7.345231));
597592

598-
let turn: f32 = (0.1 - m.x) * TWO_PI;
593+
let turn: f32 = (0.1 - m.x) * TAU;
599594
let s: f32 = turn.sin();
600595
let c: f32 = turn.cos();
601596
let rot_x: Mat3 = Mat3::from_cols_array(&[c, 0.0, s, 0.0, 1.0, 0.0, s, 0.0, -c]);

shaders/src/shaders/mandelbrot_smooth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Inputs {
6969
// equivalent optimized smooth interation count
7070
let sl: f32 = l - z.dot(z).log2().log2() + 4.0;
7171

72-
let al: f32 = smoothstep(-0.1, 0.0, (self.time * 0.5 * 6.2831).sin());
72+
let al: f32 = smoothstep(-0.1, 0.0, (self.time * 0.5 * TAU).sin());
7373
mix(l, sl, al)
7474
}
7575

0 commit comments

Comments
 (0)