library: use #[serde(from)] for Deserialize
This commit is contained in:
parent
0678317442
commit
8727ae9d87
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
use super::film::Film;
|
use super::film::Film;
|
||||||
use crate::{Point, Vector};
|
use crate::{Point, Vector};
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Represent an abstract camera to observe the scene.
|
/// Represent an abstract camera to observe the scene.
|
||||||
#[derive(Debug, PartialEq)]
|
#[serde(from = "SerializedCamera")]
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
/// Where the camera is set in the scene (i.e: its focal point).
|
/// Where the camera is set in the scene (i.e: its focal point).
|
||||||
origin: Point,
|
origin: Point,
|
||||||
|
@ -140,16 +141,6 @@ impl From<SerializedCamera> for Camera {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Camera {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let cam: SerializedCamera = Deserialize::deserialize(deserializer)?;
|
|
||||||
Ok(cam.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -2,12 +2,13 @@ use super::{Light, SpatialLight};
|
||||||
use crate::core::LinearColor;
|
use crate::core::LinearColor;
|
||||||
use crate::{Point, Vector};
|
use crate::{Point, Vector};
|
||||||
use nalgebra::Unit;
|
use nalgebra::Unit;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// 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)]
|
#[serde(from = "SerializedSpotLight")]
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct SpotLight {
|
pub struct SpotLight {
|
||||||
position: Point,
|
position: Point,
|
||||||
direction: Unit<Vector>,
|
direction: Unit<Vector>,
|
||||||
|
@ -82,16 +83,6 @@ impl From<SerializedSpotLight> for SpotLight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for SpotLight {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let cam: SerializedSpotLight = Deserialize::deserialize(deserializer)?;
|
|
||||||
Ok(cam.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -13,9 +13,11 @@ use image::RgbImage;
|
||||||
use nalgebra::Unit;
|
use nalgebra::Unit;
|
||||||
use rand::prelude::thread_rng;
|
use rand::prelude::thread_rng;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Represent the scene being rendered.
|
/// Represent the scene being rendered.
|
||||||
|
#[serde(from = "SerializedScene")]
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
lights: LightAggregate,
|
lights: LightAggregate,
|
||||||
|
@ -339,16 +341,6 @@ impl From<SerializedScene> for Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Scene {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let cam: SerializedScene = Deserialize::deserialize(deserializer)?;
|
|
||||||
Ok(cam.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -4,10 +4,11 @@ use beevee::aabb::{Bounded, AABB};
|
||||||
use beevee::bvh::Intersected;
|
use beevee::bvh::Intersected;
|
||||||
use beevee::ray::Ray;
|
use beevee::ray::Ray;
|
||||||
use nalgebra::Unit;
|
use nalgebra::Unit;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Represent a triangle inside the scene.
|
/// Represent a triangle inside the scene.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[serde(from = "SerializedTriangle")]
|
||||||
|
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||||
pub struct Triangle {
|
pub struct Triangle {
|
||||||
c0: Point,
|
c0: Point,
|
||||||
c0c1: Vector,
|
c0c1: Vector,
|
||||||
|
@ -129,16 +130,6 @@ impl From<SerializedTriangle> for Triangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Triangle {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let cam: SerializedTriangle = Deserialize::deserialize(deserializer)?;
|
|
||||||
Ok(cam.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue