Remove operator methods from Point trait
This commit is contained in:
parent
4c62ef4efb
commit
d468d76e0a
2 changed files with 10 additions and 47 deletions
51
src/point.rs
51
src/point.rs
|
@ -69,14 +69,13 @@ impl<S: BaseNum> Point3<S> {
|
||||||
pub trait Point: Copy + Clone where
|
pub trait Point: 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 Point>::Scalar>,
|
Self: Array<Element = <Self as Point>::Scalar>,
|
||||||
// FIXME: blocked by rust-lang/rust#20671
|
|
||||||
//
|
Self: Add<<Self as Point>::Vector, Output = Self>,
|
||||||
// for<'a, 'b> &'a Self: Add<&'b V, Output = Self>,
|
Self: Sub<Self, Output = <Self as Point>::Vector>,
|
||||||
// for<'a, 'b> &'a Self: Sub<&'b Self, Output = V>,
|
|
||||||
//
|
Self: Mul<<Self as Point>::Scalar, Output = Self>,
|
||||||
// for<'a> &'a Self: Mul<S, Output = Self>,
|
Self: Div<<Self as Point>::Scalar, Output = Self>,
|
||||||
// for<'a> &'a Self: Div<S, Output = Self>,
|
Self: Rem<<Self as Point>::Scalar, Output = Self>,
|
||||||
// for<'a> &'a Self: Rem<S, Output = Self>,
|
|
||||||
{
|
{
|
||||||
/// The associated scalar.
|
/// The associated scalar.
|
||||||
///
|
///
|
||||||
|
@ -94,32 +93,6 @@ pub trait Point: Copy + Clone where
|
||||||
/// Convert a point to a vector.
|
/// Convert a point to a vector.
|
||||||
fn to_vec(self) -> Self::Vector;
|
fn to_vec(self) -> Self::Vector;
|
||||||
|
|
||||||
/// Multiply each component by a scalar, returning the new point.
|
|
||||||
#[must_use]
|
|
||||||
fn mul_s(self, scalar: Self::Scalar) -> Self;
|
|
||||||
/// Divide each component by a scalar, returning the new point.
|
|
||||||
#[must_use]
|
|
||||||
fn div_s(self, scalar: Self::Scalar) -> Self;
|
|
||||||
/// Subtract a scalar from each component, returning the new point.
|
|
||||||
#[must_use]
|
|
||||||
fn rem_s(self, scalar: Self::Scalar) -> Self;
|
|
||||||
|
|
||||||
/// Add a vector to this point, returning the new point.
|
|
||||||
#[must_use]
|
|
||||||
fn add_v(self, v: Self::Vector) -> Self;
|
|
||||||
/// Subtract another point from this one, returning a new vector.
|
|
||||||
fn sub_p(self, p: Self) -> Self::Vector;
|
|
||||||
|
|
||||||
/// Multiply each component by a scalar, in-place.
|
|
||||||
fn mul_self_s(&mut self, scalar: Self::Scalar);
|
|
||||||
/// Divide each component by a scalar, in-place.
|
|
||||||
fn div_self_s(&mut self, scalar: Self::Scalar);
|
|
||||||
/// Take the remainder of each component by a scalar, in-place.
|
|
||||||
fn rem_self_s(&mut self, scalar: Self::Scalar);
|
|
||||||
|
|
||||||
/// Add a vector to this point, in-place.
|
|
||||||
fn add_self_v(&mut self, v: Self::Vector);
|
|
||||||
|
|
||||||
/// This is a weird one, but its useful for plane calculations.
|
/// This is a weird one, but its useful for plane calculations.
|
||||||
fn dot(self, v: Self::Vector) -> Self::Scalar;
|
fn dot(self, v: Self::Vector) -> Self::Scalar;
|
||||||
}
|
}
|
||||||
|
@ -154,16 +127,6 @@ macro_rules! impl_point {
|
||||||
$VectorN::new($(self.$field),+)
|
$VectorN::new($(self.$field),+)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline] fn mul_s(self, scalar: S) -> $PointN<S> { self * scalar }
|
|
||||||
#[inline] fn div_s(self, scalar: S) -> $PointN<S> { self / scalar }
|
|
||||||
#[inline] fn rem_s(self, scalar: S) -> $PointN<S> { self % scalar }
|
|
||||||
#[inline] fn add_v(self, v: $VectorN<S>) -> $PointN<S> { self + v }
|
|
||||||
#[inline] fn sub_p(self, p: $PointN<S>) -> $VectorN<S> { self - p }
|
|
||||||
#[inline] fn mul_self_s(&mut self, scalar: S) { *self = *self * scalar; }
|
|
||||||
#[inline] fn div_self_s(&mut self, scalar: S) { *self = *self / scalar; }
|
|
||||||
#[inline] fn rem_self_s(&mut self, scalar: S) { *self = *self % scalar; }
|
|
||||||
#[inline] fn add_self_v(&mut self, vector: $VectorN<S>) { *self = *self + vector; }
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dot(self, v: $VectorN<S>) -> S {
|
fn dot(self, v: $VectorN<S>) -> S {
|
||||||
$VectorN::new($(self.$field * v.$field),+).sum()
|
$VectorN::new($(self.$field * v.$field),+).sum()
|
||||||
|
|
|
@ -93,8 +93,8 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn look_at(eye: P, center: P, up: P::Vector) -> Decomposed<P::Vector, R> {
|
fn look_at(eye: P, center: P, up: P::Vector) -> Decomposed<P::Vector, R> {
|
||||||
let rot = R::look_at(center.sub_p(eye.clone()), up);
|
let rot = R::look_at(center - eye, up);
|
||||||
let disp = rot.rotate_vector(P::origin().sub_p(eye));
|
let disp = rot.rotate_vector(P::origin() - eye);
|
||||||
Decomposed {
|
Decomposed {
|
||||||
scale: <P as Point>::Scalar::one(),
|
scale: <P as Point>::Scalar::one(),
|
||||||
rot: rot,
|
rot: rot,
|
||||||
|
@ -109,7 +109,7 @@ impl<P: Point, R: Rotation<P>> Transform<P> for Decomposed<P::Vector, R> where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_point(&self, point: P) -> P {
|
fn transform_point(&self, point: P) -> P {
|
||||||
self.rot.rotate_point(point.mul_s(self.scale)).add_v(self.disp.clone())
|
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::Vector, R>) -> Decomposed<P::Vector, R> {
|
||||||
|
|
Loading…
Reference in a new issue