2014-01-25 15:54:54 +00:00
|
|
|
// Copyright 2014 The CGMath Developers. For a full listing of the authors,
|
2015-03-14 02:49:46 +00:00
|
|
|
// refer to the Cargo.toml file at the top-level directory of this distribution.
|
2013-10-13 00:00:51 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-04-19 10:51:40 +00:00
|
|
|
use structure::*;
|
|
|
|
|
2018-05-23 11:43:52 +00:00
|
|
|
use approx;
|
2016-04-19 10:51:40 +00:00
|
|
|
use matrix::{Matrix2, Matrix3, Matrix4};
|
|
|
|
use num::{BaseFloat, BaseNum};
|
|
|
|
use point::{Point2, Point3};
|
2015-03-02 04:05:47 +00:00
|
|
|
use rotation::*;
|
2016-04-19 10:51:40 +00:00
|
|
|
use vector::{Vector2, Vector3};
|
2013-10-31 21:36:21 +00:00
|
|
|
|
2014-05-25 11:17:26 +00:00
|
|
|
/// A trait representing an [affine
|
|
|
|
/// transformation](https://en.wikipedia.org/wiki/Affine_transformation) that
|
|
|
|
/// can be applied to points or vectors. An affine transformation is one which
|
2016-04-08 09:56:30 +00:00
|
|
|
pub trait Transform<P: EuclideanSpace>: Sized {
|
2014-05-25 11:17:26 +00:00
|
|
|
/// Create an identity transformation. That is, a transformation which
|
|
|
|
/// does nothing.
|
2015-10-01 08:52:44 +00:00
|
|
|
fn one() -> Self;
|
2014-05-25 11:17:26 +00:00
|
|
|
|
|
|
|
/// Create a transformation that rotates a vector to look at `center` from
|
|
|
|
/// `eye`, using `up` for orientation.
|
2016-04-08 05:35:11 +00:00
|
|
|
fn look_at(eye: P, center: P, up: P::Diff) -> Self;
|
2013-11-02 13:11:13 +00:00
|
|
|
|
2014-05-25 11:17:26 +00:00
|
|
|
/// Transform a vector using this transform.
|
2016-04-08 05:35:11 +00:00
|
|
|
fn transform_vector(&self, vec: P::Diff) -> P::Diff;
|
2014-05-25 11:17:26 +00:00
|
|
|
|
2017-09-28 20:32:23 +00:00
|
|
|
/// Inverse transform a vector using this transform
|
|
|
|
fn inverse_transform_vector(&self, vec: P::Diff) -> Option<P::Diff> {
|
2018-01-03 02:01:02 +00:00
|
|
|
self.inverse_transform()
|
|
|
|
.and_then(|inverse| Some(inverse.transform_vector(vec)))
|
2017-09-28 20:32:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 11:17:26 +00:00
|
|
|
/// Transform a point using this transform.
|
2015-11-09 09:12:04 +00:00
|
|
|
fn transform_point(&self, point: P) -> P;
|
2013-10-31 21:36:21 +00:00
|
|
|
|
2014-05-25 11:17:26 +00:00
|
|
|
/// Combine this transform with another, yielding a new transformation
|
|
|
|
/// which has the effects of both.
|
2013-11-02 13:11:13 +00:00
|
|
|
fn concat(&self, other: &Self) -> Self;
|
2014-05-25 11:17:26 +00:00
|
|
|
|
|
|
|
/// Create a transform that "un-does" this one.
|
2016-05-01 12:59:38 +00:00
|
|
|
fn inverse_transform(&self) -> Option<Self>;
|
2013-11-02 13:11:13 +00:00
|
|
|
|
2014-05-25 11:17:26 +00:00
|
|
|
/// Combine this transform with another, in-place.
|
2013-11-02 13:11:13 +00:00
|
|
|
#[inline]
|
|
|
|
fn concat_self(&mut self, other: &Self) {
|
2015-09-29 11:36:57 +00:00
|
|
|
*self = Self::concat(self, other);
|
2013-11-02 13:11:13 +00:00
|
|
|
}
|
2013-10-13 00:00:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 12:29:01 +00:00
|
|
|
/// A generic transformation consisting of a rotation,
|
2013-10-13 00:00:51 +00:00
|
|
|
/// displacement vector and scale amount.
|
2018-05-23 11:43:52 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
2016-04-07 22:46:35 +00:00
|
|
|
pub struct Decomposed<V: VectorSpace, R> {
|
2015-11-03 04:23:22 +00:00
|
|
|
pub scale: V::Scalar,
|
2014-04-01 11:00:17 +00:00
|
|
|
pub rot: R,
|
|
|
|
pub disp: V,
|
2013-10-13 00:00:51 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 20:44:04 +00:00
|
|
|
impl<P: EuclideanSpace, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
P::Scalar: BaseFloat,
|
|
|
|
// FIXME: Investigate why this is needed!
|
|
|
|
P::Diff: VectorSpace,
|
2015-11-03 04:23:22 +00:00
|
|
|
{
|
2013-11-01 23:42:09 +00:00
|
|
|
#[inline]
|
2016-04-08 05:35:11 +00:00
|
|
|
fn one() -> Decomposed<P::Diff, R> {
|
2013-11-01 23:42:09 +00:00
|
|
|
Decomposed {
|
2016-04-19 10:51:40 +00:00
|
|
|
scale: P::Scalar::one(),
|
2015-10-01 08:52:44 +00:00
|
|
|
rot: R::one(),
|
2016-04-08 05:35:11 +00:00
|
|
|
disp: P::Diff::zero(),
|
2013-11-01 23:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-25 15:54:54 +00:00
|
|
|
#[inline]
|
2016-04-08 05:35:11 +00:00
|
|
|
fn look_at(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
|
2015-12-12 11:31:10 +00:00
|
|
|
let rot = R::look_at(center - eye, up);
|
|
|
|
let disp = rot.rotate_vector(P::origin() - eye);
|
2014-01-25 15:54:54 +00:00
|
|
|
Decomposed {
|
2016-04-19 10:51:40 +00:00
|
|
|
scale: P::Scalar::one(),
|
2014-01-25 15:54:54 +00:00
|
|
|
rot: rot,
|
|
|
|
disp: disp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:36:21 +00:00
|
|
|
#[inline]
|
2016-04-08 05:35:11 +00:00
|
|
|
fn transform_vector(&self, vec: P::Diff) -> P::Diff {
|
2015-12-12 12:24:14 +00:00
|
|
|
self.rot.rotate_vector(vec * self.scale)
|
2013-10-31 21:36:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 20:32:23 +00:00
|
|
|
#[inline]
|
|
|
|
fn inverse_transform_vector(&self, vec: P::Diff) -> Option<P::Diff> {
|
|
|
|
if ulps_eq!(self.scale, &P::Scalar::zero()) {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(self.rot.invert().rotate_vector(vec / self.scale))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:36:21 +00:00
|
|
|
#[inline]
|
2015-11-09 09:12:04 +00:00
|
|
|
fn transform_point(&self, point: P) -> P {
|
2015-12-12 11:31:10 +00:00
|
|
|
self.rot.rotate_point(point * self.scale) + self.disp
|
2013-10-31 21:36:21 +00:00
|
|
|
}
|
2013-11-01 23:42:09 +00:00
|
|
|
|
2016-04-08 05:35:11 +00:00
|
|
|
fn concat(&self, other: &Decomposed<P::Diff, R>) -> Decomposed<P::Diff, R> {
|
2013-11-02 13:11:13 +00:00
|
|
|
Decomposed {
|
|
|
|
scale: self.scale * other.scale,
|
2016-05-11 22:31:45 +00:00
|
|
|
rot: self.rot * other.rot,
|
2016-07-03 04:17:58 +00:00
|
|
|
disp: self.rot.rotate_vector(other.disp * self.scale) + self.disp,
|
2013-11-02 13:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 12:59:38 +00:00
|
|
|
fn inverse_transform(&self) -> Option<Decomposed<P::Diff, R>> {
|
2016-08-22 15:21:22 +00:00
|
|
|
if ulps_eq!(self.scale, &P::Scalar::zero()) {
|
2013-11-01 23:42:09 +00:00
|
|
|
None
|
2014-06-15 18:18:31 +00:00
|
|
|
} else {
|
2016-04-19 10:51:40 +00:00
|
|
|
let s = P::Scalar::one() / self.scale;
|
2013-11-01 23:42:09 +00:00
|
|
|
let r = self.rot.invert();
|
2015-12-12 12:24:14 +00:00
|
|
|
let d = r.rotate_vector(self.disp.clone()) * -s;
|
2014-06-15 18:18:31 +00:00
|
|
|
Some(Decomposed {
|
2018-01-03 02:01:02 +00:00
|
|
|
scale: s,
|
|
|
|
rot: r,
|
|
|
|
disp: d,
|
|
|
|
})
|
2013-11-01 23:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-01 12:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 04:23:22 +00:00
|
|
|
pub trait Transform2<S: BaseNum>: Transform<Point2<S>> + Into<Matrix3<S>> {}
|
|
|
|
pub trait Transform3<S: BaseNum>: Transform<Point3<S>> + Into<Matrix4<S>> {}
|
2013-11-01 14:32:29 +00:00
|
|
|
|
2015-11-03 04:23:22 +00:00
|
|
|
impl<S: BaseFloat, R: Rotation2<S>> From<Decomposed<Vector2<S>, R>> for Matrix3<S> {
|
|
|
|
fn from(dec: Decomposed<Vector2<S>, R>) -> Matrix3<S> {
|
2015-05-06 08:27:52 +00:00
|
|
|
let m: Matrix2<_> = dec.rot.into();
|
2015-11-08 06:41:57 +00:00
|
|
|
let mut m: Matrix3<_> = (&m * dec.scale).into();
|
2015-09-29 11:36:57 +00:00
|
|
|
m.z = dec.disp.extend(S::one());
|
2015-03-02 04:05:47 +00:00
|
|
|
m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:23:22 +00:00
|
|
|
impl<S: BaseFloat, R: Rotation3<S>> From<Decomposed<Vector3<S>, R>> for Matrix4<S> {
|
|
|
|
fn from(dec: Decomposed<Vector3<S>, R>) -> Matrix4<S> {
|
2015-05-06 08:27:52 +00:00
|
|
|
let m: Matrix3<_> = dec.rot.into();
|
2015-11-08 06:41:57 +00:00
|
|
|
let mut m: Matrix4<_> = (&m * dec.scale).into();
|
2015-09-29 11:36:57 +00:00
|
|
|
m.w = dec.disp.extend(S::one());
|
2013-11-01 14:32:29 +00:00
|
|
|
m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:23:22 +00:00
|
|
|
impl<S: BaseFloat, R: Rotation2<S>> Transform2<S> for Decomposed<Vector2<S>, R> {}
|
2015-03-02 04:05:47 +00:00
|
|
|
|
2015-11-03 04:23:22 +00:00
|
|
|
impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<Vector3<S>, R> {}
|
2016-05-16 12:16:59 +00:00
|
|
|
|
2018-05-23 11:43:52 +00:00
|
|
|
impl<S: VectorSpace, R, E: BaseFloat> approx::AbsDiffEq for Decomposed<S, R>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
2018-05-23 11:43:52 +00:00
|
|
|
S: approx::AbsDiffEq<Epsilon = E>,
|
|
|
|
S::Scalar: approx::AbsDiffEq<Epsilon = E>,
|
|
|
|
R: approx::AbsDiffEq<Epsilon = E>,
|
2016-05-16 13:22:37 +00:00
|
|
|
{
|
|
|
|
type Epsilon = E;
|
|
|
|
|
2016-08-22 15:21:22 +00:00
|
|
|
#[inline]
|
|
|
|
fn default_epsilon() -> E {
|
|
|
|
E::default_epsilon()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-05-23 11:43:52 +00:00
|
|
|
fn abs_diff_eq(&self, other: &Self, epsilon: E) -> bool {
|
|
|
|
S::Scalar::abs_diff_eq(&self.scale, &other.scale, epsilon)
|
|
|
|
&& R::abs_diff_eq(&self.rot, &other.rot, epsilon)
|
|
|
|
&& S::abs_diff_eq(&self.disp, &other.disp, epsilon)
|
2016-08-22 15:21:22 +00:00
|
|
|
}
|
2018-05-23 11:43:52 +00:00
|
|
|
}
|
2016-08-22 15:21:22 +00:00
|
|
|
|
2018-05-23 11:43:52 +00:00
|
|
|
impl<S: VectorSpace, R, E: BaseFloat> approx::RelativeEq for Decomposed<S, R>
|
|
|
|
where
|
|
|
|
S: approx::RelativeEq<Epsilon = E>,
|
|
|
|
S::Scalar: approx::RelativeEq<Epsilon = E>,
|
|
|
|
R: approx::RelativeEq<Epsilon = E>,
|
|
|
|
{
|
2016-08-22 15:21:22 +00:00
|
|
|
#[inline]
|
2018-05-23 11:43:52 +00:00
|
|
|
fn default_max_relative() -> E {
|
|
|
|
E::default_max_relative()
|
2016-08-22 15:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn relative_eq(&self, other: &Self, epsilon: E, max_relative: E) -> bool {
|
2018-01-03 02:01:02 +00:00
|
|
|
S::Scalar::relative_eq(&self.scale, &other.scale, epsilon, max_relative)
|
|
|
|
&& R::relative_eq(&self.rot, &other.rot, epsilon, max_relative)
|
|
|
|
&& S::relative_eq(&self.disp, &other.disp, epsilon, max_relative)
|
2016-08-22 15:21:22 +00:00
|
|
|
}
|
2018-05-23 11:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<S: VectorSpace, R, E: BaseFloat> approx::UlpsEq for Decomposed<S, R>
|
|
|
|
where
|
|
|
|
S: approx::UlpsEq<Epsilon = E>,
|
|
|
|
S::Scalar: approx::UlpsEq<Epsilon = E>,
|
|
|
|
R: approx::UlpsEq<Epsilon = E>,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn default_max_ulps() -> u32 {
|
|
|
|
E::default_max_ulps()
|
|
|
|
}
|
2016-08-22 15:21:22 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn ulps_eq(&self, other: &Self, epsilon: E, max_ulps: u32) -> bool {
|
2018-01-03 02:01:02 +00:00
|
|
|
S::Scalar::ulps_eq(&self.scale, &other.scale, epsilon, max_ulps)
|
|
|
|
&& R::ulps_eq(&self.rot, &other.rot, epsilon, max_ulps)
|
|
|
|
&& S::ulps_eq(&self.disp, &other.disp, epsilon, max_ulps)
|
2016-05-16 13:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:48:55 +00:00
|
|
|
#[cfg(feature = "serde")]
|
2016-05-16 12:16:59 +00:00
|
|
|
#[doc(hidden)]
|
2017-06-06 20:48:55 +00:00
|
|
|
mod serde_ser {
|
2016-05-16 12:16:59 +00:00
|
|
|
use structure::VectorSpace;
|
|
|
|
use super::Decomposed;
|
|
|
|
use serde::{self, Serialize};
|
2017-04-04 20:44:04 +00:00
|
|
|
use serde::ser::SerializeStruct;
|
2016-05-16 12:16:59 +00:00
|
|
|
|
2017-04-04 20:44:04 +00:00
|
|
|
impl<V, R> Serialize for Decomposed<V, R>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
V: Serialize + VectorSpace,
|
|
|
|
V::Scalar: Serialize,
|
|
|
|
R: Serialize,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
2017-04-04 20:44:04 +00:00
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
S: serde::Serializer,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
2017-04-04 20:44:04 +00:00
|
|
|
let mut struc = serializer.serialize_struct("Decomposed", 3)?;
|
|
|
|
struc.serialize_field("scale", &self.scale)?;
|
|
|
|
struc.serialize_field("rot", &self.rot)?;
|
|
|
|
struc.serialize_field("disp", &self.disp)?;
|
|
|
|
struc.end()
|
2016-05-16 12:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:48:55 +00:00
|
|
|
#[cfg(feature = "serde")]
|
2016-05-16 12:16:59 +00:00
|
|
|
#[doc(hidden)]
|
2017-06-06 20:48:55 +00:00
|
|
|
mod serde_de {
|
2016-05-16 12:16:59 +00:00
|
|
|
use structure::VectorSpace;
|
|
|
|
use super::Decomposed;
|
|
|
|
use serde::{self, Deserialize};
|
|
|
|
use std::marker::PhantomData;
|
2017-04-04 20:44:04 +00:00
|
|
|
use std::fmt;
|
2016-05-16 12:16:59 +00:00
|
|
|
|
|
|
|
enum DecomposedField {
|
|
|
|
Scale,
|
|
|
|
Rot,
|
|
|
|
Disp,
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
impl<'a> Deserialize<'a> for DecomposedField {
|
2017-04-04 20:44:04 +00:00
|
|
|
fn deserialize<D>(deserializer: D) -> Result<DecomposedField, D::Error>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
D: serde::Deserializer<'a>,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
|
|
|
struct DecomposedFieldVisitor;
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
impl<'b> serde::de::Visitor<'b> for DecomposedFieldVisitor {
|
2016-05-16 12:16:59 +00:00
|
|
|
type Value = DecomposedField;
|
|
|
|
|
2017-04-04 20:44:04 +00:00
|
|
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
formatter.write_str("`scale`, `rot` or `disp`")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_str<E>(self, value: &str) -> Result<DecomposedField, E>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
E: serde::de::Error,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
|
|
|
match value {
|
|
|
|
"scale" => Ok(DecomposedField::Scale),
|
|
|
|
"rot" => Ok(DecomposedField::Rot),
|
|
|
|
"disp" => Ok(DecomposedField::Disp),
|
|
|
|
_ => Err(serde::de::Error::custom("expected scale, rot or disp")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
deserializer.deserialize_str(DecomposedFieldVisitor)
|
2016-05-16 12:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
impl<'a, S: VectorSpace, R> Deserialize<'a> for Decomposed<S, R>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
S: Deserialize<'a>,
|
|
|
|
S::Scalar: Deserialize<'a>,
|
|
|
|
R: Deserialize<'a>,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
2017-04-04 20:44:04 +00:00
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Decomposed<S, R>, D::Error>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
D: serde::de::Deserializer<'a>,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
|
|
|
const FIELDS: &'static [&'static str] = &["scale", "rot", "disp"];
|
|
|
|
deserializer.deserialize_struct("Decomposed", FIELDS, DecomposedVisitor(PhantomData))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DecomposedVisitor<S: VectorSpace, R>(PhantomData<(S, R)>);
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
impl<'a, S: VectorSpace, R> serde::de::Visitor<'a> for DecomposedVisitor<S, R>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
S: Deserialize<'a>,
|
|
|
|
S::Scalar: Deserialize<'a>,
|
|
|
|
R: Deserialize<'a>,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
|
|
|
type Value = Decomposed<S, R>;
|
|
|
|
|
2017-04-04 20:44:04 +00:00
|
|
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
formatter.write_str("`scale`, `rot` and `disp` fields")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_map<V>(self, mut visitor: V) -> Result<Decomposed<S, R>, V::Error>
|
2018-01-03 02:01:02 +00:00
|
|
|
where
|
|
|
|
V: serde::de::MapAccess<'a>,
|
2016-05-16 12:16:59 +00:00
|
|
|
{
|
|
|
|
let mut scale = None;
|
|
|
|
let mut rot = None;
|
|
|
|
let mut disp = None;
|
|
|
|
|
2017-04-22 22:31:50 +00:00
|
|
|
while let Some(key) = visitor.next_key()? {
|
2017-04-04 20:44:04 +00:00
|
|
|
match key {
|
|
|
|
DecomposedField::Scale => {
|
2017-04-22 22:31:50 +00:00
|
|
|
scale = Some(visitor.next_value()?);
|
2017-04-04 20:44:04 +00:00
|
|
|
}
|
|
|
|
DecomposedField::Rot => {
|
2017-04-22 22:31:50 +00:00
|
|
|
rot = Some(visitor.next_value()?);
|
2017-04-04 20:44:04 +00:00
|
|
|
}
|
|
|
|
DecomposedField::Disp => {
|
2017-04-22 22:31:50 +00:00
|
|
|
disp = Some(visitor.next_value()?);
|
2017-04-04 20:44:04 +00:00
|
|
|
}
|
2016-05-16 12:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let scale = match scale {
|
|
|
|
Some(scale) => scale,
|
2017-04-04 20:44:04 +00:00
|
|
|
None => return Err(serde::de::Error::missing_field("scale")),
|
2016-05-16 12:16:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let rot = match rot {
|
|
|
|
Some(rot) => rot,
|
2017-04-04 20:44:04 +00:00
|
|
|
None => return Err(serde::de::Error::missing_field("rot")),
|
2016-05-16 12:16:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let disp = match disp {
|
|
|
|
Some(disp) => disp,
|
2017-04-04 20:44:04 +00:00
|
|
|
None => return Err(serde::de::Error::missing_field("disp")),
|
2016-05-16 12:16:59 +00:00
|
|
|
};
|
|
|
|
|
2017-04-04 20:44:04 +00:00
|
|
|
Ok(Decomposed {
|
2018-01-03 02:01:02 +00:00
|
|
|
scale: scale,
|
|
|
|
rot: rot,
|
|
|
|
disp: disp,
|
|
|
|
})
|
2016-05-16 12:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 13:22:37 +00:00
|
|
|
}
|