+// 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:
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]; }
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
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)
-{ return SGVec4f(v(0), v(1), v(2), v(3)); }
+{ return SGVec4f((float)v(0), (float)v(1), (float)v(2), (float)v(3)); }
inline
SGVec4d