1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Geometric type definitions.

use std::fmt::Debug;

/// A 3-dimensional vector.
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub struct Vector(pub f32, pub f32, pub f32);

/// A color.
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub struct Color(pub f32, pub f32, pub f32);

/// A vertex.
pub trait Vertex : Clone + Debug + PartialEq + PartialOrd {
    /// Get the position of the vertex.
    fn position(&self) -> Vector;
}

/// A triangle.
#[derive(Debug, PartialEq, PartialOrd)]
pub struct Triangle<V: Vertex> {
    /// The vertices that make up the triangle.
    pub vertices: [V; 3],
}

// Allow (x,y,z) pairs to work as vectors.
impl Vertex for Vector {
    fn position(&self) -> Vector { *self }
}