Rename Point to EuclideanSpace

This commit is contained in:
Brendan Zabarauskas 2016-04-08 19:56:30 +10:00
parent b5f8e7646b
commit b4063ea72a
5 changed files with 25 additions and 25 deletions

View file

@ -29,7 +29,7 @@ use angle::{Angle, Rad};
use approx::ApproxEq;
use array::Array;
use num::BaseFloat;
use point::{Point, Point3};
use point::{EuclideanSpace, Point3};
use quaternion::Quaternion;
use vector::{VectorSpace, InnerSpace};
use vector::{Vector2, Vector3, Vector4};

View file

@ -116,25 +116,25 @@ impl<S: BaseNum> Point3<S> {
/// ## Converting between points and vectors
///
/// Points can be converted to and from displacement vectors using the
/// `Point::{from_vec, to_vec}` methods. Note that under the hood these are
/// implemented as inlined a type conversion, so should not have any performance
/// implications.
/// `EuclideanSpace::{from_vec, to_vec}` methods. Note that under the hood these
/// are implemented as inlined a type conversion, so should not have any
/// performance implications.
///
/// ## References
///
/// - [CGAL 4.7 - 2D and 3D Linear Geometry Kernel: 3.1 Points and Vectors](http://doc.cgal.org/latest/Kernel_23/index.html#Kernel_23PointsandVectors)
/// - [What is the difference between a point and a vector](http://math.stackexchange.com/q/645827)
///
pub trait Point: Copy + Clone where
pub trait EuclideanSpace: Copy + Clone where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: Array<Element = <Self as Point>::Scalar>,
Self: Array<Element = <Self as EuclideanSpace>::Scalar>,
Self: Add<<Self as Point>::Diff, Output = Self>,
Self: Sub<Self, Output = <Self as Point>::Diff>,
Self: Add<<Self as EuclideanSpace>::Diff, Output = Self>,
Self: Sub<Self, Output = <Self as EuclideanSpace>::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>,
Self: Mul<<Self as EuclideanSpace>::Scalar, Output = Self>,
Self: Div<<Self as EuclideanSpace>::Scalar, Output = Self>,
Self: Rem<<Self as EuclideanSpace>::Scalar, Output = Self>,
{
/// The associated scalar over which the space is defined.
///
@ -195,7 +195,7 @@ macro_rules! impl_point {
}
}
impl<S: BaseNum> Point for $PointN<S> {
impl<S: BaseNum> EuclideanSpace for $PointN<S> {
type Scalar = S;
type Diff = $VectorN<S>;

View file

@ -10,7 +10,7 @@ pub use array::ElementWise;
pub use matrix::Matrix;
pub use matrix::SquareMatrix;
pub use point::Point;
pub use point::EuclideanSpace;
pub use rotation::Rotation;
pub use rotation::Rotation2;

View file

@ -20,16 +20,16 @@ use approx::ApproxEq;
use matrix::SquareMatrix;
use matrix::{Matrix2, Matrix3};
use num::BaseFloat;
use point::{Point, Point2, Point3};
use point::{EuclideanSpace, Point2, Point3};
use quaternion::Quaternion;
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.
pub trait Rotation<P: Point>: PartialEq + Sized where
pub trait Rotation<P: EuclideanSpace>: PartialEq + Sized where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: ApproxEq<Epsilon = <P as Point>::Scalar>,
<P as Point>::Scalar: BaseFloat,
Self: ApproxEq<Epsilon = <P as EuclideanSpace>::Scalar>,
<P as EuclideanSpace>::Scalar: BaseFloat,
{
/// Create the identity transform (causes no transformation).
fn one() -> Self;

View file

@ -27,7 +27,7 @@ use vector::*;
/// 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
pub trait Transform<P: Point>: Sized {
pub trait Transform<P: EuclideanSpace>: Sized {
/// Create an identity transformation. That is, a transformation which
/// does nothing.
fn one() -> Self;
@ -78,16 +78,16 @@ pub struct Decomposed<V: VectorSpace, R> {
pub disp: V,
}
impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R> where
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 Point>::Scalar: BaseFloat,
<P as EuclideanSpace>::Scalar: BaseFloat,
// FIXME: Investigate why this is needed!
<P as Point>::Diff: VectorSpace,
<P as EuclideanSpace>::Diff: VectorSpace,
{
#[inline]
fn one() -> Decomposed<P::Diff, R> {
Decomposed {
scale: <P as Point>::Scalar::one(),
scale: <P as EuclideanSpace>::Scalar::one(),
rot: R::one(),
disp: P::Diff::zero(),
}
@ -98,7 +98,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R> where
let rot = R::look_at(center - eye, up);
let disp = rot.rotate_vector(P::origin() - eye);
Decomposed {
scale: <P as Point>::Scalar::one(),
scale: <P as EuclideanSpace>::Scalar::one(),
rot: rot,
disp: disp,
}
@ -123,10 +123,10 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Diff, R> where
}
fn invert(&self) -> Option<Decomposed<P::Diff, R>> {
if self.scale.approx_eq(&<P as Point>::Scalar::zero()) {
if self.scale.approx_eq(&<P as EuclideanSpace>::Scalar::zero()) {
None
} else {
let s = <P as Point>::Scalar::one() / self.scale;
let s = <P as EuclideanSpace>::Scalar::one() / self.scale;
let r = self.rot.invert();
let d = r.rotate_vector(self.disp.clone()) * -s;
Some(Decomposed {