commit
e02eb9811a
3 changed files with 64 additions and 40 deletions
|
@ -6,6 +6,6 @@ rust:
|
|||
- stable
|
||||
|
||||
script:
|
||||
- cargo build && cargo test
|
||||
- cargo build && cargo test && cargo test --features "eders"
|
||||
- if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo bench; fi
|
||||
- if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo build --features "use_simd" && cargo test --features "use_simd" && cargo bench --features "use_simd"; fi
|
||||
|
|
|
@ -37,10 +37,10 @@ approx = "0.1"
|
|||
num-traits = "0.1"
|
||||
rand = "0.3"
|
||||
rustc-serialize = { version = "0.3", optional = true }
|
||||
serde = { version = "0.8", optional = true }
|
||||
serde_derive = { version = "0.8", optional = true }
|
||||
serde = { version = "0.9", optional = true }
|
||||
serde_derive = { version = "0.9", optional = true }
|
||||
simd = { version = "0.2", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
glium = "0.15"
|
||||
serde_json = "0.8"
|
||||
serde_json = "0.9"
|
||||
|
|
|
@ -64,11 +64,10 @@ pub struct Decomposed<V: VectorSpace, R> {
|
|||
pub disp: V,
|
||||
}
|
||||
|
||||
impl<P: EuclideanSpace, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R> where
|
||||
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
|
||||
<P as EuclideanSpace>::Scalar: BaseFloat,
|
||||
// FIXME: Investigate why this is needed!
|
||||
<P as EuclideanSpace>::Diff: VectorSpace,
|
||||
impl<P: EuclideanSpace, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R>
|
||||
where <P as EuclideanSpace>::Scalar: BaseFloat,
|
||||
// FIXME: Investigate why this is needed!
|
||||
<P as EuclideanSpace>::Diff: VectorSpace
|
||||
{
|
||||
#[inline]
|
||||
fn one() -> Decomposed<P::Diff, R> {
|
||||
|
@ -116,10 +115,10 @@ impl<P: EuclideanSpace, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R>
|
|||
let r = self.rot.invert();
|
||||
let d = r.rotate_vector(self.disp.clone()) * -s;
|
||||
Some(Decomposed {
|
||||
scale: s,
|
||||
rot: r,
|
||||
disp: d,
|
||||
})
|
||||
scale: s,
|
||||
rot: r,
|
||||
disp: d,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +149,9 @@ impl<S: BaseFloat, R: Rotation2<S>> Transform2<S> for Decomposed<Vector2<S>, R>
|
|||
impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<Vector3<S>, R> {}
|
||||
|
||||
impl<S: VectorSpace, R, E: BaseFloat> ApproxEq for Decomposed<S, R>
|
||||
where S: ApproxEq<Epsilon = E>, S::Scalar: ApproxEq<Epsilon = E>, R: ApproxEq<Epsilon = E>
|
||||
where S: ApproxEq<Epsilon = E>,
|
||||
S::Scalar: ApproxEq<Epsilon = E>,
|
||||
R: ApproxEq<Epsilon = E>
|
||||
{
|
||||
type Epsilon = E;
|
||||
|
||||
|
@ -190,18 +191,21 @@ mod eders_ser {
|
|||
use structure::VectorSpace;
|
||||
use super::Decomposed;
|
||||
use serde::{self, Serialize};
|
||||
use serde::ser::SerializeStruct;
|
||||
|
||||
impl<V: VectorSpace, R> Serialize for Decomposed<V, R>
|
||||
where V: Serialize, V::Scalar: Serialize, R: Serialize
|
||||
impl<V, R> Serialize for Decomposed<V, R>
|
||||
where V: Serialize + VectorSpace,
|
||||
V::Scalar: Serialize,
|
||||
R: Serialize
|
||||
{
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: serde::Serializer
|
||||
{
|
||||
let mut state = try!(serializer.serialize_struct("Decomposed", 3));
|
||||
try!(serializer.serialize_struct_elt(&mut state, "scale", &self.scale));
|
||||
try!(serializer.serialize_struct_elt(&mut state, "rot", &self.rot));
|
||||
try!(serializer.serialize_struct_elt(&mut state, "disp", &self.disp));
|
||||
serializer.serialize_struct_end(state)
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,6 +217,7 @@ mod eders_de {
|
|||
use super::Decomposed;
|
||||
use serde::{self, Deserialize};
|
||||
use std::marker::PhantomData;
|
||||
use std::fmt;
|
||||
|
||||
enum DecomposedField {
|
||||
Scale,
|
||||
|
@ -221,7 +226,7 @@ mod eders_de {
|
|||
}
|
||||
|
||||
impl Deserialize for DecomposedField {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<DecomposedField, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<DecomposedField, D::Error>
|
||||
where D: serde::Deserializer
|
||||
{
|
||||
struct DecomposedFieldVisitor;
|
||||
|
@ -229,7 +234,11 @@ mod eders_de {
|
|||
impl serde::de::Visitor for DecomposedFieldVisitor {
|
||||
type Value = DecomposedField;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<DecomposedField, E>
|
||||
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>
|
||||
where E: serde::de::Error
|
||||
{
|
||||
match value {
|
||||
|
@ -246,9 +255,11 @@ mod eders_de {
|
|||
}
|
||||
|
||||
impl<S: VectorSpace, R> Deserialize for Decomposed<S, R>
|
||||
where S: Deserialize, S::Scalar: Deserialize, R: Deserialize
|
||||
where S: Deserialize,
|
||||
S::Scalar: Deserialize,
|
||||
R: Deserialize
|
||||
{
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Decomposed<S, R>, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<Decomposed<S, R>, D::Error>
|
||||
where D: serde::de::Deserializer
|
||||
{
|
||||
const FIELDS: &'static [&'static str] = &["scale", "rot", "disp"];
|
||||
|
@ -259,44 +270,57 @@ mod eders_de {
|
|||
struct DecomposedVisitor<S: VectorSpace, R>(PhantomData<(S, R)>);
|
||||
|
||||
impl<S: VectorSpace, R> serde::de::Visitor for DecomposedVisitor<S, R>
|
||||
where S: Deserialize, S::Scalar: Deserialize, R: Deserialize
|
||||
where S: Deserialize,
|
||||
S::Scalar: Deserialize,
|
||||
R: Deserialize
|
||||
{
|
||||
type Value = Decomposed<S, R>;
|
||||
|
||||
fn visit_map<V>(&mut self, mut visitor: V) -> Result<Decomposed<S, R>, V::Error>
|
||||
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>
|
||||
where V: serde::de::MapVisitor
|
||||
{
|
||||
let mut scale = None;
|
||||
let mut rot = None;
|
||||
let mut disp = None;
|
||||
|
||||
loop {
|
||||
match try!(visitor.visit_key()) {
|
||||
Some(DecomposedField::Scale) => { scale = Some(try!(visitor.visit_value())); },
|
||||
Some(DecomposedField::Rot) => { rot = Some(try!(visitor.visit_value())); },
|
||||
Some(DecomposedField::Disp) => { disp = Some(try!(visitor.visit_value())); },
|
||||
_ => { break; },
|
||||
while let Some(key) = visitor.visit_key()? {
|
||||
match key {
|
||||
DecomposedField::Scale => {
|
||||
scale = Some(visitor.visit_value()?);
|
||||
}
|
||||
DecomposedField::Rot => {
|
||||
rot = Some(visitor.visit_value()?);
|
||||
}
|
||||
DecomposedField::Disp => {
|
||||
disp = Some(visitor.visit_value()?);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let scale = match scale {
|
||||
Some(scale) => scale,
|
||||
None => try!(visitor.missing_field("scale")),
|
||||
None => return Err(serde::de::Error::missing_field("scale")),
|
||||
};
|
||||
|
||||
let rot = match rot {
|
||||
Some(rot) => rot,
|
||||
None => try!(visitor.missing_field("rot")),
|
||||
None => return Err(serde::de::Error::missing_field("rot")),
|
||||
};
|
||||
|
||||
let disp = match disp {
|
||||
Some(disp) => disp,
|
||||
None => try!(visitor.missing_field("disp")),
|
||||
None => return Err(serde::de::Error::missing_field("disp")),
|
||||
};
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok(Decomposed { scale: scale, rot: rot, disp: disp })
|
||||
Ok(Decomposed {
|
||||
scale: scale,
|
||||
rot: rot,
|
||||
disp: disp,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue