From c23096140353939de9e0ad9b70d0ef55428cd846 Mon Sep 17 00:00:00 2001 From: Daniel Oom Date: Fri, 12 Jul 2024 12:36:50 +0200 Subject: [PATCH] Rename Geometric to Geometry --- geometry/src/bound.rs | 4 ++-- geometry/src/{geometric.rs => geometry.rs} | 26 +++++++++++----------- geometry/src/lib.rs | 2 +- kdtree-cli/src/main.rs | 4 ++-- kdtree-reducer-cli/src/main.rs | 14 ++++++------ kdtree/src/build_sah.rs | 4 ++-- kdtree/src/format.rs | 8 +++---- kdtree/src/lib.rs | 8 +++---- kdtree/src/split.rs | 4 ++-- 9 files changed, 37 insertions(+), 37 deletions(-) rename geometry/src/{geometric.rs => geometry.rs} (54%) diff --git a/geometry/src/bound.rs b/geometry/src/bound.rs index 3a0eb4e0..1bfb9c0c 100644 --- a/geometry/src/bound.rs +++ b/geometry/src/bound.rs @@ -1,10 +1,10 @@ -use crate::{aabb::Aabb, geometric::Geometric}; +use crate::{aabb::Aabb, geometry::Geometry}; pub fn combine_bounding_boxes(a: &Aabb, b: &Aabb) -> Aabb { Aabb::from_extents(a.min().min(b.min()), a.max().max(b.max())) } -pub fn geometries_bounding_box(geometries: &[Geometric]) -> Aabb { +pub fn geometries_bounding_box(geometries: &[Geometry]) -> Aabb { if geometries.is_empty() { return Aabb::empty(); } diff --git a/geometry/src/geometric.rs b/geometry/src/geometry.rs similarity index 54% rename from geometry/src/geometric.rs rename to geometry/src/geometry.rs index c13b9bae..4866f366 100644 --- a/geometry/src/geometric.rs +++ b/geometry/src/geometry.rs @@ -6,51 +6,51 @@ use crate::{ }; #[derive(Clone, Debug, PartialEq)] -pub enum Geometric { +pub enum Geometry { Triangle(Triangle), AxiallyAlignedTriangle(AxiallyAlignedTriangle), } -impl Geometric { +impl Geometry { #[inline] pub fn min(&self) -> Vec3 { match self { - Geometric::Triangle(t) => t.min(), - Geometric::AxiallyAlignedTriangle(t) => t.min(), + Geometry::Triangle(t) => t.min(), + Geometry::AxiallyAlignedTriangle(t) => t.min(), } } #[inline] pub fn max(&self) -> Vec3 { match self { - Geometric::Triangle(t) => t.max(), - Geometric::AxiallyAlignedTriangle(t) => t.max(), + Geometry::Triangle(t) => t.max(), + Geometry::AxiallyAlignedTriangle(t) => t.max(), } } #[inline] pub fn intersect_ray(&self, ray: &Ray) -> Option { match self { - Geometric::Triangle(t) => t.intersect_ray(ray), - Geometric::AxiallyAlignedTriangle(t) => t.intersect_ray(ray), + Geometry::Triangle(t) => t.intersect_ray(ray), + Geometry::AxiallyAlignedTriangle(t) => t.intersect_ray(ray), } } #[inline] pub fn clip_aabb(&self, aabb: &Aabb) -> Option { match self { - Geometric::Triangle(t) => t.clip_aabb(aabb), - Geometric::AxiallyAlignedTriangle(t) => t.clip_aabb(aabb), + Geometry::Triangle(t) => t.clip_aabb(aabb), + Geometry::AxiallyAlignedTriangle(t) => t.clip_aabb(aabb), } } } -impl From for Geometric { +impl From for Geometry { #[inline] fn from(value: Triangle) -> Self { value .as_axially_aligned() - .map(Geometric::AxiallyAlignedTriangle) - .unwrap_or(Geometric::Triangle(value)) + .map(Geometry::AxiallyAlignedTriangle) + .unwrap_or(Geometry::Triangle(value)) } } diff --git a/geometry/src/lib.rs b/geometry/src/lib.rs index 8995c2bf..8ef028dc 100644 --- a/geometry/src/lib.rs +++ b/geometry/src/lib.rs @@ -4,7 +4,7 @@ pub mod axial_triangle; pub mod axis; pub mod bound; pub mod clip; -pub mod geometric; +pub mod geometry; pub mod intersection; pub mod ray; pub mod sphere; diff --git a/kdtree-cli/src/main.rs b/kdtree-cli/src/main.rs index f666d457..1dba10af 100644 --- a/kdtree-cli/src/main.rs +++ b/kdtree-cli/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; use geometry::{ - aabb::Aabb, bound::geometries_bounding_box, geometric::Geometric, triangle::Triangle, + aabb::Aabb, bound::geometries_bounding_box, geometry::Geometry, triangle::Triangle, }; use kdtree::{ build::build_kdtree, @@ -180,7 +180,7 @@ fn main() { .into() }) }) - .collect::>(); + .collect::>(); eprintln!(" Triangles: {}", triangles.len()); eprintln!("Building kdtree..."); diff --git a/kdtree-reducer-cli/src/main.rs b/kdtree-reducer-cli/src/main.rs index 084c7c97..01eab913 100644 --- a/kdtree-reducer-cli/src/main.rs +++ b/kdtree-reducer-cli/src/main.rs @@ -7,11 +7,11 @@ use std::{ use clap::Parser; use rand::{rngs::SmallRng, seq::SliceRandom, SeedableRng}; -use geometry::{geometric::Geometric, intersection::RayIntersection, ray::Ray, triangle::Triangle}; +use geometry::{geometry::Geometry, intersection::RayIntersection, ray::Ray, triangle::Triangle}; use kdtree::{build::build_kdtree, build_sah::SahKdTreeBuilder, format::write_tree_json, KdTree}; use wavefront::obj; -fn build_test_tree(geometries: Vec) -> kdtree::KdTree { +fn build_test_tree(geometries: Vec) -> kdtree::KdTree { build_kdtree( SahKdTreeBuilder { traverse_cost: 2.0, @@ -23,7 +23,7 @@ fn build_test_tree(geometries: Vec) -> kdtree::KdTree { ) } -fn verify_removal(ray: &Ray, actual: &(Geometric, RayIntersection), tree: &KdTree) -> bool { +fn verify_removal(ray: &Ray, actual: &(Geometry, RayIntersection), tree: &KdTree) -> bool { let intersection = tree.intersect(ray, 0.0..=f32::MAX).unwrap(); let same_geometry = tree.geometries[intersection.0 as usize] == actual.0; let same_intersection = intersection.1 == actual.1; @@ -32,11 +32,11 @@ fn verify_removal(ray: &Ray, actual: &(Geometric, RayIntersection), tree: &KdTre fn try_removing( ray: &Ray, - actual: &(Geometric, RayIntersection), - geometries: &[Geometric], + actual: &(Geometry, RayIntersection), + geometries: &[Geometry], try_index: usize, try_count: usize, -) -> Option> { +) -> Option> { let mut reduced = Vec::with_capacity(geometries.len() - try_count); reduced.extend_from_slice(&geometries[0..try_index]); reduced.extend_from_slice(&geometries[try_index + try_count..]); @@ -46,7 +46,7 @@ fn try_removing( fn reduce_tree( ray: &Ray, - geometries: Vec, + geometries: Vec, expected_intersection: &(usize, RayIntersection), actual_intersection: &(usize, RayIntersection), ) -> KdTree { diff --git a/kdtree/src/build_sah.rs b/kdtree/src/build_sah.rs index 6910158e..1945b0c0 100644 --- a/kdtree/src/build_sah.rs +++ b/kdtree/src/build_sah.rs @@ -1,7 +1,7 @@ use glam::Vec3; use rayon::prelude::*; -use geometry::{aabb::Aabb, aap::Aap, bound::geometries_bounding_box, geometric::Geometric}; +use geometry::{aabb::Aabb, aap::Aap, bound::geometries_bounding_box, geometry::Geometry}; use crate::split::clip_geometries; @@ -15,7 +15,7 @@ pub struct SahKdTreeBuilder { pub traverse_cost: f32, pub intersect_cost: f32, pub empty_factor: f32, - pub geometries: Vec, + pub geometries: Vec, } pub const MAX_DEPTH: u32 = 20; diff --git a/kdtree/src/format.rs b/kdtree/src/format.rs index bc4233ff..3f766bc9 100644 --- a/kdtree/src/format.rs +++ b/kdtree/src/format.rs @@ -1,8 +1,8 @@ use crate::{KdNode, KdTree}; -use geometry::{axis::Axis, geometric::Geometric}; +use geometry::{axis::Axis, geometry::Geometry}; use std::io::{self}; -fn write_triangle_bracketed(write: &mut W, geometries: &[Geometric]) -> Result<(), io::Error> +fn write_triangle_bracketed(write: &mut W, geometries: &[Geometry]) -> Result<(), io::Error> where W: io::Write, { @@ -12,8 +12,8 @@ where geometries .iter() .map(|t| match t { - Geometric::Triangle(t) => t.as_arrays(), - Geometric::AxiallyAlignedTriangle(t) => t.as_arrays(), + Geometry::Triangle(t) => t.as_arrays(), + Geometry::AxiallyAlignedTriangle(t) => t.as_arrays(), }) .collect::>() ) diff --git a/kdtree/src/lib.rs b/kdtree/src/lib.rs index e0108701..e057b191 100644 --- a/kdtree/src/lib.rs +++ b/kdtree/src/lib.rs @@ -1,7 +1,7 @@ use std::{fmt::Display, ops::RangeInclusive}; use arrayvec::ArrayVec; -use geometry::{aap::Aap, geometric::Geometric, intersection::RayIntersection, ray::Ray}; +use geometry::{aap::Aap, geometry::Geometry, intersection::RayIntersection, ray::Ray}; pub mod build; pub mod build_sah; @@ -11,7 +11,7 @@ mod split; pub const MAX_DEPTH: usize = 20; fn intersect_closest( - geometries: &[Geometric], + geometries: &[Geometry], indices: &[u32], ray: &Ray, t_range: RangeInclusive, @@ -66,7 +66,7 @@ impl KdNode { pub fn intersect( &self, - geometries: &[Geometric], + geometries: &[Geometry], ray: &Ray, t_range: RangeInclusive, ) -> Option<(u32, RayIntersection)> { @@ -161,7 +161,7 @@ impl<'a> Iterator for KdTreeNodeIter<'a> { pub struct KdTree { pub root: Box, - pub geometries: Vec, + pub geometries: Vec, } impl KdTree { diff --git a/kdtree/src/split.rs b/kdtree/src/split.rs index 7f635834..869e3c81 100644 --- a/kdtree/src/split.rs +++ b/kdtree/src/split.rs @@ -1,10 +1,10 @@ -use geometry::{aabb::Aabb, aap::Aap, geometric::Geometric}; +use geometry::{aabb::Aabb, aap::Aap, geometry::Geometry}; use crate::build::KdCell; use rayon::iter::{IntoParallelIterator, ParallelIterator}; -pub(crate) fn clip_geometries(geometries: &[Geometric], cell: &KdCell) -> Vec<(u32, Aabb)> { +pub(crate) fn clip_geometries(geometries: &[Geometry], cell: &KdCell) -> Vec<(u32, Aabb)> { cell.indices() .into_par_iter() .filter_map(|i| {