Compare commits

..

No commits in common. "b159820bad089e31a779d041290f73c9514ea7e6" and "a30a5a383cd38e9a125d2c741007ee3018cbdb7e" have entirely different histories.

6 changed files with 0 additions and 86 deletions

View File

@ -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"

View File

@ -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]

View File

@ -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.

View File

@ -1 +0,0 @@
mod tuples;

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View File

@ -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.))
}
}