-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::{fmt::{Display, Formatter, self}, ops::Index}; | ||
|
||
use crate::linalg::Vec3; | ||
|
||
|
||
/// An `Axis` in a three-dimensional coordinate system. | ||
/// Used to access `Vec3` structs via index. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// use raytracer::render::Axis; | ||
/// use raytracer::linalg::Vec3; | ||
/// | ||
/// let mut vec = Vec3::new(1.0, 0.5, 42.0); | ||
/// | ||
/// assert_eq!(vec[Axis::Y], 0.5); | ||
/// ``` | ||
/// | ||
/// [`Vec3`] is also indexable using `Axis`. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
pub enum Axis { | ||
/// Index of the X axis. | ||
X = 0, | ||
|
||
/// Index of the Y axis. | ||
Y = 1, | ||
|
||
/// Index of the Z axis. | ||
Z = 2, | ||
} | ||
|
||
/// Display implementation for `Axis`. | ||
impl Display for Axis { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
match *self { | ||
Axis::X => "x", | ||
Axis::Y => "y", | ||
Axis::Z => "z", | ||
} | ||
) | ||
} | ||
} | ||
|
||
/// Make `Vector3` indexable by `Axis`. | ||
impl Index<Axis> for Vec3 { | ||
type Output = f64; | ||
|
||
fn index(&self, axis: Axis) -> &f64 { | ||
match axis { | ||
Axis::X => &self.x, | ||
Axis::Y => &self.y, | ||
Axis::Z => &self.z, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ pub use interval::Interval; | |
mod color; | ||
pub use color::Color; | ||
pub use color::Rgb; | ||
|
||
mod axis; | ||
pub use axis::Axis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters