Compare commits
No commits in common. "b159820bad089e31a779d041290f73c9514ea7e6" and "a30a5a383cd38e9a125d2c741007ee3018cbdb7e" have entirely different histories.
b159820bad
...
a30a5a383c
5
rtchallenge/Cargo.lock
generated
5
rtchallenge/Cargo.lock
generated
@ -1,5 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "rtchallenge"
|
||||
version = "0.1.0"
|
||||
@ -1,9 +0,0 @@
|
||||
[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]
|
||||
@ -1,4 +0,0 @@
|
||||
# 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 +0,0 @@
|
||||
mod tuples;
|
||||
@ -1,3 +0,0 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
#[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