We can create Polymorphism using enums
This commit is contained in:
parent
50eabecfe9
commit
36c16d053e
@ -33,6 +33,22 @@ pub enum Geometry {
|
||||
Line(Line),
|
||||
}
|
||||
|
||||
impl Geometry {
|
||||
pub fn greet(&self) {
|
||||
match self {
|
||||
Geometry::Sphere(_) => {
|
||||
println!("Sphere!");
|
||||
}
|
||||
Geometry::Line(_) => {
|
||||
println!("Line!");
|
||||
}
|
||||
Geometry::Plane(_) => {
|
||||
println!("Plane!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@ -61,6 +61,9 @@ impl RenderableGeometry {
|
||||
fn main() {
|
||||
let tex = Rc::new(Texture::load_texture());
|
||||
|
||||
let sphere = Geometry::Sphere(Sphere::new(Point3::new(0.0, 0.0, 0.0), 1.0));
|
||||
sphere.greet();
|
||||
|
||||
let geo1 = RenderableGeometry::new(
|
||||
Mat4x4::ident(),
|
||||
Geometry::Sphere(Sphere::new(Point3::new(0.0, 0.0, 0.0), 1.0)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user