Compare commits
3 Commits
a30a5a383c
...
b159820bad
| Author | SHA1 | Date | |
|---|---|---|---|
| b159820bad | |||
| 3952a8ba83 | |||
| 495c64249c |
5
rtchallenge/Cargo.lock
generated
Normal file
5
rtchallenge/Cargo.lock
generated
Normal file
@ -0,0 +1,5 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "rtchallenge"
|
||||
version = "0.1.0"
|
||||
9
rtchallenge/Cargo.toml
Normal file
9
rtchallenge/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "rtchallenge"
|
||||
version = "0.1.0"
|
||||
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
4
rtchallenge/README.md
Normal file
4
rtchallenge/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# The Ray Tracer Challenge: A Test-Driven Guide to Your First 3D Renderer
|
||||
This is a rust implementation of https://pragprog.com/titles/jbtracer/the-ray-tracer-challenge/
|
||||
|
||||
It attempts to be a test-driven developed ray tracer.
|
||||
1
rtchallenge/src/lib.rs
Normal file
1
rtchallenge/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
mod tuples;
|
||||
3
rtchallenge/src/main.rs
Normal file
3
rtchallenge/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
64
rtchallenge/src/tuples.rs
Normal file
64
rtchallenge/src/tuples.rs
Normal file
@ -0,0 +1,64 @@
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Tuple {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
w: f32,
|
||||
}
|
||||
|
||||
impl Tuple {
|
||||
fn is_point(&self) -> bool {
|
||||
self.w == 1.0
|
||||
}
|
||||
|
||||
fn is_vector(&self) -> bool {
|
||||
self.w == 0.0
|
||||
}
|
||||
}
|
||||
|
||||
fn point(x: f32, y: f32, z: f32) -> Tuple {
|
||||
tuple(x, y, z, 1.0)
|
||||
}
|
||||
|
||||
fn vector(x: f32, y: f32, z: f32) -> Tuple {
|
||||
tuple(x, y, z, 0.0)
|
||||
}
|
||||
|
||||
fn tuple(x: f32, y: f32, z: f32, w: f32) -> Tuple {
|
||||
Tuple { x, y, z, w }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{point, tuple, vector};
|
||||
#[test]
|
||||
fn is_point() {
|
||||
// A tuple with w = 1 is a point
|
||||
let a = tuple(4.3, -4.2, 3.1, 1.0);
|
||||
assert_eq!(a.x, 4.3);
|
||||
assert_eq!(a.y, -4.2);
|
||||
assert_eq!(a.z, 3.1);
|
||||
assert_eq!(a.w, 1.0);
|
||||
assert!(a.is_point());
|
||||
assert!(!a.is_vector());
|
||||
}
|
||||
#[test]
|
||||
fn is_vector() {
|
||||
// A tuple with w = 0 is a point
|
||||
let a = tuple(4.3, -4.2, 3.1, 0.0);
|
||||
assert_eq!(a.x, 4.3);
|
||||
assert_eq!(a.y, -4.2);
|
||||
assert_eq!(a.z, 3.1);
|
||||
assert_eq!(a.w, 0.0);
|
||||
assert!(!a.is_point());
|
||||
assert!(a.is_vector());
|
||||
}
|
||||
#[test]
|
||||
fn point_tuple() {
|
||||
assert_eq!(point(4., -4., 3.), tuple(4., -4., 3., 1.))
|
||||
}
|
||||
#[test]
|
||||
fn vector_tuple() {
|
||||
assert_eq!(vector(4., -4., 3.), tuple(4., -4., 3., 0.))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user