Rename Vector trait to VectorSpace and EuclideanVector to InnerSpace
This commit is contained in:
parent
cfeb001ea7
commit
2b36ea2ef9
7 changed files with 27 additions and 27 deletions
|
@ -31,7 +31,7 @@ use array::Array;
|
||||||
use num::BaseFloat;
|
use num::BaseFloat;
|
||||||
use point::{Point, Point3};
|
use point::{Point, Point3};
|
||||||
use quaternion::Quaternion;
|
use quaternion::Quaternion;
|
||||||
use vector::{Vector, EuclideanVector};
|
use vector::{VectorSpace, InnerSpace};
|
||||||
use vector::{Vector2, Vector3, Vector4};
|
use vector::{Vector2, Vector3, Vector4};
|
||||||
|
|
||||||
/// A 2 x 2, column major matrix
|
/// A 2 x 2, column major matrix
|
||||||
|
|
|
@ -143,7 +143,7 @@ pub trait Point: Copy + Clone where
|
||||||
type Scalar: BaseNum;
|
type Scalar: BaseNum;
|
||||||
|
|
||||||
/// The associated space of displacement vectors.
|
/// The associated space of displacement vectors.
|
||||||
type Vector: Vector<Scalar = Self::Scalar>;
|
type Vector: VectorSpace<Scalar = Self::Scalar>;
|
||||||
|
|
||||||
/// The point at the origin of the Euclidean space.
|
/// The point at the origin of the Euclidean space.
|
||||||
fn origin() -> Self;
|
fn origin() -> Self;
|
||||||
|
|
|
@ -20,5 +20,5 @@ pub use transform::Transform;
|
||||||
pub use transform::Transform2;
|
pub use transform::Transform2;
|
||||||
pub use transform::Transform3;
|
pub use transform::Transform3;
|
||||||
|
|
||||||
pub use vector::EuclideanVector;
|
pub use vector::InnerSpace;
|
||||||
pub use vector::Vector;
|
pub use vector::VectorSpace;
|
||||||
|
|
|
@ -26,7 +26,7 @@ use matrix::{Matrix3, Matrix4};
|
||||||
use num::BaseFloat;
|
use num::BaseFloat;
|
||||||
use point::Point3;
|
use point::Point3;
|
||||||
use rotation::{Rotation, Rotation3, Basis3};
|
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
|
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
||||||
|
|
|
@ -22,7 +22,7 @@ use matrix::{Matrix2, Matrix3};
|
||||||
use num::BaseFloat;
|
use num::BaseFloat;
|
||||||
use point::{Point, Point2, Point3};
|
use point::{Point, Point2, Point3};
|
||||||
use quaternion::Quaternion;
|
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
|
/// 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.
|
/// creates a circular motion, and preserves at least one point in the space.
|
||||||
|
|
|
@ -72,7 +72,7 @@ pub trait Transform<P: Point>: Sized {
|
||||||
/// A generic transformation consisting of a rotation,
|
/// A generic transformation consisting of a rotation,
|
||||||
/// displacement vector and scale amount.
|
/// displacement vector and scale amount.
|
||||||
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Decomposed<V: Vector, R> {
|
pub struct Decomposed<V: VectorSpace, R> {
|
||||||
pub scale: V::Scalar,
|
pub scale: V::Scalar,
|
||||||
pub rot: R,
|
pub rot: R,
|
||||||
pub disp: V,
|
pub disp: V,
|
||||||
|
@ -82,7 +82,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
|
||||||
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
|
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
|
||||||
<P as Point>::Scalar: BaseFloat,
|
<P as Point>::Scalar: BaseFloat,
|
||||||
// FIXME: Investigate why this is needed!
|
// FIXME: Investigate why this is needed!
|
||||||
<P as Point>::Vector: Vector,
|
<P as Point>::Vector: VectorSpace,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Decomposed<P::Vector, R> {
|
fn one() -> Decomposed<P::Vector, R> {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
//! vector are also provided:
|
//! vector are also provided:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```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!(Vector2::new(1.0f64, 0.0f64), Vector2::unit_x());
|
||||||
//! assert_eq!(vec3(0.0f64, 0.0f64, 0.0f64), Vector3::zero());
|
//! assert_eq!(vec3(0.0f64, 0.0f64, 0.0f64), Vector3::zero());
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
//! using the built-in operators.
|
//! using the built-in operators.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use cgmath::{Vector, Vector2, Vector3, Vector4};
|
//! use cgmath::{VectorSpace, Vector2, Vector3, Vector4};
|
||||||
//!
|
//!
|
||||||
//! let a: Vector2<f64> = Vector2::new(3.0, 4.0);
|
//! let a: Vector2<f64> = Vector2::new(3.0, 4.0);
|
||||||
//! let b: Vector2<f64> = Vector2::new(-3.0, -4.0);
|
//! let b: Vector2<f64> = Vector2::new(-3.0, -4.0);
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
//! and [cross products](http://en.wikipedia.org/wiki/Cross_product).
|
//! and [cross products](http://en.wikipedia.org/wiki/Cross_product).
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use cgmath::{Vector, EuclideanVector};
|
//! use cgmath::{VectorSpace, InnerSpace};
|
||||||
//! use cgmath::{Vector2, Vector3, Vector4};
|
//! use cgmath::{Vector2, Vector3, Vector4};
|
||||||
//!
|
//!
|
||||||
//! // All vectors implement the dot product as a method:
|
//! // All vectors implement the dot product as a method:
|
||||||
|
@ -83,9 +83,9 @@
|
||||||
//! the methods provided by the [`Array`](../array/trait.Array.html) trait.
|
//! the methods provided by the [`Array`](../array/trait.Array.html) trait.
|
||||||
//! This trait also provides a `map()` method for applying arbitrary functions.
|
//! This trait also provides a `map()` method for applying arbitrary functions.
|
||||||
//!
|
//!
|
||||||
//! The [`Vector`](../trait.Vector.html) trait presents the most general
|
//! The [`VectorSpace`](../trait.VectorSpace.html) trait presents the most
|
||||||
//! features of the vectors, while [`EuclideanVector`]
|
//! general features of the vectors, while [`InnerSpace`]
|
||||||
//! (../array/trait.EuclideanVector.html) is more specific to Euclidean space.
|
//! (../array/trait.InnerSpace.html) is more specific to Euclidean space.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -143,16 +143,16 @@ use num::{BaseNum, BaseFloat, PartialOrd};
|
||||||
/// let upscaled_translation = translation * scale_factor;
|
/// let upscaled_translation = translation * scale_factor;
|
||||||
/// let downscaled_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
|
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
|
||||||
Self: Array<Element = <Self as Vector>::Scalar>,
|
Self: Array<Element = <Self as VectorSpace>::Scalar>,
|
||||||
|
|
||||||
Self: Add<Self, Output = Self>,
|
Self: Add<Self, Output = Self>,
|
||||||
Self: Sub<Self, Output = Self>,
|
Self: Sub<Self, Output = Self>,
|
||||||
|
|
||||||
Self: Mul<<Self as Vector>::Scalar, Output = Self>,
|
Self: Mul<<Self as VectorSpace>::Scalar, Output = Self>,
|
||||||
Self: Div<<Self as Vector>::Scalar, Output = Self>,
|
Self: Div<<Self as VectorSpace>::Scalar, Output = Self>,
|
||||||
Self: Rem<<Self as Vector>::Scalar, Output = Self>,
|
Self: Rem<<Self as VectorSpace>::Scalar, Output = Self>,
|
||||||
{
|
{
|
||||||
/// The associated scalar.
|
/// The associated scalar.
|
||||||
type Scalar: BaseNum;
|
type Scalar: BaseNum;
|
||||||
|
@ -267,7 +267,7 @@ macro_rules! impl_vector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> Vector for $VectorN<S> {
|
impl<S: BaseNum> VectorSpace for $VectorN<S> {
|
||||||
type Scalar = S;
|
type Scalar = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -530,10 +530,10 @@ impl<S: BaseNum> Vector4<S> {
|
||||||
///
|
///
|
||||||
/// The dot product allows for the definition of other useful operations, like
|
/// The dot product allows for the definition of other useful operations, like
|
||||||
/// finding the magnitude of a vector or normalizing it.
|
/// 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
|
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
|
||||||
<Self as Vector>::Scalar: BaseFloat,
|
<Self as VectorSpace>::Scalar: BaseFloat,
|
||||||
Self: ApproxEq<Epsilon = <Self as Vector>::Scalar>,
|
Self: ApproxEq<Epsilon = <Self as VectorSpace>::Scalar>,
|
||||||
{
|
{
|
||||||
/// Vector dot (or inner) product.
|
/// Vector dot (or inner) product.
|
||||||
fn dot(self, other: Self) -> Self::Scalar;
|
fn dot(self, other: Self) -> Self::Scalar;
|
||||||
|
@ -593,13 +593,13 @@ pub trait EuclideanVector: Vector + Sized where
|
||||||
|
|
||||||
/// Dot product of two vectors.
|
/// Dot product of two vectors.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn dot<V: EuclideanVector>(a: V, b: V) -> V::Scalar where
|
pub fn dot<V: InnerSpace>(a: V, b: V) -> V::Scalar where
|
||||||
V::Scalar: BaseFloat,
|
V::Scalar: BaseFloat,
|
||||||
{
|
{
|
||||||
V::dot(a, b)
|
V::dot(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> EuclideanVector for Vector2<S> {
|
impl<S: BaseFloat> InnerSpace for Vector2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dot(self, other: Vector2<S>) -> S {
|
fn dot(self, other: Vector2<S>) -> S {
|
||||||
Vector2::mul_element_wise(self, other).sum()
|
Vector2::mul_element_wise(self, other).sum()
|
||||||
|
@ -611,7 +611,7 @@ impl<S: BaseFloat> EuclideanVector for Vector2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> EuclideanVector for Vector3<S> {
|
impl<S: BaseFloat> InnerSpace for Vector3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dot(self, other: Vector3<S>) -> S {
|
fn dot(self, other: Vector3<S>) -> S {
|
||||||
Vector3::mul_element_wise(self, other).sum()
|
Vector3::mul_element_wise(self, other).sum()
|
||||||
|
@ -623,7 +623,7 @@ impl<S: BaseFloat> EuclideanVector for Vector3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> EuclideanVector for Vector4<S> {
|
impl<S: BaseFloat> InnerSpace for Vector4<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dot(self, other: Vector4<S>) -> S {
|
fn dot(self, other: Vector4<S>) -> S {
|
||||||
Vector4::mul_element_wise(self, other).sum()
|
Vector4::mul_element_wise(self, other).sum()
|
||||||
|
|
Loading…
Reference in a new issue