world: add test_world constructor for book tests.
This commit is contained in:
parent
3bc9f6f924
commit
eebdc270eb
@ -1,4 +1,10 @@
|
|||||||
use crate::{lights::PointLight, spheres::Sphere};
|
use crate::{
|
||||||
|
lights::PointLight,
|
||||||
|
materials::Material,
|
||||||
|
matrices::{Matrix2x2, Matrix4x4},
|
||||||
|
spheres::Sphere,
|
||||||
|
tuples::{Color, Tuple},
|
||||||
|
};
|
||||||
|
|
||||||
/// World holds all drawable objects and the light(s) that illuminate them.
|
/// World holds all drawable objects and the light(s) that illuminate them.
|
||||||
///
|
///
|
||||||
@ -17,3 +23,32 @@ pub struct World {
|
|||||||
pub light: Option<PointLight>,
|
pub light: Option<PointLight>,
|
||||||
pub objects: Vec<Sphere>,
|
pub objects: Vec<Sphere>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl World {
|
||||||
|
/// Creates a world suitable for use across multiple tests in from the book.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// use rtchallenge::world::World;
|
||||||
|
///
|
||||||
|
/// let w = World::test_world();
|
||||||
|
/// assert_eq!(w.objects.len(), 2);
|
||||||
|
/// assert!(w.light.is_some());
|
||||||
|
/// ```
|
||||||
|
pub fn test_world() -> World {
|
||||||
|
let light = PointLight::new(Tuple::point(-10., 10., -10.), Color::new(1., 1., 1.));
|
||||||
|
let mut s1 = Sphere::default();
|
||||||
|
s1.material = Material {
|
||||||
|
color: Color::new(0.8, 1., 0.6),
|
||||||
|
diffuse: 0.7,
|
||||||
|
specular: 0.2,
|
||||||
|
..Material::default()
|
||||||
|
};
|
||||||
|
let mut s2 = Sphere::default();
|
||||||
|
s2.transform = Matrix4x4::scaling(0.5, 0.5, 0.5);
|
||||||
|
World {
|
||||||
|
light: Some(light),
|
||||||
|
objects: vec![s1, s2],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user