changed point/vector to not take tuples in

This commit is contained in:
Jon Janzen
2021-01-23 18:30:01 -07:00
parent f827fd19eb
commit 2e481efd7a

View File

@@ -4,14 +4,14 @@ extern crate approx;
use std::f32; use std::f32;
type PointVector = (f32, f32, f32, f32); type PointVector = (f32, f32, f32, f32);
type Dimensions = (f32, f32, f32);
fn point(dims: Dimensions) -> PointVector { fn point(x: f32, y: f32, z: f32) -> PointVector {
(dims.0, dims.1, dims.2, 1.0) (x, y, z, 1.0)
} }
fn vector(dims: Dimensions) -> PointVector {
(dims.0, dims.1, dims.2, 0.0) fn vector(x: f32, y: f32, z: f32) -> PointVector {
(x, y, z, 0.0)
} }
fn tuple_x(tuple: PointVector) -> f32 { fn tuple_x(tuple: PointVector) -> f32 {
@@ -58,7 +58,7 @@ mod tests {
#[test] #[test]
fn create_point() { fn create_point() {
let point = point((4.0, -4.0, 3.0)); let point = point(4.0, -4.0, 3.0);
assert_eq!(true, tuple_is_point(point)); assert_eq!(true, tuple_is_point(point));
} }
@@ -75,28 +75,28 @@ mod tests {
#[test] #[test]
fn create_vector() { fn create_vector() {
let vector = vector((4.0, -4.0, 3.0)); let vector = vector(4.0, -4.0, 3.0);
assert_eq!(true, tuple_is_vector(vector)); assert_eq!(true, tuple_is_vector(vector));
} }
#[test] #[test]
fn tuples_equal() { fn tuples_equal() {
let lhs = point((1.0, 2.0, 3.0)); let lhs = point(1.0, 2.0, 3.0);
let rhs = point((1.0, 2.0, 3.0)); let rhs = point(1.0, 2.0, 3.0);
assert_eq!(true, tuple_equals(lhs, rhs)); assert_eq!(true, tuple_equals(lhs, rhs));
} }
#[test] #[test]
fn tuples_relative_equal() { fn tuples_relative_equal() {
let lhs = point((1.0000001, 2.0, 3.0)); let lhs = point(1.0000001, 2.0, 3.0);
let rhs = point((1.0, 2.0, 3.0)); let rhs = point(1.0, 2.0, 3.0);
assert_eq!(true, tuple_equals(lhs, rhs)); assert_eq!(true, tuple_equals(lhs, rhs));
} }
#[test] #[test]
fn tuples_not_equal() { fn tuples_not_equal() {
let lhs = point((1.0, 2.0, 3.0)); let lhs = point(1.0, 2.0, 3.0);
let rhs = vector((1.0, 2.0, 3.0)); let rhs = vector(1.0, 2.0, 3.0);
assert_eq!(false, tuple_equals(lhs, rhs)); assert_eq!(false, tuple_equals(lhs, rhs));
} }
} }