diff --git a/src/lib.rs b/src/lib.rs index a778d97..e49766f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,128 +1,4 @@ -use std::ops::{Add, Div, Mul, Sub}; +mod geometry; +mod math; -#[derive(Copy, Clone)] -pub struct Vector3 { - x: f64, - y: f64, - z: f64, -} - -impl Vector3 { - pub fn new(x: f64, y: f64, z: f64) -> Vector3 { - Vector3 { x, y, z } - } -} - -impl Add for Vector3 { - type Output = Vector3; - - fn add(self, rhs: Vector3) -> Self::Output { - Vector3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) - } -} - -impl Sub for Vector3 { - type Output = Vector3; - - fn sub(self, rhs: Vector3) -> Self::Output { - Vector3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) - } -} - -impl Mul for Vector3 { - type Output = Vector3; - - fn mul(self, rhs: f64) -> Self::Output { - Vector3::new(self.x * rhs, self.y * rhs, self.z * rhs) - } -} - -impl Mul for f64 { - type Output = Vector3; - - fn mul(self, rhs: Vector3) -> Self::Output { - Vector3::new(self * rhs.x, self * rhs.y, self * rhs.z) - } -} - -impl Mul for Vector3 { - type Output = f64; - - fn mul(self, rhs: Vector3) -> Self::Output { - self.x * rhs.x + self.y * rhs.y + self.z * rhs.z - } -} - -impl Div for Vector3 { - type Output = Vector3; - - fn div(self, rhs: f64) -> Self::Output { - Vector3::new(self.x / rhs, self.y / rhs, self.z / rhs) - } -} - -#[derive(Copy, Clone)] -pub struct Point3 { - x: f64, - y: f64, - z: f64, -} - -impl Point3 { - pub fn new(x: f64, y: f64, z: f64) -> Point3 { - Point3 { x, y, z } - } - - pub fn get_x(&self) -> f64 { - self.x - } -} - -impl Add for Point3 { - type Output = Point3; - - fn add(self, rhs: Vector3) -> Self::Output { - Point3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) - } -} - -impl Sub for Point3 { - type Output = Vector3; - - fn sub(self, rhs: Point3) -> Self::Output { - Vector3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) - } -} - -pub struct Plane { - point: Point3, - normal: Vector3, -} - -impl Plane { - pub fn new(point: Point3, normal: Vector3) -> Plane { - Plane { point, normal } - } -} - -pub struct Line { - point: Point3, - direction: Vector3, -} - -pub struct Sphere { - point: Point3, - radius: f64, -} - -impl Sphere { - pub fn new(point: Point3, radius: f64) -> Sphere { - Sphere { point, radius } - } -} - -pub enum Geometry { - Sphere(Sphere), - Plane(Plane), - Line(Line), -} +pub use math::Point3; diff --git a/src/main.rs b/src/main.rs index fe3cc87..94d2357 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use hello::*; +use hello::Point3; fn main() { let p = Point3::new(0.0, 0.0, 0.0);