[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN helpers.h doc/documentation.h test/normali...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN helpers.h doc/documentation.h test/normali... |
Date: |
Thu, 16 Apr 2009 17:59:09 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/04/16 17:59:09
Modified files:
. : helpers.h
doc : documentation.h
Added files:
test : normalize_test2.cc
Log message:
Fixed normalize() to work on all kinds of vector.
Updated documentation.
Added normalize test program.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/test/normalize_test2.cc?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/TooN/doc/documentation.h?cvsroot=toon&r1=1.16&r2=1.17
Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- helpers.h 16 Apr 2009 17:33:55 -0000 1.49
+++ helpers.h 16 Apr 2009 17:59:09 -0000 1.50
@@ -68,9 +68,23 @@
return v * (1/sqrt(v*v));
}
- template<int Size, class Precision, class Base> inline void
normalize(Vector<Size, Precision, Base> & v)
+ //Note because of the overload later, this function will ONLY receive
sliced vectors. Therefore
+ //a copy can be made, which is still a slice, so operating on the copy
operates on the original
+ //data.
+ ///Normalize a vector in place
+ ///@param v Vector to normalize
+ ///@ingroup gLinAlg
+ template<int Size, class Precision, class Base> inline void
normalize(Vector<Size, Precision, Base> v)
{
- v /= std::sqrt(v*v);
+ using std::sqrt;
+ v /= sqrt(v*v);
+ }
+
+ //This overload is required to operate on non-slice vectors
+ ///@overload
+ template<int Size, class Precision> inline void normalize(Vector<Size,
Precision> & v)
+ {
+ normalize(v.as_slice());
}
template<int Size, typename Precision, typename Base> inline
Vector<Size-1, Precision> project( const Vector<Size, Precision, Base> & v){
Index: doc/documentation.h
===================================================================
RCS file: /cvsroot/toon/TooN/doc/documentation.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- doc/documentation.h 15 Apr 2009 15:50:35 -0000 1.16
+++ doc/documentation.h 16 Apr 2009 17:59:09 -0000 1.17
@@ -328,7 +328,7 @@
void func(Vector<3>& v) //This will catch any non-slices and
forward them on.
{
- func(v.slice<0,3>());
+ func(v.as_slice());
}
@endcode
Index: test/normalize_test2.cc
===================================================================
RCS file: test/normalize_test2.cc
diff -N test/normalize_test2.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/normalize_test2.cc 16 Apr 2009 17:59:08 -0000 1.1
@@ -0,0 +1,38 @@
+#include <TooN/helpers.h>
+
+using namespace std;
+using namespace TooN;
+
+int main()
+{
+ {
+ Vector<4> v;
+
+ v = makeVector(1,1,1,1);
+ normalize(v);
+ cout << v << endl;
+
+ v = makeVector(1,1,1,1);
+ normalize(v.slice<0,2>());
+ cout << v << endl;
+
+ v = makeVector(1,1,1,1);
+ normalize(v.slice(0,3));
+ cout << v << endl;
+ }
+
+ {
+ Vector<> v = makeVector(1,1,1,1);
+
+ normalize(v);
+ cout << v << endl;
+
+ v = makeVector(1,1,1,1);
+ normalize(v.slice<0,2>());
+ cout << v << endl;
+
+ v = makeVector(1,1,1,1);
+ normalize(v.slice(0,3));
+ cout << v << endl;
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN helpers.h doc/documentation.h test/normali...,
Edward Rosten <=