From df495feb5711bf01a025dbc188eef7c83bc4c5c4 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Thu, 24 Jun 2021 15:35:43 -0700 Subject: [PATCH] Make important types/functions public. --- rtchallenge/src/lib.rs | 2 +- rtchallenge/src/tuples.rs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rtchallenge/src/lib.rs b/rtchallenge/src/lib.rs index 921850a..eecba71 100644 --- a/rtchallenge/src/lib.rs +++ b/rtchallenge/src/lib.rs @@ -1 +1 @@ -mod tuples; +pub mod tuples; diff --git a/rtchallenge/src/tuples.rs b/rtchallenge/src/tuples.rs index ce091ad..bff4917 100644 --- a/rtchallenge/src/tuples.rs +++ b/rtchallenge/src/tuples.rs @@ -1,25 +1,25 @@ use std::ops::{Add, Div, Mul, Neg, Sub}; #[derive(Debug, PartialEq, Copy, Clone)] -struct Tuple { - x: f32, - y: f32, - z: f32, - w: f32, +pub struct Tuple { + pub x: f32, + pub y: f32, + pub z: f32, + pub w: f32, } impl Tuple { - fn is_point(&self) -> bool { + pub fn is_point(&self) -> bool { self.w == 1.0 } - fn is_vector(&self) -> bool { + pub fn is_vector(&self) -> bool { self.w == 0.0 } - fn magnitude(&self) -> f32 { + pub fn magnitude(&self) -> f32 { (self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w).sqrt() } - fn normalize(&self) -> Tuple { + pub fn normalize(&self) -> Tuple { let m = self.magnitude(); Tuple { x: self.x / m, @@ -101,22 +101,22 @@ impl Sub for Tuple { } } -fn point(x: f32, y: f32, z: f32) -> Tuple { +pub fn point(x: f32, y: f32, z: f32) -> Tuple { tuple(x, y, z, 1.0) } -fn vector(x: f32, y: f32, z: f32) -> Tuple { +pub 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 { +pub fn tuple(x: f32, y: f32, z: f32, w: f32) -> Tuple { Tuple { x, y, z, w } } -fn dot(a: Tuple, b: Tuple) -> f32 { +pub fn dot(a: Tuple, b: Tuple) -> f32 { a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w } -fn cross(a: Tuple, b: Tuple) -> Tuple { +pub fn cross(a: Tuple, b: Tuple) -> Tuple { vector( a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,