Skip to content

Commit

Permalink
refactor: simplify lifetime annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther committed Dec 20, 2024
1 parent e394a75 commit 80b09f9
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion clovers-cli/src/sampler/blue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl BlueSampler {
}
}

impl<'scene> SamplerTrait<'scene> for BlueSampler {
impl SamplerTrait<'_> for BlueSampler {
fn sample(&mut self, i: i32, j: i32, index: i32) -> Randomness {
let pixel_offset = Vec2::new(
(self.get)(i, j, index, SamplerDimension::PixelOffsetX),
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/bvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Display for BvhAlgorithm {
}
}

impl<'scene> BVHNode<'scene> {
impl BVHNode<'_> {
/// Create a new `BVHNode` tree from a given list of [Object](crate::objects::Object)s
#[must_use]
pub fn from_list(bvh_algorithm: BvhAlgorithm, hitables: Vec<Hitable>) -> BVHNode {
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/bvh/hitable_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{

use super::BVHNode;

impl<'scene> HitableTrait for BVHNode<'scene> {
impl HitableTrait for BVHNode<'_> {
/// The main `hit` function for a [`BVHNode`]. Given a [Ray], and an interval `distance_min` and `distance_max`, returns either `None` or `Some(HitRecord)` based on whether the ray intersects with the encased objects during that interval.
#[must_use]
fn hit(
Expand Down
4 changes: 2 additions & 2 deletions clovers/src/bvh/testcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use crate::{

use super::BVHNode;

impl<'scene> BVHNode<'scene> {
impl BVHNode<'_> {
// NOTE: this must be kept in close alignment with the implementation of BVHNode::hit()!
// TODO: maybe move the statistics counting to the method itself? Measure the impact?
/// Alternate hit method that maintains a test count for the BVH traversals.
pub fn testcount(
&'scene self,
&self,
depth: &mut usize,
ray: &Ray,
distance_min: Float,
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/hitable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'scene> HitableList<'scene> {
}

// TODO: ideally, this impl should be removed entirely
impl<'scene> HitableTrait for HitableList<'scene> {
impl HitableTrait for HitableList<'_> {
#[must_use]
fn hit(
&self,
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/hitrecord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct HitRecord<'a> {
pub front_face: bool,
}

impl<'a> HitRecord<'a> {
impl HitRecord<'_> {
/// Sets the face normal of this [`HitRecord`].
pub fn set_face_normal(&mut self, ray: &Ray, outward_normal: Direction) {
self.front_face = ray.direction.dot(&outward_normal) < 0.0;
Expand Down
6 changes: 3 additions & 3 deletions clovers/src/materials/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct GLTFMaterial<'scene> {
bitangents: Option<[Vec3; 3]>,
}

impl<'scene> Default for GLTFMaterial<'scene> {
impl Default for GLTFMaterial<'_> {
fn default() -> Self {
todo!()
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl<'scene> GLTFMaterial<'scene> {
}
}

impl<'scene> MaterialTrait for GLTFMaterial<'scene> {
impl MaterialTrait for GLTFMaterial<'_> {
fn scatter(
&self,
ray: &Ray,
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'scene> MaterialTrait for GLTFMaterial<'scene> {
}
}

impl<'scene> GLTFMaterial<'scene> {
impl GLTFMaterial<'_> {
fn sample_base_color(&self, hit_record: &HitRecord) -> LinSrgb {
let base_color_texture = self
.material
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn object_to_hitable(obj: Object, materials: &[SharedMaterial]) -> Hitable<'
fn initialize_material<'scene>(
material_init: MaterialInit,
materials: &'scene [SharedMaterial],
) -> &Material {
) -> &'scene Material {
let material: &Material = match material_init {
MaterialInit::Owned(m) => {
// TODO: do not leak memory
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/boxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'scene> Boxy<'scene> {
}
}

impl<'scene> HitableTrait for Boxy<'scene> {
impl HitableTrait for Boxy<'_> {
/// The main `hit` function for a [Boxy]. Given a [Ray], and an interval `distance_min` and `distance_max`, returns either `None` or `Some(HitRecord)` based on whether the ray intersects with the object during that interval.
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/constant_medium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'scene> ConstantMedium<'scene> {
}
}

impl<'scene> HitableTrait for ConstantMedium<'scene> {
impl HitableTrait for ConstantMedium<'_> {
/// Hit function for the [`ConstantMedium`] object. Returns a [`HitRecord`] if hit. TODO: explain the math for the fog
#[must_use]
fn hit(
Expand Down
4 changes: 2 additions & 2 deletions clovers/src/objects/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct GLTF<'scene> {
pub aabb: AABB,
}

impl<'scene> GLTF<'scene> {
impl GLTF<'_> {
#[must_use]
/// Create a new STL object with the given initialization parameters.
///
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'scene> GLTFTriangle<'scene> {
}
}

impl<'scene> HitableTrait for GLTFTriangle<'scene> {
impl HitableTrait for GLTFTriangle<'_> {
fn hit(
&self,
ray: &Ray,
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/moving_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'scene> MovingSphere<'scene> {
}
}

impl<'scene> HitableTrait for MovingSphere<'scene> {
impl HitableTrait for MovingSphere<'_> {
/// Hit method for the [`MovingSphere`] object. First gets the interpolated center position at the given time, then follows the implementation of [Sphere](crate::objects::Sphere) object's hit method.
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'scene> Quad<'scene> {
}
}

impl<'scene> HitableTrait for Quad<'scene> {
impl HitableTrait for Quad<'_> {
/// Hit method for the quad rectangle
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'scene> RotateY<'scene> {
}
}

impl<'scene> HitableTrait for RotateY<'scene> {
impl HitableTrait for RotateY<'_> {
/// Hit method for the [`RotateY`] object. Finds the rotation-adjusted [`HitRecord`] for the possible intersection of the [Ray] with the encased [Object].
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'scene> Sphere<'scene> {
}
}

impl<'scene> HitableTrait for Sphere<'scene> {
impl HitableTrait for Sphere<'_> {
/// Hit method for the [Sphere] object. Returns a [`HitRecord`] if the given [Ray] intersects with the sphere at the given distance interval.
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'scene> Translate<'scene> {
}
}

impl<'scene> HitableTrait for Translate<'scene> {
impl HitableTrait for Translate<'_> {
/// Hit method for the [Translate] object. Finds the translation-adjusted [`HitRecord`] for the possible intersection of the [Ray] with the encased [Object].
#[must_use]
fn hit(
Expand Down
2 changes: 1 addition & 1 deletion clovers/src/objects/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'scene> Triangle<'scene> {
}
}

impl<'scene> HitableTrait for Triangle<'scene> {
impl HitableTrait for Triangle<'_> {
/// Hit method for the triangle
#[must_use]
fn hit(
Expand Down
4 changes: 2 additions & 2 deletions clovers/src/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'scene> HitablePDF<'scene> {
}
}

impl<'scene> PDFTrait for HitablePDF<'scene> {
impl PDFTrait for HitablePDF<'_> {
#[must_use]
fn value(
&self,
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'scene> MixturePDF<'scene> {
}
}

impl<'scene> PDFTrait for MixturePDF<'scene> {
impl PDFTrait for MixturePDF<'_> {
#[must_use]
fn value(
&self,
Expand Down

0 comments on commit 80b09f9

Please sign in to comment.