Skip to content

Commit

Permalink
Rename Geometric to Geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed Jul 12, 2024
1 parent ae57ada commit c230961
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions geometry/src/bound.rs
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
26 changes: 13 additions & 13 deletions geometry/src/geometric.rs → geometry/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RayIntersection> {
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<Aabb> {
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<Triangle> for Geometric {
impl From<Triangle> 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))
}
}
2 changes: 1 addition & 1 deletion geometry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions kdtree-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -180,7 +180,7 @@ fn main() {
.into()
})
})
.collect::<Vec<Geometric>>();
.collect::<Vec<Geometry>>();
eprintln!(" Triangles: {}", triangles.len());

eprintln!("Building kdtree...");
Expand Down
14 changes: 7 additions & 7 deletions kdtree-reducer-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Geometric>) -> kdtree::KdTree {
fn build_test_tree(geometries: Vec<Geometry>) -> kdtree::KdTree {
build_kdtree(
SahKdTreeBuilder {
traverse_cost: 2.0,
Expand All @@ -23,7 +23,7 @@ fn build_test_tree(geometries: Vec<Geometric>) -> 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;
Expand All @@ -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<Vec<Geometric>> {
) -> Option<Vec<Geometry>> {
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..]);
Expand All @@ -46,7 +46,7 @@ fn try_removing(

fn reduce_tree(
ray: &Ray,
geometries: Vec<Geometric>,
geometries: Vec<Geometry>,
expected_intersection: &(usize, RayIntersection),
actual_intersection: &(usize, RayIntersection),
) -> KdTree {
Expand Down
4 changes: 2 additions & 2 deletions kdtree/src/build_sah.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,7 +15,7 @@ pub struct SahKdTreeBuilder {
pub traverse_cost: f32,
pub intersect_cost: f32,
pub empty_factor: f32,
pub geometries: Vec<Geometric>,
pub geometries: Vec<Geometry>,
}

pub const MAX_DEPTH: u32 = 20;
Expand Down
8 changes: 4 additions & 4 deletions kdtree/src/format.rs
Original file line number Diff line number Diff line change
@@ -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<W>(write: &mut W, geometries: &[Geometric]) -> Result<(), io::Error>
fn write_triangle_bracketed<W>(write: &mut W, geometries: &[Geometry]) -> Result<(), io::Error>
where
W: io::Write,
{
Expand All @@ -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::<Vec<_>>()
)
Expand Down
8 changes: 4 additions & 4 deletions kdtree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<f32>,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl KdNode {

pub fn intersect(
&self,
geometries: &[Geometric],
geometries: &[Geometry],
ray: &Ray,
t_range: RangeInclusive<f32>,
) -> Option<(u32, RayIntersection)> {
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<'a> Iterator for KdTreeNodeIter<'a> {

pub struct KdTree {
pub root: Box<KdNode>,
pub geometries: Vec<Geometric>,
pub geometries: Vec<Geometry>,
}

impl KdTree {
Expand Down
4 changes: 2 additions & 2 deletions kdtree/src/split.rs
Original file line number Diff line number Diff line change
@@ -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| {
Expand Down

0 comments on commit c230961

Please sign in to comment.