73 lines
1.2 KiB
Rust
73 lines
1.2 KiB
Rust
use crate::math::{Point3, Vector3};
|
|
|
|
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),
|
|
}
|
|
|
|
impl Geometry {
|
|
pub fn draw(&self) {
|
|
match self {
|
|
Geometry::Sphere(_) => {
|
|
println!("Drawing Sphere!");
|
|
}
|
|
Geometry::Line(_) => {
|
|
println!("Drawing Line!");
|
|
}
|
|
Geometry::Plane(_) => {
|
|
println!("Drawing Plane!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn new_plane() {
|
|
let p = Point3::new(1.0, 2.0, 3.0);
|
|
let n = Vector3::new(4.0, 5.0, 6.0);
|
|
|
|
let plane = Plane::new(p, n);
|
|
|
|
assert_eq!(plane.point, p);
|
|
assert_eq!(plane.normal, n);
|
|
}
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn foo() {
|
|
panic!("This code panics!");
|
|
}
|
|
}
|