diff --git a/src/geometry.rs b/src/geometry.rs index 83b4ed4..7908973 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,39 +1,39 @@ use crate::math::{Point3, Vector3}; -pub struct Plane { - point: Point3, - normal: Vector3, +pub struct Plane { + point: Point3, + normal: Vector3, } -impl Plane { - pub fn new(point: Point3, normal: Vector3) -> Plane { +impl Plane { + pub fn new(point: Point3, normal: Vector3) -> Plane { Plane { point, normal } } } -pub struct Line { - point: Point3, - direction: Vector3, +pub struct Line { + point: Point3, + direction: Vector3, } -pub struct Sphere { - point: Point3, - radius: f64, +pub struct Sphere { + point: Point3, + radius: T, } -impl Sphere { - pub fn new(point: Point3, radius: f64) -> Sphere { +impl Sphere { + pub fn new(point: Point3, radius: T) -> Sphere { Sphere { point, radius } } } -pub enum Geometry { - Sphere(Sphere), - Plane(Plane), - Line(Line), +pub enum Geometry { + Sphere(Sphere), + Plane(Plane), + Line(Line), } -impl Geometry { +impl Geometry { pub fn draw(&self) { match self { Geometry::Sphere(_) => { diff --git a/src/main.rs b/src/main.rs index 7d2d401..da54778 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,14 +42,18 @@ impl Texture { } } -struct RenderableGeometry { +struct RenderableGeometry { transform: Mat4x4, - geometry: Geometry, + geometry: Geometry, texture: Rc>, } -impl RenderableGeometry { - fn new(transform: Mat4x4, geometry: Geometry, texture: Rc>) -> RenderableGeometry { +impl RenderableGeometry { + fn new( + transform: Mat4x4, + geometry: Geometry, + texture: Rc>, + ) -> RenderableGeometry { RenderableGeometry { transform, geometry, @@ -62,19 +66,19 @@ trait Renderable { fn render(&self); } -impl Renderable for Sphere { +impl Renderable for Sphere { fn render(&self) { println!("Rendering Sphere!"); } } -impl Renderable for Plane { +impl Renderable for Plane { fn render(&self) { println!("Rendering Plane!"); } } -impl Renderable for Line { +impl Renderable for Line { fn render(&self) { println!("Rendering Line!"); } diff --git a/src/math.rs b/src/math.rs index 988841e..b787954 100644 --- a/src/math.rs +++ b/src/math.rs @@ -78,30 +78,36 @@ where } #[derive(Copy, Clone, PartialEq, Debug)] -pub struct Point3 { - x: f64, - y: f64, - z: f64, +pub struct Point3 { + x: T, + y: T, + z: T, } -impl Point3 { - pub fn new(x: f64, y: f64, z: f64) -> Point3 { +impl Point3 { + pub fn new(x: T, y: T, z: T) -> Point3 { Point3 { x, y, z } } } -impl Add> for Point3 { - type Output = Point3; +impl Add> for Point3 +where + T: Add, +{ + 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 { +impl Sub for Point3 +where + T: Sub, +{ type Output = Vector3; - fn sub(self, rhs: Point3) -> Self::Output { + fn sub(self, rhs: Point3) -> Self::Output { Vector3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) } }