]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGVec4.hxx
Remove fastmath funktions like discussed on the list.
[simgear.git] / simgear / math / SGVec4.hxx
index 2e469e7fd1e60ebd0fa8b324a07655afb4b11d0e..feee964b4b5b57b68915e1be74db7f289a20ceef 100644 (file)
@@ -1,7 +1,24 @@
+// Copyright (C) 2006  Mathias Froehlich - Mathias.Froehlich@web.de
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+
 #ifndef SGVec4_H
 #define SGVec4_H
 
-/// 3D Vector Class
+/// 4D Vector Class
 template<typename T>
 class SGVec4 {
 public:
@@ -35,6 +52,13 @@ public:
   T& operator()(unsigned i)
   { return _data[i]; }
 
+  /// Access raw data by index, the index is unchecked
+  const T& operator[](unsigned i) const
+  { return _data[i]; }
+  /// Access raw data by index, the index is unchecked
+  T& operator[](unsigned i)
+  { return _data[i]; }
+
   /// Access the x component
   const T& x(void) const
   { return _data[0]; }
@@ -224,6 +248,20 @@ equivalent(const SGVec4<T>& v1, const SGVec4<T>& v2)
   return equivalent(v1, v2, tol, tol);
 }
 
+/// The euclidean distance of the two vectors
+template<typename T>
+inline
+T
+dist(const SGVec4<T>& v1, const SGVec4<T>& v2)
+{ return norm(v1 - v2); }
+
+/// The squared euclidean distance of the two vectors
+template<typename T>
+inline
+T
+distSqr(const SGVec4<T>& v1, const SGVec4<T>& v2)
+{ SGVec4<T> tmp = v1 - v2; return dot(tmp, tmp); }
+
 #ifndef NDEBUG
 template<typename T>
 inline
@@ -242,10 +280,6 @@ std::basic_ostream<char_type, traits_type>&
 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGVec4<T>& v)
 { return s << "[ " << v(0) << ", " << v(1) << ", " << v(2) << ", " << v(3) << " ]"; }
 
-/// Two classes doing actually the same on different types
-typedef SGVec4<float> SGVec4f;
-typedef SGVec4<double> SGVec4d;
-
 inline
 SGVec4f
 toVec4f(const SGVec4d& v)