Make important types/functions public.

This commit is contained in:
Bill Thiede 2021-06-24 15:35:43 -07:00
parent 21afbf8e7c
commit df495feb57
2 changed files with 15 additions and 15 deletions

View File

@ -1 +1 @@
mod tuples;
pub mod tuples;

View File

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