Rename Point::Vector to Point::Diff

This commit is contained in:
Brendan Zabarauskas 2016-04-08 15:35:11 +10:00
parent 2b36ea2ef9
commit b5f8e7646b
3 changed files with 25 additions and 25 deletions

View file

@ -79,7 +79,7 @@ impl<S: BaseNum> Point3<S> {
}
/// Points in a [Euclidean space](https://en.wikipedia.org/wiki/Euclidean_space)
/// with an associated vector space, `Self::Vector`.
/// with an associated space of displacement vectors.
///
/// # Point-Vector distinction
///
@ -129,21 +129,21 @@ pub trait Point: Copy + Clone where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: Array<Element = <Self as Point>::Scalar>,
Self: Add<<Self as Point>::Vector, Output = Self>,
Self: Sub<Self, Output = <Self as Point>::Vector>,
Self: Add<<Self as Point>::Diff, Output = Self>,
Self: Sub<Self, Output = <Self as Point>::Diff>,
Self: Mul<<Self as Point>::Scalar, Output = Self>,
Self: Div<<Self as Point>::Scalar, Output = Self>,
Self: Rem<<Self as Point>::Scalar, Output = Self>,
{
/// The associated scalar.
/// The associated scalar over which the space is defined.
///
/// Due to the equality constraints demanded by `Self::Vector`, this is effectively just an
/// alias to `Self::Vector::Scalar`.
/// Due to the equality constraints demanded by `Self::Diff`, this is effectively just an
/// alias to `Self::Diff::Scalar`.
type Scalar: BaseNum;
/// The associated space of displacement vectors.
type Vector: VectorSpace<Scalar = Self::Scalar>;
type Diff: VectorSpace<Scalar = Self::Scalar>;
/// The point at the origin of the Euclidean space.
fn origin() -> Self;
@ -152,16 +152,16 @@ pub trait Point: Copy + Clone where
///
/// This can be considered equivalent to the addition of the displacement
/// vector `v` to to `Self::origin()`.
fn from_vec(v: Self::Vector) -> Self;
fn from_vec(v: Self::Diff) -> Self;
/// Convert a point to a displacement vector.
///
/// This can be seen as equivalent to the displacement vector from
/// `Self::origin()` to `self`.
fn to_vec(self) -> Self::Vector;
fn to_vec(self) -> Self::Diff;
/// This is a weird one, but its useful for plane calculations.
fn dot(self, v: Self::Vector) -> Self::Scalar;
fn dot(self, v: Self::Diff) -> Self::Scalar;
}
macro_rules! impl_point {
@ -197,7 +197,7 @@ macro_rules! impl_point {
impl<S: BaseNum> Point for $PointN<S> {
type Scalar = S;
type Vector = $VectorN<S>;
type Diff = $VectorN<S>;
#[inline]
fn origin() -> $PointN<S> {

View file

@ -35,14 +35,14 @@ pub trait Rotation<P: Point>: PartialEq + Sized where
fn one() -> Self;
/// Create a rotation to a given direction with an 'up' vector
fn look_at(dir: P::Vector, up: P::Vector) -> Self;
fn look_at(dir: P::Diff, up: P::Diff) -> Self;
/// Create a shortest rotation to transform vector 'a' into 'b'.
/// Both given vectors are assumed to have unit length.
fn between_vectors(a: P::Vector, b: P::Vector) -> Self;
fn between_vectors(a: P::Diff, b: P::Diff) -> Self;
/// Rotate a vector using this rotation.
fn rotate_vector(&self, vec: P::Vector) -> P::Vector;
fn rotate_vector(&self, vec: P::Diff) -> P::Diff;
/// Rotate a point using this rotation, by converting it to its
/// representation as a vector.

View file

@ -34,17 +34,17 @@ pub trait Transform<P: Point>: Sized {
/// Create a transformation that rotates a vector to look at `center` from
/// `eye`, using `up` for orientation.
fn look_at(eye: P, center: P, up: P::Vector) -> Self;
fn look_at(eye: P, center: P, up: P::Diff) -> Self;
/// Transform a vector using this transform.
fn transform_vector(&self, vec: P::Vector) -> P::Vector;
fn transform_vector(&self, vec: P::Diff) -> P::Diff;
/// Transform a point using this transform.
fn transform_point(&self, point: P) -> P;
/// Transform a vector as a point using this transform.
#[inline]
fn transform_as_point(&self, vec: P::Vector) -> P::Vector {
fn transform_as_point(&self, vec: P::Diff) -> P::Diff {
self.transform_point(P::from_vec(vec)).to_vec()
}
@ -78,23 +78,23 @@ pub struct Decomposed<V: VectorSpace, R> {
pub disp: V,
}
impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R> where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
<P as Point>::Scalar: BaseFloat,
// FIXME: Investigate why this is needed!
<P as Point>::Vector: VectorSpace,
<P as Point>::Diff: VectorSpace,
{
#[inline]
fn one() -> Decomposed<P::Vector, R> {
fn one() -> Decomposed<P::Diff, R> {
Decomposed {
scale: <P as Point>::Scalar::one(),
rot: R::one(),
disp: P::Vector::zero(),
disp: P::Diff::zero(),
}
}
#[inline]
fn look_at(eye: P, center: P, up: P::Vector) -> Decomposed<P::Vector, R> {
fn look_at(eye: P, center: P, up: P::Diff) -> Decomposed<P::Diff, R> {
let rot = R::look_at(center - eye, up);
let disp = rot.rotate_vector(P::origin() - eye);
Decomposed {
@ -105,7 +105,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
}
#[inline]
fn transform_vector(&self, vec: P::Vector) -> P::Vector {
fn transform_vector(&self, vec: P::Diff) -> P::Diff {
self.rot.rotate_vector(vec * self.scale)
}
@ -114,7 +114,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
self.rot.rotate_point(point * self.scale) + self.disp
}
fn concat(&self, other: &Decomposed<P::Vector, R>) -> Decomposed<P::Vector, R> {
fn concat(&self, other: &Decomposed<P::Diff, R>) -> Decomposed<P::Diff, R> {
Decomposed {
scale: self.scale * other.scale,
rot: self.rot.concat(&other.rot),
@ -122,7 +122,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
}
}
fn invert(&self) -> Option<Decomposed<P::Vector, R>> {
fn invert(&self) -> Option<Decomposed<P::Diff, R>> {
if self.scale.approx_eq(&<P as Point>::Scalar::zero()) {
None
} else {