From ea98ef15b7faf4caa7b01f794d4e6bb3a9aca7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 8 Sep 2013 18:29:51 +0200 Subject: [PATCH] Implement `Norm` and `Dot` for `DVec`. --- src/dvec.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/dvec.rs b/src/dvec.rs index 7a0455b3..9d16988e 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -3,6 +3,8 @@ use std::vec; use std::vec::{VecIterator, VecMutIterator}; use std::cmp::ApproxEq; use std::iterator::FromIterator; +use traits::dot::Dot; +use traits::norm::Norm; use traits::iterable::{Iterable, IterableMut}; use traits::translation::Translation; use traits::scalar_op::{ScalarAdd, ScalarSub}; @@ -173,10 +175,9 @@ impl> Neg> for DVec { } } -impl DVec { - /// Will change soon. +impl Dot for DVec { #[inline] - pub fn dot(&self, other: &DVec) -> N { + fn dot(&self, other: &DVec) -> N { assert!(self.at.len() == other.at.len()); let mut res: N = Zero::zero(); @@ -188,9 +189,8 @@ impl DVec { res } - /// Will change soon. #[inline] - pub fn sub_dot(&self, a: &DVec, b: &DVec) -> N { + fn sub_dot(&self, a: &DVec, b: &DVec) -> N { let mut res: N = Zero::zero(); for i in range(0u, self.at.len()) { @@ -271,22 +271,19 @@ impl + Neg + Clone> Translation> for DVec { } } -impl DVec { - /// Will change soon. +impl Norm for DVec { #[inline] - pub fn sqnorm(&self) -> N { + fn sqnorm(&self) -> N { self.dot(self) } - /// Will change soon. #[inline] - pub fn norm(&self) -> N { + fn norm(&self) -> N { self.sqnorm().sqrt() } - /// Will change soon. #[inline] - pub fn normalized(&self) -> DVec { + fn normalized(&self) -> DVec { let mut res : DVec = self.clone(); res.normalize(); @@ -294,9 +291,8 @@ impl DVec { res } - /// Will change soon. #[inline] - pub fn normalize(&mut self) -> N { + fn normalize(&mut self) -> N { let l = self.norm(); for i in range(0u, self.at.len()) {