Skip to content

Commit

Permalink
Remove overly liberal uses of derive(Copy)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed Aug 6, 2024
1 parent 9303c9c commit 047941f
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion geometry/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use glam::Vec3;

use super::aap::Aap;

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Aabb {
min: Vec3,
max: Vec3,
Expand Down
2 changes: 1 addition & 1 deletion geometry/src/aap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ray::Ray;

use super::axis::Axis;

#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct Aap {
pub axis: Axis,
pub distance: f32,
Expand Down
12 changes: 6 additions & 6 deletions geometry/src/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn clip_triangle_aabb(v0: &Vec3, v1: &Vec3, v2: &Vec3, aabb: &Aabb) -> Array
(true, Aap::new_z(aabb_max.z)),
];

let is_inside = |clip_plane: (bool, Aap), point: Vec3| {
let is_inside = |clip_plane: &(bool, Aap), point: Vec3| {
if clip_plane.0 {
point[clip_plane.1.axis] <= clip_plane.1.distance
} else {
Expand All @@ -31,7 +31,7 @@ pub fn clip_triangle_aabb(v0: &Vec3, v1: &Vec3, v2: &Vec3, aabb: &Aabb) -> Array
output.push(*v2);
output.push(*v0);

for clip_plane @ (_, plane) in clip_planes {
for clip_plane in clip_planes {
if output.is_empty() {
return output;
}
Expand All @@ -40,13 +40,13 @@ pub fn clip_triangle_aabb(v0: &Vec3, v1: &Vec3, v2: &Vec3, aabb: &Aabb) -> Array
let points_iter = input.iter().cycle().skip(input.len() - 1).zip(input.iter());
for (a, b) in points_iter {
let ray = Ray::between(*a, *b);
let intersecting = plane.intersect_ray_point(&ray);
if is_inside(clip_plane, *b) {
if !is_inside(clip_plane, *a) {
let intersecting = clip_plane.1.intersect_ray_point(&ray);
if is_inside(&clip_plane, *b) {
if !is_inside(&clip_plane, *a) {
output.push(intersecting.unwrap());
}
output.push(*b);
} else if is_inside(clip_plane, *a) {
} else if is_inside(&clip_plane, *a) {
output.push(intersecting.unwrap());
}
}
Expand Down
4 changes: 2 additions & 2 deletions geometry/src/intersection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct PointIntersection {
pub u: f32,
pub v: f32,
Expand All @@ -18,7 +18,7 @@ impl PointIntersection {
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct RayIntersection {
pub t: f32,
pub u: f32,
Expand Down
2 changes: 1 addition & 1 deletion geometry/src/ray.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use glam::Vec3;

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct Ray {
pub origin: Vec3,
pub direction: Vec3,
Expand Down
4 changes: 2 additions & 2 deletions geometry/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
clip::clip_triangle_aabb, intersection::RayIntersection, ray::Ray,
};

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Triangle {
pub v0: Vec3,
pub v1: Vec3,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Triangle {
}

#[inline]
pub fn as_arrays(self) -> [[f32; 3]; 3] {
pub fn as_arrays(&self) -> [[f32; 3]; 3] {
[self.v0.into(), self.v1.into(), self.v2.into()]
}

Expand Down
15 changes: 8 additions & 7 deletions kdtree-tester/src/bin/kdtree-reducer-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ fn try_removing(

fn reduce_tree(
seed: u64,
intersection: &CheckedIntersection,
intersection: CheckedIntersection,
geometries: Vec<Geometry>,
) -> (Vec<Geometry>, KdNode) {
let actual_intersection = intersection.kdtree.as_ref().unwrap();
let actual_geometry = geometries[actual_intersection.index as usize].clone();
let actual = (actual_geometry, actual_intersection.intersection);
let actual = (
geometries[intersection.kdtree.as_ref().unwrap().index as usize].clone(),
intersection.kdtree.as_ref().unwrap().intersection.clone(),
);
let mut geometries = geometries;
geometries.swap(0, intersection.reference.as_ref().unwrap().index as usize);
geometries.swap(1, intersection.kdtree.as_ref().unwrap().index as usize);
geometries.swap(0, intersection.reference.unwrap().index as usize);
geometries.swap(1, intersection.kdtree.unwrap().index as usize);
geometries[2..].shuffle(&mut SmallRng::seed_from_u64(seed));
let mut try_index: usize = 2;
let mut try_count = geometries.len() - try_index;
Expand Down Expand Up @@ -189,7 +190,7 @@ fn main() {
}

eprintln!("Reducing tree...");
let (geometries, tree) = reduce_tree(args.seed, &intersection, geometries);
let (geometries, tree) = reduce_tree(args.seed, intersection, geometries);

eprintln!("Writing reduced tree to {:?}...", args.output);
write_tree_json(
Expand Down
6 changes: 3 additions & 3 deletions kdtree-tester/src/checked_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl CheckedIntersection {
pub fn as_bytes(&self, iteration: u16) -> [u8; 50] {
let mut bytes = [0u8; 50];
let ray = if let Some(kdtree) = &self.kdtree {
self.ray.extended(kdtree.intersection.t)
&self.ray.extended(kdtree.intersection.t)
} else if let Some(reference) = &self.reference {
self.ray.extended(reference.intersection.t)
&self.ray.extended(reference.intersection.t)
} else {
self.ray
&self.ray
};
let correct_point = self
.ray
Expand Down
2 changes: 1 addition & 1 deletion kdtree-tester/src/ray_bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl RayBouncer {
.intersect(&self.scene.geometries, ray, t_range.clone());
let reference = self.reference_ray_intersect(ray, t_range);
CheckedIntersection {
ray: *ray,
ray: ray.clone(),
reference,
kdtree,
}
Expand Down
4 changes: 2 additions & 2 deletions kdtree/src/sah.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) fn find_best_split(
.filter_map(|plane| {
calculate_cost(
cost,
split_and_partition_clipped_geometries(&clipped, cell.boundary, plane),
split_and_partition_clipped_geometries(&clipped, cell.boundary.clone(), plane),
)
})
.reduce(min_by_snd)
Expand All @@ -109,7 +109,7 @@ pub(crate) fn find_best_split(
.filter_map(|plane| {
calculate_cost(
cost,
split_and_partition_clipped_geometries(&clipped, cell.boundary, plane),
split_and_partition_clipped_geometries(&clipped, cell.boundary.clone(), plane),
)
})
.reduce_with(min_by_snd)
Expand Down
4 changes: 2 additions & 2 deletions scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
},
};

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
struct TriangleNormals {
n0: Vec3,
n1: Vec3,
Expand All @@ -29,7 +29,7 @@ impl TriangleNormals {
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
struct TriangleTexcoords {
uv0: Vec2,
uv1: Vec2,
Expand Down

0 comments on commit 047941f

Please sign in to comment.