Compare commits
2 Commits
285c75bbda
...
2e481efd7a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e481efd7a | ||
|
|
f827fd19eb |
@@ -4,14 +4,14 @@ extern crate approx;
|
||||
use std::f32;
|
||||
|
||||
type PointVector = (f32, f32, f32, f32);
|
||||
type Dimensions = (f32, f32, f32);
|
||||
|
||||
fn point(dims: Dimensions) -> PointVector {
|
||||
(dims.0, dims.1, dims.2, 1.0)
|
||||
fn point(x: f32, y: f32, z: f32) -> PointVector {
|
||||
(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 {
|
||||
@@ -29,10 +29,18 @@ fn tuple_z(tuple: PointVector) -> f32 {
|
||||
fn tuple_is_point(tuple: PointVector) -> bool {
|
||||
relative_eq!(1.0, tuple.3)
|
||||
}
|
||||
|
||||
fn tuple_is_vector(tuple: PointVector) -> bool {
|
||||
relative_eq!(0.0, tuple.3)
|
||||
}
|
||||
|
||||
fn tuple_equals(lhs: PointVector, rhs: PointVector) -> bool {
|
||||
relative_eq!(lhs.0, rhs.0)
|
||||
&& relative_eq!(lhs.1, rhs.1)
|
||||
&& relative_eq!(lhs.2, rhs.2)
|
||||
&& relative_eq!(lhs.3, rhs.3)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -50,7 +58,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -67,7 +75,28 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuples_equal() {
|
||||
let lhs = point(1.0, 2.0, 3.0);
|
||||
let rhs = point(1.0, 2.0, 3.0);
|
||||
assert_eq!(true, tuple_equals(lhs, rhs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuples_relative_equal() {
|
||||
let lhs = point(1.0000001, 2.0, 3.0);
|
||||
let rhs = point(1.0, 2.0, 3.0);
|
||||
assert_eq!(true, tuple_equals(lhs, rhs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuples_not_equal() {
|
||||
let lhs = point(1.0, 2.0, 3.0);
|
||||
let rhs = vector(1.0, 2.0, 3.0);
|
||||
assert_eq!(false, tuple_equals(lhs, rhs));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user