← Back to team overview

nrtb-core team mailing list archive

[Branch ~fpstovall/nrtb/cpp_common] Rev 42: Fix for bug 814217; added dot and vector products to the triad template and approriate unit tests.

 

------------------------------------------------------------
revno: 42
committer: fpstovall@xxxxxxxxx
branch nick: dev
timestamp: Tue 2011-07-26 22:27:23 -0400
message:
  Fix for bug 814217; added dot and vector products to the triad template and approriate unit tests.
  With this change, the triad template should now be ready for use.
modified:
  common/point/common_test.cpp
  common/point/triad.h


--
lp:~fpstovall/nrtb/cpp_common
https://code.launchpad.net/~fpstovall/nrtb/cpp_common

Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/cpp_common.
To unsubscribe from this branch go to https://code.launchpad.net/~fpstovall/nrtb/cpp_common/+edit-subscription
=== modified file 'common/point/common_test.cpp'
--- common/point/common_test.cpp	2011-07-20 02:12:28 +0000
+++ common/point/common_test.cpp	2011-07-27 02:27:23 +0000
@@ -94,6 +94,10 @@
 	// normalization test
 	cout << "\ta.normalize() = " << a.normalize() << endl;
 	returnme = test_ld("a.normalize().magnatude()",a.normalize().magnatude(),1.0,returnme);
+	// dot and vector product tests.
+	returnme = test_ld("a.dot_product(b)",a.dot_product(b),10,returnme);
+	returnme = test_triad("a.vector_product(b)",a.vector_product(b),
+		ld_triad(-4,8,-4),returnme);
 	// string i/o tests, assumes "2,3.5,7) is input.
 	cout << "\tInput a new value for b \"(2,3.5,7)\": " << flush;
 	cin >> b; cout << endl;

=== modified file 'common/point/triad.h'
--- common/point/triad.h	2010-12-25 22:44:22 +0000
+++ common/point/triad.h	2011-07-27 02:27:23 +0000
@@ -92,6 +92,10 @@
 	T range(const triad<T> & a);
 	/// Returns the magnatude of the vector.
 	T magnatude();
+	/// Returns the dot (scalar) product of two triads
+	T dot_product(const triad<T> & a);
+	/// Returns the vector product of two triads
+	triad<T> vector_product(const triad<T> & a);
 	bool operator == (const triad<T> & a);
 	bool operator != (const triad<T> & a);
 	/// Loads from a std::string.
@@ -301,6 +305,26 @@
 };
 
 template <class T>
+T triad<T>::dot_product(const triad<T> & a)
+{
+  T returnme;
+  returnme = x * a.x;
+  returnme += y * a.y;
+  returnme += z * a.z;
+  return returnme;
+};
+
+template <class T>
+triad<T> triad<T>::vector_product(const triad<T> & a)
+{
+  triad<T> rv;
+  rv.x = (y * a.z) - (z * a.y);
+  rv.y = (z * a.x) - (x * a.z);
+  rv.z = (x * a.y) - (y * a.x);
+  return rv;
+};
+
+template <class T>
 bool triad<T>::operator == (const triad<T> & a)
 {
 	return ((x == a.x) && (y == a.y) && (z == a.z));