Skip to content

Commit

Permalink
Move macros to their own module
Browse files Browse the repository at this point in the history
And use $crate to avoid having to import dependencies
  • Loading branch information
banga committed Jan 26, 2024
1 parent bcc347b commit 5ac03cd
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/bin/analyze_obj.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env::args;

use craytracer::{bounds::Bounds, geometry::point::Point, p};
use craytracer::{bounds::Bounds, p};
use tobj::{Material, Mesh};

fn analyze_obj(file_name: &str) {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sampling.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use craytracer::{
geometry::{normal::Normal, point::Point, vector::Vector},
geometry::vector::Vector,
n, p,
sampling::{
samplers::{IndependentSampler, Sampler, SobolSampler, UniformSampler},
Expand Down
21 changes: 0 additions & 21 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ pub mod vector {
#[derive(Clone, Copy, Debug)]
pub struct Vector(pub f64, pub f64, pub f64);

#[macro_export]
macro_rules! v {
($x:expr, $y:expr, $z:expr) => {
Vector($x as f64, $y as f64, $z as f64)
};
}

impl Vector {
pub fn new(x: i32, y: i32, z: i32) -> Vector {
Vector(x as f64, y as f64, z as f64)
Expand Down Expand Up @@ -225,13 +218,6 @@ pub mod point {
#[derive(Clone, Copy, Debug)]
pub struct Point(pub f64, pub f64, pub f64);

#[macro_export]
macro_rules! p {
($x:expr, $y:expr, $z:expr) => {
Point($x as f64, $y as f64, $z as f64)
};
}

impl Point {
pub fn new(x: i32, y: i32, z: i32) -> Point {
Point(x as f64, y as f64, z as f64)
Expand Down Expand Up @@ -388,13 +374,6 @@ pub mod normal {
#[derive(Clone, Copy, Debug)]
pub struct Normal(pub f64, pub f64, pub f64);

#[macro_export]
macro_rules! n {
($x:expr, $y:expr, $z:expr) => {
Normal($x as f64, $y as f64, $z as f64)
};
}

impl Normal {
pub const X: Normal = n!(1, 0, 0);
pub const Y: Normal = n!(0, 1, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[macro_use]
pub mod macros;
pub mod bounds;
pub mod bsdf;
pub mod bvh;
Expand Down
2 changes: 1 addition & 1 deletion src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use crate::{
color::Color,
constants::EPSILON,
geometry::{normal::Normal, point::Point, vector::Vector},
geometry::{point::Point, vector::Vector},
intersection::PrimitiveIntersection,
n,
pdf::Pdf,
Expand Down
26 changes: 26 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pub use crate::geometry::vector::Vector;

#[macro_export]
macro_rules! v {
($x:expr, $y:expr, $z:expr) => {
$crate::macros::Vector($x as f64, $y as f64, $z as f64)
};
}

pub use crate::geometry::point::Point;

#[macro_export]
macro_rules! p {
($x:expr, $y:expr, $z:expr) => {
$crate::macros::Point($x as f64, $y as f64, $z as f64)
};
}

pub use crate::geometry::normal::Normal;

#[macro_export]
macro_rules! n {
($x:expr, $y:expr, $z:expr) => {
$crate::macros::Normal($x as f64, $y as f64, $z as f64)
};
}
2 changes: 1 addition & 1 deletion tests/test_bvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use craytracer::{
bvh::{Bvh, SplitMethod},
color::Color,
geometry::{point::Point, X},
geometry::X,
material::Material,
p,
primitive::Primitive,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bxdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use approx::assert_abs_diff_eq;

use craytracer::{
bxdf::{reflect, refract},
geometry::{normal::Normal, traits::DotProduct, vector::Vector},
geometry::{traits::DotProduct, vector::Vector},
n, v,
};

Expand Down
4 changes: 1 addition & 3 deletions tests/test_geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
pub mod vector {
use craytracer::{
geometry::{traits::DotProduct, vector::Vector, X, Y, Z},
geometry::{traits::DotProduct, X, Y, Z},
v,
};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -106,8 +106,6 @@ pub mod vector {

#[cfg(test)]
pub mod point {
use craytracer::geometry::point::Point;
use craytracer::geometry::vector::Vector;
use craytracer::{p, v};
use pretty_assertions::assert_eq;

Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ mod parser {
camera::Camera,
color::Color,
film::Film,
geometry::{point::Point, vector::Vector, O, Y},
geometry::{point::Point, O, Y},
light::Light,
material::Material,
p,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod triangle {
use craytracer::{
bounds::Bounds,
constants::EPSILON,
geometry::{normal::Normal, point::Point, vector::Vector, O, Z},
geometry::{point::Point, O, Z},
n, p,
ray::Ray,
shape::Shape,
Expand Down
3 changes: 0 additions & 3 deletions tests/test_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ pub mod matrix {
pub mod transformation {
use approx::assert_abs_diff_eq;
use craytracer::bounds::Bounds;
use craytracer::geometry::normal::Normal;
use craytracer::geometry::point::Point;
use craytracer::geometry::vector::Vector;
use craytracer::geometry::{O, X, Y, Z};
use craytracer::ray::Ray;
use craytracer::transformation::{Transformable, Transformation};
Expand Down

0 comments on commit 5ac03cd

Please sign in to comment.