library: document light module

This commit is contained in:
Antoine Martin 2020-03-22 00:08:11 +01:00
parent 04deae1d88
commit 2aed964101
5 changed files with 41 additions and 0 deletions

View file

@ -10,6 +10,16 @@ pub struct AmbientLight {
} }
impl AmbientLight { impl AmbientLight {
/// Creates a new `AmbientLight`.
///
/// # Examples
///
/// ```
/// # use pathtracer::light::AmbientLight;
/// # use pathtracer::core::color::LinearColor;
/// #
/// let amb_light = AmbientLight::new(LinearColor::new(1.0, 0.0, 1.0));
/// ```
pub fn new(color: LinearColor) -> Self { pub fn new(color: LinearColor) -> Self {
AmbientLight { color } AmbientLight { color }
} }

View file

@ -12,6 +12,20 @@ pub struct DirectionalLight {
} }
impl DirectionalLight { impl DirectionalLight {
/// Creates a new `DirectionalLight`.
///
/// # Examples
///
/// ```
/// # use pathtracer::light::DirectionalLight;
/// # use pathtracer::core::color::LinearColor;
/// # use pathtracer::Vector;
/// #
/// let dir_light = DirectionalLight::new(
/// Vector::new(1.0, 0.0, 0.0),
/// LinearColor::new(1.0, 0.0, 1.0),
/// );
/// ```
pub fn new(direction: Vector, color: LinearColor) -> Self { pub fn new(direction: Vector, color: LinearColor) -> Self {
DirectionalLight { DirectionalLight {
direction: direction.normalize(), direction: direction.normalize(),

View file

@ -1,3 +1,5 @@
//! Various light implementations
use super::core::LinearColor; use super::core::LinearColor;
use super::{Point, Vector}; use super::{Point, Vector};

View file

@ -11,6 +11,20 @@ pub struct PointLight {
} }
impl PointLight { impl PointLight {
/// Creates a new `PointLight`.
///
/// # Examples
///
/// ```
/// # use pathtracer::light::PointLight;
/// # use pathtracer::core::color::LinearColor;
/// # use pathtracer::Point;
/// #
/// let dir_light = PointLight::new(
/// Point::origin(),
/// LinearColor::new(1.0, 0.0, 1.0),
/// );
/// ```
pub fn new(position: Point, color: LinearColor) -> Self { pub fn new(position: Point, color: LinearColor) -> Self {
PointLight { position, color } PointLight { position, color }
} }

View file

@ -4,6 +4,7 @@ use crate::{Point, Vector};
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
/// Represent a light emanating from a directed light-source, outputting rays in a cone. /// Represent a light emanating from a directed light-source, outputting rays in a cone.
///
/// The illumination cone cannot have an FOV over 180°. /// The illumination cone cannot have an FOV over 180°.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct SpotLight { pub struct SpotLight {