From 2b36ea2ef981d7c12943a446fa25d42588cad3b9 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 8 Apr 2016 08:46:35 +1000 Subject: [PATCH] Rename Vector trait to VectorSpace and EuclideanVector to InnerSpace --- src/matrix.rs | 2 +- src/point.rs | 2 +- src/prelude.rs | 4 ++-- src/quaternion.rs | 2 +- src/rotation.rs | 2 +- src/transform.rs | 4 ++-- src/vector.rs | 38 +++++++++++++++++++------------------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/matrix.rs b/src/matrix.rs index aa1aaf2..e509dd2 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -31,7 +31,7 @@ use array::Array; use num::BaseFloat; use point::{Point, Point3}; use quaternion::Quaternion; -use vector::{Vector, EuclideanVector}; +use vector::{VectorSpace, InnerSpace}; use vector::{Vector2, Vector3, Vector4}; /// A 2 x 2, column major matrix diff --git a/src/point.rs b/src/point.rs index e35877c..a16059b 100644 --- a/src/point.rs +++ b/src/point.rs @@ -143,7 +143,7 @@ pub trait Point: Copy + Clone where type Scalar: BaseNum; /// The associated space of displacement vectors. - type Vector: Vector; + type Vector: VectorSpace; /// The point at the origin of the Euclidean space. fn origin() -> Self; diff --git a/src/prelude.rs b/src/prelude.rs index edbfc0f..1378f96 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -20,5 +20,5 @@ pub use transform::Transform; pub use transform::Transform2; pub use transform::Transform3; -pub use vector::EuclideanVector; -pub use vector::Vector; +pub use vector::InnerSpace; +pub use vector::VectorSpace; diff --git a/src/quaternion.rs b/src/quaternion.rs index 880359d..9a04f92 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -26,7 +26,7 @@ use matrix::{Matrix3, Matrix4}; use num::BaseFloat; use point::Point3; use rotation::{Rotation, Rotation3, Basis3}; -use vector::{Vector3, Vector, EuclideanVector}; +use vector::{Vector3, VectorSpace, InnerSpace}; /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector diff --git a/src/rotation.rs b/src/rotation.rs index 614a5ac..bff231c 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -22,7 +22,7 @@ use matrix::{Matrix2, Matrix3}; use num::BaseFloat; use point::{Point, Point2, Point3}; use quaternion::Quaternion; -use vector::{EuclideanVector, Vector2, Vector3}; +use vector::{InnerSpace, Vector2, Vector3}; /// A trait for a generic rotation. A rotation is a transformation that /// creates a circular motion, and preserves at least one point in the space. diff --git a/src/transform.rs b/src/transform.rs index 59e6826..7896c8f 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -72,7 +72,7 @@ pub trait Transform: Sized { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. #[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct Decomposed { +pub struct Decomposed { pub scale: V::Scalar, pub rot: R, pub disp: V, @@ -82,7 +82,7 @@ impl> Transform

for Decomposed where // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092

::Scalar: BaseFloat, // FIXME: Investigate why this is needed! -

::Vector: Vector, +

::Vector: VectorSpace, { #[inline] fn one() -> Decomposed { diff --git a/src/vector.rs b/src/vector.rs index 659527f..ffbeff6 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -22,7 +22,7 @@ //! vector are also provided: //! //! ```rust -//! use cgmath::{Vector, Vector2, Vector3, Vector4, vec3}; +//! use cgmath::{VectorSpace, Vector2, Vector3, Vector4, vec3}; //! //! assert_eq!(Vector2::new(1.0f64, 0.0f64), Vector2::unit_x()); //! assert_eq!(vec3(0.0f64, 0.0f64, 0.0f64), Vector3::zero()); @@ -33,7 +33,7 @@ //! using the built-in operators. //! //! ```rust -//! use cgmath::{Vector, Vector2, Vector3, Vector4}; +//! use cgmath::{VectorSpace, Vector2, Vector3, Vector4}; //! //! let a: Vector2 = Vector2::new(3.0, 4.0); //! let b: Vector2 = Vector2::new(-3.0, -4.0); @@ -61,7 +61,7 @@ //! and [cross products](http://en.wikipedia.org/wiki/Cross_product). //! //! ```rust -//! use cgmath::{Vector, EuclideanVector}; +//! use cgmath::{VectorSpace, InnerSpace}; //! use cgmath::{Vector2, Vector3, Vector4}; //! //! // All vectors implement the dot product as a method: @@ -83,9 +83,9 @@ //! the methods provided by the [`Array`](../array/trait.Array.html) trait. //! This trait also provides a `map()` method for applying arbitrary functions. //! -//! The [`Vector`](../trait.Vector.html) trait presents the most general -//! features of the vectors, while [`EuclideanVector`] -//! (../array/trait.EuclideanVector.html) is more specific to Euclidean space. +//! The [`VectorSpace`](../trait.VectorSpace.html) trait presents the most +//! general features of the vectors, while [`InnerSpace`] +//! (../array/trait.InnerSpace.html) is more specific to Euclidean space. use std::fmt; use std::mem; @@ -143,16 +143,16 @@ use num::{BaseNum, BaseFloat, PartialOrd}; /// let upscaled_translation = translation * scale_factor; /// let downscaled_translation = translation / scale_factor; /// ``` -pub trait Vector: Copy + Clone where +pub trait VectorSpace: Copy + Clone where // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 - Self: Array::Scalar>, + Self: Array::Scalar>, Self: Add, Self: Sub, - Self: Mul<::Scalar, Output = Self>, - Self: Div<::Scalar, Output = Self>, - Self: Rem<::Scalar, Output = Self>, + Self: Mul<::Scalar, Output = Self>, + Self: Div<::Scalar, Output = Self>, + Self: Rem<::Scalar, Output = Self>, { /// The associated scalar. type Scalar: BaseNum; @@ -267,7 +267,7 @@ macro_rules! impl_vector { } } - impl Vector for $VectorN { + impl VectorSpace for $VectorN { type Scalar = S; #[inline] @@ -530,10 +530,10 @@ impl Vector4 { /// /// The dot product allows for the definition of other useful operations, like /// finding the magnitude of a vector or normalizing it. -pub trait EuclideanVector: Vector + Sized where +pub trait InnerSpace: VectorSpace + Sized where // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 - ::Scalar: BaseFloat, - Self: ApproxEq::Scalar>, + ::Scalar: BaseFloat, + Self: ApproxEq::Scalar>, { /// Vector dot (or inner) product. fn dot(self, other: Self) -> Self::Scalar; @@ -593,13 +593,13 @@ pub trait EuclideanVector: Vector + Sized where /// Dot product of two vectors. #[inline] -pub fn dot(a: V, b: V) -> V::Scalar where +pub fn dot(a: V, b: V) -> V::Scalar where V::Scalar: BaseFloat, { V::dot(a, b) } -impl EuclideanVector for Vector2 { +impl InnerSpace for Vector2 { #[inline] fn dot(self, other: Vector2) -> S { Vector2::mul_element_wise(self, other).sum() @@ -611,7 +611,7 @@ impl EuclideanVector for Vector2 { } } -impl EuclideanVector for Vector3 { +impl InnerSpace for Vector3 { #[inline] fn dot(self, other: Vector3) -> S { Vector3::mul_element_wise(self, other).sum() @@ -623,7 +623,7 @@ impl EuclideanVector for Vector3 { } } -impl EuclideanVector for Vector4 { +impl InnerSpace for Vector4 { #[inline] fn dot(self, other: Vector4) -> S { Vector4::mul_element_wise(self, other).sum()