# HG changeset patch # User Eris Caffee # Date 1317232122 18000 # Node ID 3788625551898faad1b86b8ac6e723f6f9af69ed # Parent 11e216148d1cf293eff7f7ddb4f1e1526255d9e2 Refactored Vectors into templated classes. Much nicer now. diff -r 11e216148d1c -r 378862555189 CMakeLists.txt --- a/CMakeLists.txt Tue Sep 06 11:26:39 2011 -0500 +++ b/CMakeLists.txt Wed Sep 28 12:48:42 2011 -0500 @@ -120,8 +120,16 @@ add_definitions(-pedantic -Wall) endif () +################################################################################ +# Other miscellaneous compiler options + +#if (CMAKE_COMPILER_IS_GNUCXX) +# # Allow anonymous structs +# add_definitions(-fms-extensions) +#endif () ################################################################################ +# Build for profiling. option(Option_Profile_Program "Build for gprof profiling." OFF) if (Option_Profile_Program) @@ -138,11 +146,8 @@ # test driver. Also, it just seems good practice to explicitly list things since # it avoids accidental inclusion of things that ought not to be included. set (SRCS_${App_Name} - src/Vector.cpp - src/Matrix.cpp include/Math.h include/Vector.h - include/Matrix.h ) include_directories ( @@ -162,19 +167,19 @@ # clobber each others temp files since they are being built from the same # sources. -add_library (${App_Name} SHARED - ${SRCS_${App_Name}} -) -set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name}) -set_target_properties (${App_Name} PROPERTIES PREFIX "lib") -set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1) - -add_library (${App_Name}-static STATIC - ${SRCS_${App_Name}} -) -set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name}) -set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib") -set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) +#add_library (${App_Name} SHARED +# ${SRCS_${App_Name}} +#) +#set_target_properties (${App_Name} PROPERTIES OUTPUT_NAME ${App_Name}) +#set_target_properties (${App_Name} PROPERTIES PREFIX "lib") +#set_target_properties (${App_Name} PROPERTIES CLEAN_DIRECT_OUTPUT 1) +# +#add_library (${App_Name}-static STATIC +# ${SRCS_${App_Name}} +#) +#set_target_properties (${App_Name}-static PROPERTIES OUTPUT_NAME ${App_Name}) +#set_target_properties (${App_Name}-static PROPERTIES PREFIX "lib") +#set_target_properties (${App_Name}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) # Build a test application. @@ -190,6 +195,6 @@ ) target_link_libraries (${App_Name}-test - ${App_Name} +# ${App_Name} ) diff -r 11e216148d1c -r 378862555189 include/Math.h --- a/include/Math.h Tue Sep 06 11:26:39 2011 -0500 +++ b/include/Math.h Wed Sep 28 12:48:42 2011 -0500 @@ -2,7 +2,7 @@ #define MATH_H_ #include "Vector.h" -#include "Matrix.h" +// #include "Matrix.h" namespace arda { diff -r 11e216148d1c -r 378862555189 include/Matrix.h --- a/include/Matrix.h Tue Sep 06 11:26:39 2011 -0500 +++ b/include/Matrix.h Wed Sep 28 12:48:42 2011 -0500 @@ -406,6 +406,115 @@ float * transpose4(Matrix4f m, Matrix4f mres); double * transpose4(Matrix4d m, Matrix4d mres); + ////////////////////////////////////////////////////////////////////////// + // det*(Matrix m) + // Computer the determinant of a matrix. + // Returns the determinant. + + inline double det2(Matrix2i m) + { return m[0] * m[3] - m[1] * m[2]; } + inline double det2(Matrix2f m) + { return m[0] * m[3] - m[1] * m[2]; } + inline double det2(Matrix2d m) + { return m[0] * m[3] - m[1] * m[2]; } + + inline double det3(Matrix3i m) + { return m[0] * ( m[4] * m[8] + - m[5] * m[7]) + - m[3] * ( m[1] * m[8] + - m[2] * m[7]) + + m[6] * ( m[1] * m[5] + - m[2] * m[4]); } + inline double det3(Matrix3f m) + { return m[0] * ( m[4] * m[8] + - m[5] * m[7]) + - m[3] * ( m[1] * m[8] + - m[2] * m[7]) + + m[6] * ( m[1] * m[5] + - m[2] * m[4]); } + inline double det3(Matrix3d m) + { return m[0] * ( m[4] * m[8] + - m[5] * m[7]) + - m[3] * ( m[1] * m[8] + - m[2] * m[7]) + + m[6] * (m[1] * m[5] + - m[2] * m[4]); } + + inline double det4(Matrix4i m) + { return m[0] * (m[5] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[6] * m[15] - + m[7] * m[14]) + + m[13] * (m[6] * m[11] - + m[7] * m[10])) - + m[4] * (m[1] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[11] - + m[3] * m[10])) + + m[8] * (m[1] * (m[6] * m[15] - + m[7] * m[14]) - + m[5] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[7] - + m[3] * m[6])) + + m[12] * (m[1] * (m[6] * m[11] - + m[7] * m[10]) - + m[5] * (m[2] * m[11] - + m[3] * m[10]) + + m[9] * (m[2] * m[7] - + m[3] * m[6])); } + inline double det4(Matrix4f m) + { return m[0] * (m[5] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[6] * m[15] - + m[7] * m[14]) + + m[13] * (m[6] * m[11] - + m[7] * m[10])) - + m[4] * (m[1] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[11] - + m[3] * m[10])) + + m[8] * (m[1] * (m[6] * m[15] - + m[7] * m[14]) - + m[5] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[7] - + m[3] * m[6])) + + m[12] * (m[1] * (m[6] * m[11] - + m[7] * m[10]) - + m[5] * (m[2] * m[11] - + m[3] * m[10]) + + m[9] * (m[2] * m[7] - + m[3] * m[6])); } + inline double det4(Matrix4d m) + { return m[0] * (m[5] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[6] * m[15] - + m[7] * m[14]) + + m[13] * (m[6] * m[11] - + m[7] * m[10])) - + m[4] * (m[1] * (m[10] * m[15] - + m[11] * m[14]) - + m[9] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[11] - + m[3] * m[10])) + + m[8] * (m[1] * (m[6] * m[15] - + m[7] * m[14]) - + m[5] * (m[2] * m[15] - + m[3] * m[14]) + + m[13] * (m[2] * m[7] - + m[3] * m[6])) + + m[12] * (m[1] * (m[6] * m[11] - + m[7] * m[10]) - + m[5] * (m[2] * m[11] - + m[3] * m[10]) + + m[9] * (m[2] * m[7] - + m[3] * m[6])); } } // namespace Matrix } // namespace arda diff -r 11e216148d1c -r 378862555189 include/Vector.h --- a/include/Vector.h Tue Sep 06 11:26:39 2011 -0500 +++ b/include/Vector.h Wed Sep 28 12:48:42 2011 -0500 @@ -1,420 +1,497 @@ #ifndef VECTOR_H_ #define VECTOR_H_ +#include #include #include +#include +#include + namespace arda { - namespace Vector + //////////////////////////////////////////////////////////////////////////////// + // Vectors + // + // Templated classes for 2, 3, and 4 dimensional vectors of any type, + // although these types are really intended to be int, float, and double + // only. (i.e. if you roll your own base type, it had better act like + // a numeric scalar.) + // + // Supported operations on vectors + // + // Construction + // Vector v; // Default zero vector. + // Vector v2(v); // Construct from other vector. + // T a, b; + // Vector v(a, b) // Construct from values. + // [] + // If you have a Vector named v you can access it's member elements as + // v[0], v[1], v[2], and v[3]. in addtion to v.x, v.y, v.z, and v.w + // == != + += - -= + // Defined for operations on two vectors of the same type. + // * *= / /= + // Defined for scalar multiplication/division with int, float, and double. + // *= and /= are defined as member functions, but * and / are defined + // as standalone template operators so that I can support v*a as well as + // a*v order of multiplication. + // assign(T a, T b [, T b [, T d]]) + // Directly assign values to the vector. + // cross(Vector3& v2) + // cross(Vector3& v2, Vector3& vres) + // Cross product of the vector with v2. Only defined for Vector3 types. + // The version that takes two arguments stores the result in the second + // argument. This may be faster since no temporary object is created + // during the operation. + // dot(Vector& v2) + // The dot product of the vector with v2. + // get_angle(Vector& v2) + // Returns the angle (in radians) between the vector and v2. + // Not meaningful for int vectors. + // get_anglen(Vector& v2) + // Like get_angle(), but the vectors must already be normalized. + // Not meaningful for int vectors. + // getstring(std::string & s) + // Returns a C string representation of the vector. + // This is one of the few non-inline Vector functions. + // length() + // Get the length of a vector. + // Returns a double for all vector types. + // normalize() + // Normalizes the vecor. + // Not meaningful for int vectors. + // proj(Vector& v2, Vector& vres) + // Calculates the projection of the vector onto v2 and returns the result + // in vres. + // Not meaningful for int vectors. + // Returns vres. + // + // + // Note that the following typedefs are defined for convenience: + // + // typedef Vector2 Vector2i; + // typedef Vector2 Vector2f; + // typedef Vector2 Vector2d; + // typedef Vector3 Vector3i; + // typedef Vector3 Vector3f; + // typedef Vector3 Vector3d; + // typedef Vector4 Vector4i; + // typedef Vector4 Vector4f; + // typedef Vector4 Vector4d; + // + // + // Scalar multiplication and division are overloaded. Why? + // I'm not sure I need this. The idea is to support all likely scalar + // types without having to rely on implicit or explicity type conversion, + // especially not a conversion that might result in loss of precision. + // Multiplying a float Vector by a double scala, for example. + // Is there a better way to do this? + + + + ///////////////////////////////////////////////////////////////////////////// + template class Vector2 { + public: + T x, y; - //////////////////////////////////////////////////////////////////////////////// - // Vectors - // - // Supported operations on vectors - // - // assign*() Assign the value of one vector to another. - // add*() Add two vectors - // cross() Cross product of two 3-space vectors. - // dot*() Dot product. - // get_angle*() Calculate angle between two vectors. - // length*() Length of a vector (the Euclidean norm). - // normalize*() Normalize the vector. - // proj*() Calculate the projection of one vector onto another. - // scale*() Multiply vector by a scalar. - // subtract*() A convenience function to avoid writing add(v1, scale(v2, -1)) - // getstring*() Returns a printable string representation of the vector. - // - // All functions except getstring are defined inline. + // Constructors + Vector2() : x (0), y(0) {} + Vector2(T a) : x (a), y(a) {} + Vector2(T a, T b) : x (a), y(b) {} - typedef int Vector2i[2]; - typedef float Vector2f[2]; - typedef double Vector2d[2]; + // Array indexing + inline T& operator[](unsigned int i) + { assert (i<2); if (i==0) return x; return y; } + inline const T& operator[](unsigned int i) const + { assert (i<2); if (i==0) return x; return y; } - typedef int Vector3i[3]; - typedef float Vector3f[3]; - typedef double Vector3d[3]; + // Assignment + inline Vector2& operator=(const Vector2& v2) + { x = v2.x; y = v2.y; return *this; } + inline Vector2& assign(const T a, const T b) + { x = a; y = b; return *this; } - typedef int Vector4i[4]; - typedef float Vector4f[4]; - typedef double Vector4d[4]; + // Comparison + inline bool operator==(Vector2& v2) const + { return ((x == v2.x) && (y == v2.y)); } + inline bool operator!=(Vector2& v2) const + { return ! ((x == v2.x) && (y == v2.y)); } - ////////////////////////////////////////////////////////////////////////// - // getstring*(Vector v) - // Returns a C string representation of the vector. - // This is one of the few non-inline Vector functions. + // Vector addition + inline Vector2 operator+(const Vector2& v2) const + { Vector2 vres; vres.x = x + v2.x; vres.y = y + v2.y; return vres; } + inline Vector2& operator+=(const Vector2& v2) + { x += v2.x; y += v2.y; return *this; } - std::string & getstring2v(Vector2i v, std::string & s); - std::string & getstring2v(Vector2f v, std::string & s); - std::string & getstring2v(Vector2d v, std::string & s); - std::string & getstring3v(Vector3i v, std::string & s); - std::string & getstring3v(Vector3f v, std::string & s); - std::string & getstring3v(Vector3d v, std::string & s); - std::string & getstring4v(Vector4i v, std::string & s); - std::string & getstring4v(Vector4f v, std::string & s); - std::string & getstring4v(Vector4d v, std::string & s); - - ////////////////////////////////////////////////////////////////////////// - // scale*(Vector v, scalar s) - // Multiply a vector by a scalar. - // Returns v so that the result may be passed to other functions. + // Vector subtraction + inline Vector2 operator-(const Vector2& v2) const + { Vector2 vres; vres.x = x - v2.x; vres.y = y - v2.y; return vres; } + inline Vector2& operator-=(const Vector2& v2) + { x -= v2.x; y -= v2.y; return *this; } - inline int * scale2v(Vector2i v, const int s) - { v[0] *= s ; v[1] *= s; return v; } - inline int * scale2v(Vector2i v, const float s) - { v[0] *= s ; v[1] *= s; return v; } - inline int * scale2v(Vector2i v, const double s) - { v[0] *= s ; v[1] *= s; return v; } + // Scalar multiplication + inline Vector2& operator*=(const int a) + { x *= a; y *= a; return *this; } + inline Vector2& operator*=(const float a) + { x *= a; y *= a; return *this; } + inline Vector2& operator*=(const double a) + { x *= a; y *= a; return *this; } - inline float * scale2v(Vector2f v, const int s) - { v[0] *= s ; v[1] *= s; return v; } - inline float * scale2v(Vector2f v, const float s) - { v[0] *= s ; v[1] *= s; return v; } - inline float * scale2v(Vector2f v, const double s) - { v[0] *= s ; v[1] *= s; return v; } + // Scalar division + inline Vector2& operator/=(const int a) + { assert(a!=0); x /= a; y /= a; return *this; } + inline Vector2& operator/=(const float a) + { assert(a!=0); x /= a; y /= a; return *this; } + inline Vector2& operator/=(const double a) + { assert(a!=0); x /= a; y /= a; return *this; } - inline double * scale2v(Vector2d v, const int s) - { v[0] *= s ; v[1] *= s; return v; } - inline double * scale2v(Vector2d v, const float s) - { v[0] *= s ; v[1] *= s; return v; } - inline double * scale2v(Vector2d v, const double s) - { v[0] *= s ; v[1] *= s; return v; } + // methods - inline int * scale3v(Vector3i v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline int * scale3v(Vector3i v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline int * scale3v(Vector3i v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - - inline float * scale3v(Vector3f v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline float * scale3v(Vector3f v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline float * scale3v(Vector3f v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } + inline T dot(const Vector2& v2) const + { return x*v2.x + y*v2.y; } - inline double * scale3v(Vector3d v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline double * scale3v(Vector3d v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } - inline double * scale3v(Vector3d v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; return v; } + inline double get_angle(Vector2& v2) + { + double tmp = dot(v2); + return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); + } + inline double get_anglen(Vector2& v2) + { return acos((double) dot(v2)); } - inline int * scale4v(Vector4i v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline int * scale4v(Vector4i v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline int * scale4v(Vector4i v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } + std::string & getstring(std::string & s) const; - inline float * scale4v(Vector4f v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline float * scale4v(Vector4f v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline float * scale4v(Vector4f v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } + inline double length(void) const + { return sqrt((dot(*this))); } - inline double * scale4v(Vector4d v, const int s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline double * scale4v(Vector4d v, const float s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } - inline double * scale4v(Vector4d v, const double s) - { v[0] *= s ; v[1] *= s; v[2] *= s; v[3] *= s; return v; } + inline Vector2& normalize() + { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; return *this; } + inline Vector2 proj(Vector2& v2) + { Vector2 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } + inline Vector2& proj(Vector2& v2, Vector2& vres) + { vres = v2 * dot(v2)/v2.dot(v2); return vres; } + }; - ////////////////////////////////////////////////////////////////////////// - // dot*(Vector v1, Vector v2) - // The dot product of two vectors, which must be the same type - // Returns a long for int vectors, a double for floating point vectors. + // Scalar multiplication, continued + template inline Vector2 operator*(const Vector2& v, const int a) + { return Vector2(v) *= a;} + template inline Vector2 operator*(const int a, const Vector2& v) + { return Vector2(v) *= a;} + template inline Vector2 operator*(const Vector2 v, const float a) + { return Vector2(v) *= a;} + template inline Vector2 operator*(const float a, const Vector2 v) + { return Vector2(v) *= a;} + template inline Vector2 operator*(const Vector2& v, const double a) + { return Vector2(v) *= a;} + template inline Vector2 operator*(const double a, const Vector2& v) + { return Vector2(v) *= a;} - inline long dot2v(Vector2i v1, Vector2i v2) - { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1]; } - inline double dot2v(Vector2f v1, Vector2f v2) - { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1]; } - inline double dot2v(Vector2d v1, Vector2d v2) - { return v1[0]*v2[0] + v1[1]*v2[1]; } + // Scalar division, continued + template inline Vector2 operator/(const Vector2& v, const int a) + { return Vector2(v) /= a;} + template inline Vector2 operator/(const int a, const Vector2& v) + { return Vector2(v) /= a;} + template inline Vector2 operator/(const Vector2& v, const float a) + { return Vector2(v) /= a;} + template inline Vector2 operator/(const float a, const Vector2& v) + { return Vector2(v) /= a;} + template inline Vector2 operator/(const Vector2& v, const double a) + { return Vector2(v) /= a;} + template inline Vector2 operator/(const double a, const Vector2& v) + { return Vector2(v) /= a;} - inline long dot3v(Vector3i v1, Vector3i v2) - { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1] + (long) v1[2]*v2[2]; } - inline double dot3v(Vector3f v1, Vector3f v2) - { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1] + (double) v1[2]*v2[2]; } - inline double dot3v(Vector3d v1, Vector3d v2) - { return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; } + ///////////////////////////////////////////////////////////////////////////// + template class Vector3 + { + public: + T x, y, z; - inline long dot4v(Vector4i v1, Vector4i v2) - { return (long) v1[0]*v2[0] + (long) v1[1]*v2[1] + (long) v1[2]*v2[2] + (long) v1[3]*v2[3]; } - inline double dot4v(Vector4f v1, Vector4f v2) - { return (double) v1[0]*v2[0] + (double) v1[1]*v2[1] + (double) v1[2]*v2[2] + (double) v1[3]*v2[3]; } - inline double dot4v(Vector4d v1, Vector4d v2) - { return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2] + v1[3]*v2[3]; } + // Constructors + Vector3() : x (0), y(0), z(0) {} + Vector3(T a) : x (a), y(a), z(a) {} + Vector3(T a, T b, T c) : x (a), y(b), z(c) {} + // Array indexing + inline T& operator[](unsigned int i) + { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } + inline const T& operator[](unsigned int i) const + { assert (i<3); if (i==0) return x; if (i==1) return y; return z; } - ////////////////////////////////////////////////////////////////////////// - // length*(Vector v) - // Get the length of a vector. - // Returns a float for float for float vectors, and a double for - // int and double vectors. + // Assignment + inline Vector3& operator=(const Vector3& v2) + { x = v2.x; y = v2.y; z = v2.z; return *this; } + inline Vector3& assign(const T a, const T b, const T c) + { x = a; y = b; z = c; return *this; } - inline double length2v(Vector2i v) - { return sqrt((dot2v(v, v))); } - inline double length2v(Vector2f v) - { return sqrtf((dot2v(v, v))); } - inline double length2v(Vector2d v) - { return sqrt((dot2v(v, v))); } + // Comparison + inline bool operator==(Vector3& v2) const + { return ((x == v2.x) && (y == v2.y) && (z == v2.z)); } + inline bool operator!=(Vector3& v2) const + { return ! ((x == v2.x) && (y == v2.y) && (z == v2.z)); } - inline double length3v(Vector3i v) - { return sqrt((dot3v(v, v))); } - inline double length3v(Vector3f v) - { return sqrtf((dot3v(v, v))); } - inline double length3v(Vector3d v) - { return sqrt((dot3v(v, v))); } + // Vector addition + inline Vector3 operator+(const Vector3& v2) const + { Vector3 vres; vres.x = x + v2.x; vres.y = y + v2.y; vres.z = z + v2.z; return vres; } + inline Vector3& operator+=(const Vector3& v2) + { x += v2.x; y += v2.y; z += v2.z; return *this; } - inline double length4v(Vector4i v) - { return sqrt((dot4v(v, v))); } - inline double length4v(Vector4f v) - { return sqrtf((dot4v(v, v))); } - inline double length4v(Vector4d v) - { return sqrt((dot4v(v, v))); } + // Vector subtraction + inline Vector3 operator-(const Vector3& v2) const + { Vector3 vres; vres.x = x - v2.x; vres.y = y - v2.y; vres.z = z - v2.z; return vres; } + inline Vector3& operator-=(const Vector3& v2) + { x -= v2.x; y -= v2.y; z -= v2.z; return *this; } + // Scalar multiplication + inline Vector3& operator*=(const int a) + { x *= a; y *= a; z *= a; return *this; } + inline Vector3& operator*=(const float a) + { x *= a; y *= a; z *= a; return *this; } + inline Vector3& operator*=(const double a) + { x *= a; y *= a; z *= a; return *this; } - ////////////////////////////////////////////////////////////////////////// - // add*(Vector v1, Vector v2) - // Add v2 to v1. - // Returns v1 so that the result may be used in further - // calculations. + // Scalar division + inline Vector3& operator/=(const int a) + { assert(a!=0); x /= a; y /= a; z /= a; return *this; } + inline Vector3& operator/=(const float a) + { assert(a!=0); x /= a; y /= a; z /= a; return *this; } + inline Vector3& operator/=(const double a) + { assert(a!=0); x /= a; y /= a; z /= a; return *this; } - inline int * add2v(Vector2i v1, Vector2i v2) - { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } - inline float * add2v(Vector2f v1, Vector2f v2) - { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } - inline double * add2v(Vector2d v1, Vector2d v2) - { v1[0] += v2[0]; v1[1] += v2[1]; return v1; } - inline int * add3v(Vector3i v1, Vector3i v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } - inline float * add3v(Vector3f v1, Vector3f v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } - inline double * add3v(Vector3d v1, Vector3d v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; return v1; } + // methods - inline int * add4v(Vector4i v1, Vector4i v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } - inline float * add4v(Vector4f v1, Vector4f v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } - inline double * add4v(Vector4d v1, Vector4d v2) - { v1[0] += v2[0]; v1[1] += v2[1]; v1[2] += v2[2]; v1[3] += v2[3]; return v1; } - - ////////////////////////////////////////////////////////////////////////// - // normalize*(Vector v) - // Normalizes the vecor. Only defined for floating point vectors. - // Returns the vector. - - inline float * normalize2v(Vector2f v) - { double l = length2v(v); v[0] /= l; v[1] /= l; return v; } - inline double * normalize2v(Vector2d v) - { double l = length2v(v); v[0] /= l; v[1] /= l; return v; } - - inline float * normalize3v(Vector3f v) - { double l = length3v(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } - inline double * normalize3v(Vector3d v) - { double l = length3v(v); v[0] /= l; v[1] /= l; v[2] /= l; return v; } - - inline float * normalize4v(Vector4f v) - { double l = length4v(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } - inline double * normalize4v(Vector4d v) - { double l = length4v(v); v[0] /= l; v[1] /= l; v[2] /= l; v[3] /= l; return v; } - - ////////////////////////////////////////////////////////////////////////// - // cross(Vector3 v) - // Only defined for floating point 3 vectors. - // Returns the result vector. - - inline float * cross(Vector3f v1, Vector3f v2, Vector3f vres) + inline Vector3& cross(Vector3& v2, Vector3& vres) { - vres[0] = v1[1]*v2[2] - v2[1]*v1[2]; - vres[1] = -v1[0]*v2[2] + v2[0]*v1[2]; - vres[2] = v1[0]*v2[1] - v2[0]*v1[1]; + vres.x = y*v2.z - v2.y*z; + vres.y = -x*v2.z + v2.x*z; + vres.z = x*v2.y - v2.x*y; + return vres; + } + inline Vector3 cross(Vector3& v2) + { + Vector3 vres; + vres.x = y*v2.z - v2.y*z; + vres.y = -x*v2.z + v2.x*z; + vres.z = x*v2.y - v2.x*y; return vres; } - inline double * cross(Vector3d v1, Vector3d v2, Vector3d vres) + inline T dot(const Vector3& v2) const + { return x*v2.x + y*v2.y + z*v2.z; } + + inline double get_angle(Vector3& v2) { - vres[0] = v1[1]*v2[2] - v2[1]*v1[2]; - vres[1] = -v1[0]*v2[2] + v2[0]*v1[2]; - vres[2] = v1[0]*v2[1] - v2[0]*v1[1]; - return vres; - } - - ////////////////////////////////////////////////////////////////////////// - // get_angle*(Vector3 v1, Vector3 v2) - // Returns the angle in radians between the two vectors. - // - // get_angle[234]n() take pre-normalized vectors as arguments and will - // fail otherwise. This version is not defined for interger - // vectors since you can't normalize an integer vector. - // get_angle[234]() take arbitrary vectors as arguments. - // - // I started out with two version of get_angle3: - // get_angle3_1 implemented as - // return acos(dot3v(v1, v2)/(length3v(v1)*length3v(v2))); - // get_angle3_2 implemented as - // double tmp = dot3v(v1, v2); - // return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); - // - // I ran timing tests, since I expected the second one - the one I chose to - // use, in the end - to be faster since it only resulted in one sqrt call - // instead of two. Here are the results - // - // get_angle3_1 44.753006890 seconds for 500,000,000 iterations. - // get_angle3_2 36.940170102 seconds for 500,000,000 iterations. - // - // Faster? Yes. About 7 nanoseconds vs 9. A ridiculous optimization - // to worry about? Eh. I might as well use it. - - inline double get_angle2n(Vector2f v1, Vector2f v2) - { return acos(dot2v(v1, v2)); } - inline double get_angle2n(Vector2d v1, Vector2d v2) - { return acos(dot2v(v1, v2)); } - inline double get_angle2v(Vector2i v1, Vector2i v2) - { - double tmp = dot2v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); - } - inline double get_angle2v(Vector2f v1, Vector2f v2) - { - double tmp = dot2v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); - } - inline double get_angle2v(Vector2d v1, Vector2d v2) - { - double tmp = dot2v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot2v(v1,v1)*dot2v(v2,v2)))); + double tmp = dot(v2); + return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); } - inline double get_angle3n(Vector3f v1, Vector3f v2) - { return acos(dot3v(v1, v2)); } - inline double get_angle3n(Vector3d v1, Vector3d v2) - { return acos(dot3v(v1, v2)); } - inline double get_angle3v(Vector3i v1, Vector3i v2) + inline double get_anglen(Vector3& v2) + { return acos((double) dot(v2)); } + + std::string & getstring(std::string & s) const; + + inline double length(void) const + { return sqrt((dot(*this))); } + + inline Vector3& normalize() + { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; return *this; } + + inline Vector3 proj(Vector3& v2) + { Vector3 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } + inline Vector3& proj(Vector3& v2, Vector3& vres) + { vres = v2 * dot(v2)/v2.dot(v2); return vres; } + }; + + // Scalar multiplication, continued + template inline Vector3 operator*(const Vector3& v, const int a) + { return Vector3(v) *= a;} + template inline Vector3 operator*(const int a, const Vector3& v) + { return Vector3(v) *= a;} + template inline Vector3 operator*(const Vector3 v, const float a) + { return Vector3(v) *= a;} + template inline Vector3 operator*(const float a, const Vector3 v) + { return Vector3(v) *= a;} + template inline Vector3 operator*(const Vector3& v, const double a) + { return Vector3(v) *= a;} + template inline Vector3 operator*(const double a, const Vector3& v) + { return Vector3(v) *= a;} + + // Scalar division, continued + template inline Vector3 operator/(const Vector3& v, const int a) + { return Vector3(v) /= a;} + template inline Vector3 operator/(const int a, const Vector3& v) + { return Vector3(v) /= a;} + template inline Vector3 operator/(const Vector3& v, const float a) + { return Vector3(v) /= a;} + template inline Vector3 operator/(const float a, const Vector3& v) + { return Vector3(v) /= a;} + template inline Vector3 operator/(const Vector3& v, const double a) + { return Vector3(v) /= a;} + template inline Vector3 operator/(const double a, const Vector3& v) + { return Vector3(v) /= a;} + + ///////////////////////////////////////////////////////////////////////////// + template class Vector4 + { + public: + T x, y, z, w; + + // Constructors + Vector4() : x (0), y(0), z(0), w(0) {} + Vector4(T a) : x (a), y(a), z(a), w(a) {} + Vector4(T a, T b, T c, T d) : x (a), y(b), z(c), w(d) {} + + // Array indexing + inline T& operator[](unsigned int i) + { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } + inline const T& operator[](unsigned int i) const + { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; } + + // Assignment + inline Vector4& operator=(const Vector4& v2) + { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; } + inline Vector4& assign(const T a, const T b, const T c, const T d) + { x = a; y = b; z = c; w = d; return *this; } + + // Comparison + inline bool operator==(Vector4& v2) const + { return ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); } + inline bool operator!=(Vector4& v2) const + { return ! ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); } + + // Vector addition + inline Vector4 operator+(const Vector4& v2) const + { Vector4 vres; vres.x = x + v2.x; vres.y = y + v2.y; vres.z = z + v2.z; vres.w = w + v2.w; return vres; } + inline Vector4& operator+=(const Vector4& v2) + { x += v2.x; y += v2.y; z += v2.z; w += v2.w; return *this; } + + // Vector subtraction + inline Vector4 operator-(const Vector4& v2) const + { Vector4 vres; vres.x = x - v2.x; vres.y = y - v2.y; vres.z = z - v2.z; vres.w = w - v2.w; return vres; } + inline Vector4& operator-=(const Vector4& v2) + { x -= v2.x; y -= v2.y; z -= v2.z; w -= v2.w; return *this; } + + // Scalar multiplication + inline Vector4& operator*=(const int a) + { x *= a; y *= a; z *= a; w *= a; return *this; } + inline Vector4& operator*=(const float a) + { x *= a; y *= a; z *= a; w *= a; return *this; } + inline Vector4& operator*=(const double a) + { x *= a; y *= a; z *= a; w *= a; return *this; } + + // Scalar division + inline Vector4& operator/=(const int a) + { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } + inline Vector4& operator/=(const float a) + { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } + inline Vector4& operator/=(const double a) + { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; } + + + // methods + + inline T dot(const Vector4& v2) const + { return x*v2.x + y*v2.y + z*v2.z + w*v2.w; } + + inline double get_angle(Vector4& v2) { - double tmp = dot3v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); - } - inline double get_angle3v(Vector3f v1, Vector3f v2) - { - double tmp = dot3v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); - } - inline double get_angle3v(Vector3d v1, Vector3d v2) - { - double tmp = dot3v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot3v(v1,v1)*dot3v(v2,v2)))); + double tmp = dot(v2); + return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2)))); } - inline double get_angle4n(Vector4f v1, Vector4f v2) - { return acos(dot4v(v1, v2)); } - inline double get_angle4n(Vector4d v1, Vector4d v2) - { return acos(dot4v(v1, v2)); } - inline double get_angle4v(Vector4i v1, Vector4i v2) - { - double tmp = dot4v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); - } - inline double get_angle4v(Vector4f v1, Vector4f v2) - { - double tmp = dot4v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); - } - inline double get_angle4v(Vector4d v1, Vector4d v2) - { - double tmp = dot4v(v1, v2); - return acos(sqrtf(tmp*tmp/(dot4v(v1,v1)*dot4v(v2,v2)))); - } + inline double get_anglen(Vector4& v2) + { return acos((double) dot(v2)); } - ////////////////////////////////////////////////////////////////////////// - // subtract*(Vector v1, Vector v2) - // Subtract v2 from v1, - // Equivalent to add(v1, scale(v2, -1)). - // Returns v1 so that the result may be used in further - // calculations. + std::string & getstring(std::string & s) const; - inline int * subtract2v(Vector2i v1, Vector2i v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } - inline float * subtract2v(Vector2f v1, Vector2f v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } - inline double * subtract2v(Vector2d v1, Vector2d v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; return v1; } + inline double length(void) const + { return sqrt((dot(*this))); } - inline int * subtract3v(Vector3i v1, Vector3i v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } - inline float * subtract3v(Vector3f v1, Vector3f v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } - inline double * subtract3v(Vector3d v1, Vector3d v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; return v1; } + inline Vector4& normalize() + { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; w /= l; return *this; } - inline int * subtract4v(Vector4i v1, Vector4i v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1;} - inline float * subtract4v(Vector4f v1, Vector4f v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1; } - inline double * subtract4v(Vector4d v1, Vector4d v2) - { v1[0] -= v2[0]; v1[1] -= v2[1]; v1[2] -= v2[2]; v1[3] -= v2[3]; return v1; } + inline Vector4 proj(Vector4& v2) + { Vector4 vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; } + inline Vector4& proj(Vector4& v2, Vector4& vres) + { vres = v2 * dot(v2)/v2.dot(v2); return vres; } + }; + // Scalar multiplication, continued + template inline Vector4 operator*(const Vector4& v, const int a) + { return Vector4(v) *= a;} + template inline Vector4 operator*(const int a, const Vector4& v) + { return Vector4(v) *= a;} + template inline Vector4 operator*(const Vector4 v, const float a) + { return Vector4(v) *= a;} + template inline Vector4 operator*(const float a, const Vector4 v) + { return Vector4(v) *= a;} + template inline Vector4 operator*(const Vector4& v, const double a) + { return Vector4(v) *= a;} + template inline Vector4 operator*(const double a, const Vector4& v) + { return Vector4(v) *= a;} - ////////////////////////////////////////////////////////////////////////// - // assign*(Vector v1, Vector v2) - // Copies the value of v2 into v1. - // Returns v1. + // Scalar division, continued + template inline Vector4 operator/(const Vector4& v, const int a) + { return Vector4(v) /= a;} + template inline Vector4 operator/(const int a, const Vector4& v) + { return Vector4(v) /= a;} + template inline Vector4 operator/(const Vector4& v, const float a) + { return Vector4(v) /= a;} + template inline Vector4 operator/(const float a, const Vector4& v) + { return Vector4(v) /= a;} + template inline Vector4 operator/(const Vector4& v, const double a) + { return Vector4(v) /= a;} + template inline Vector4 operator/(const double a, const Vector4& v) + { return Vector4(v) /= a;} - inline int * assign2v(Vector2i v1, Vector2i v2) - { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } - inline float * assign2v(Vector2f v1, Vector2f v2) - { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } - inline double * assign2v(Vector2d v1, Vector2d v2) - { v1[0] = v2[0]; v1[1] = v2[1]; return v1; } + ///////////////////////////////////////////////////////////////////////////// - inline int * assign3v(Vector3i v1, Vector3i v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } - inline float * assign3v(Vector3f v1, Vector3f v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } - inline double * assign3v(Vector3d v1, Vector3d v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; return v1; } + typedef Vector2 Vector2i; + typedef Vector2 Vector2f; + typedef Vector2 Vector2d; - inline int * assign4v(Vector4i v1, Vector4i v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } - inline float * assign4v(Vector4f v1, Vector4f v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } - inline double * assign4v(Vector4d v1, Vector4d v2) - { v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2]; v1[3] = v2[3]; return v1; } + typedef Vector3 Vector3i; + typedef Vector3 Vector3f; + typedef Vector3 Vector3d; - - ////////////////////////////////////////////////////////////////////////// - // proj*(Vector v1, Vector v2, Vector vres) - // Calculates the projection of v1 onto v2 and returns the result - // in vres. - // Only defined for floating point vectors. - // Returns vres. - - inline float * proj2v(Vector2f v1, Vector2f v2, Vector2f vres) - { assign2v(vres, v2); scale2v(vres, (dot2v(v1, vres)/dot2v(vres,vres))); return vres; } - inline double * proj2v(Vector2d v1, Vector2d v2, Vector2d vres) - { assign2v(vres, v2); scale2v(vres, (dot2v(v1, vres)/dot2v(vres,vres))); return vres; } - - inline float * proj3v(Vector3f v1, Vector3f v2, Vector3f vres) - { assign3v(vres, v2); scale3v(vres, (dot3v(v1, vres)/dot3v(vres,vres))); return vres; } - inline double * proj3v(Vector3d v1, Vector3d v2, Vector3d vres) - { assign3v(vres, v2); scale3v(vres, (dot3v(v1, vres)/dot3v(vres,vres))); return vres; } - - inline float * proj4v(Vector4f v1, Vector4f v2, Vector4f vres) - { assign4v(vres, v2); scale4v(vres, (dot4v(v1, vres)/dot4v(vres,vres))); return vres; } - inline double * proj4v(Vector4d v1, Vector4d v2, Vector4d vres) - { assign4v(vres, v2); scale4v(vres, (dot4v(v1, vres)/dot4v(vres,vres))); return vres; } - - } // Vector + typedef Vector4 Vector4i; + typedef Vector4 Vector4f; + typedef Vector4 Vector4d; } // namespace arda +//////////////////////////////////////////////////////////////////////////////// +template std::string & arda::Vector2::getstring(std::string & s) const + { + s.clear(); + std::stringstream ss; + ss << "[ " << x << ", " << y << " ]"; + s = ss.str(); + return s; + } + +//////////////////////////////////////////////////////////////////////////////// +template std::string & arda::Vector3::getstring(std::string & s) const + { + s.clear(); + std::stringstream ss; + ss << "[ " << x << ", " << y << ", " << z << " ]"; + s = ss.str(); + return s; + } + +//////////////////////////////////////////////////////////////////////////////// +template std::string & arda::Vector4::getstring(std::string & s) const + { + s.clear(); + std::stringstream ss; + ss << "[ " << x << ", " << y << ", " << z << ", " << w << " ]"; + s = ss.str(); + return s; + } + + #endif // VECTOR_H_ diff -r 11e216148d1c -r 378862555189 src/Vector.cpp --- a/src/Vector.cpp Tue Sep 06 11:26:39 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -#include "Vector.h" - -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring2v(Vector2i v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring2v(Vector2f v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring2v(Vector2d v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring3v(Vector3i v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring3v(Vector3f v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring3v(Vector3d v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring4v(Vector4i v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring4v(Vector4f v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; - s = ss.str(); - return s; - } - -//////////////////////////////////////////////////////////////////////////////// -std::string & arda::Vector::getstring4v(Vector4d v, std::string & s) - { - s.clear(); - std::stringstream ss; - ss << "[ " << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << " ]"; - s = ss.str(); - return s; - } diff -r 11e216148d1c -r 378862555189 src/main.cpp --- a/src/main.cpp Tue Sep 06 11:26:39 2011 -0500 +++ b/src/main.cpp Wed Sep 28 12:48:42 2011 -0500 @@ -5,272 +5,417 @@ using namespace std; #include "Math.h" -using namespace arda::Vector; -using namespace arda::Matrix; +using namespace arda; //////////////////////////////////////////////////////////////////////////////// void test_vector(void) { string s1, s2; - // Vector::scale*() { cout << "===============================================================" << endl << - "Testing Vector::scale*()" << endl; + "Testing Vector constructors" << endl; + Vector2i v2i_1; + Vector2i v2i_2(1); + Vector2i v2i_3(1, 2); + Vector2i v2i_4(v2i_3); - Vector2i v2i = { 1, 2 }; - cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl; - scale2v(v2i, 2); - cout << setw(40) << "scale2v(v2i, 2): " << getstring2v(v2i, s1) << endl; - scale2v(v2i, 2.4); - cout << setw(40) << "scale2v(v2i, 2.4): " << getstring2v(v2i, s1) << endl; - scale2v(scale2v(v2i, 2), 3); - cout << setw(40) << "scale2v(scale2v(v2i, 2), 3): " << getstring2v(v2i, s1) << endl; + cout << setw(40) << "v2i_1: " << v2i_1.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl; + cout << setw(40) << "v2i_4: " << v2i_4.getstring(s1) << endl; + Vector3f v3f_1; + Vector3f v3f_2(1); + Vector3f v3f_3(1, 2, 3); + Vector3f v3f_4(v3f_3); - Vector3f v3f = { 3.0, 4.1, 5.2 }; - cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; - scale3v(v3f, 2.2f); - cout << setw(40) << "scale3v(v3f, 2.2f): " << getstring3v(v3f, s1) << endl; - scale3v(v3f, 2); - cout << setw(40) << "scale3v(v2f, 2): " << getstring3v(v3f, s1) << endl; + cout << setw(40) << "v3f_1: " << v3f_1.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v3f_4: " << v3f_4.getstring(s1) << endl; - Vector4d v4d = { 6.0L, 7.1L, 8.2L, 9.3L }; - cout << setw(40) << "vd4: " << getstring4v(v4d, s1) << endl; - scale4v(v4d, 2.0); - cout << setw(40) << "scale4v(v4d, 2.0): " << getstring4v(v4d, s1) << endl; - scale4v(v4d, 2); - cout << setw(40) << "scale4v(v4d, 2): " << getstring4v(v4d, s1) << endl; + Vector4d v4d_1; + Vector4d v4d_2(1); + Vector4d v4d_3(1, 2, 3, 4); + Vector4d v4d_4(v4d_3); + + cout << setw(40) << "v4d_1: " << v4d_1.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl; + cout << setw(40) << "v4d_4: " << v4d_4.getstring(s1) << endl; } - - // Vector::dot*() { cout << "===============================================================" << endl << - "Testing Vector::dot*()" << endl; + "Testing Vector array indexing" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); - Vector2i v2i[2] = { { 1, 2 }, { 3, 4 } }; - cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; - cout << setw(40) << "dot2v(v2i[0], v2i[1]): " << dot2v(v2i[0], v2i[1]) << endl; - - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - cout << setw(40) << "dot3v(v3f[0], v3f[1]): " << dot3v(v3f[0], v3f[1]) << endl; - - Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; - cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; - cout << setw(40) << "dot4v(v4d[0], v4d[1]): " << dot4v(v4d[0], v4d[1]) << endl; - + cout << setw(40) << "v2i: " << v2i[0] << ", " << v2i[1] << endl; + cout << setw(40) << "v3f: " << v3f[0] << ", " << v3f[1] << ", " << v3f[2] << endl; + cout << setw(40) << "v4d: " << v4d[0] << ", " << v4d[1] << ", " << v4d[2] << ", " << v4d[3] << endl; } - // Vector::length*() { cout << "===============================================================" << endl << - "Testing Vector::length*()" << endl; + "Testing Vector assignment" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2; + Vector3f v3f_2; + Vector4d v4d_2; - Vector2i v2i = { 1, 2 }; - cout << setw(40) << "v2i: " << getstring2v(v2i, s1) << endl; - cout << setw(40) << "length2v(v2i): " << length2v(v2i) << endl; - - Vector3f v3f = { 1.1f, 2.2f, 3.3f }; - cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; - cout << setw(40) << "length3v(v3f): " << length3v(v3f) << endl; - - Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; - cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl; - cout << setw(40) << "length4v(v4d): " << length4v(v4d) << endl; - + cout << "Before assignment" << endl; + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + + v2i_2 = v2i; + v3f_2 = v3f; + v4d_2 = v4d; + cout << "After assignment by =" << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + + v2i_2.assign(1, 1); + v3f_2.assign(2.2, 2.2, 2.2); + v4d_2.assign(3.3, 3.3, 3.3, 3.3); + cout << "After assignment by assign()" << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; } - // Vector::add*() { cout << "===============================================================" << endl << - "Testing Vector::add*()" << endl; + "Testing Vector comparison" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2; + Vector3f v3f_2; + Vector4d v4d_2; - Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; - cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; - add2v(v2i[0], v2i[1]); - cout << setw(40) << "add2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "length2v(add2v(v2i[0], v2i[1])): " << length2v(add2v(v2i[0], v2i[1])) << endl; - - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - add3v(v3f[0], v3f[1]); - cout << setw(40) << "add3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "length3v(add3v(v3f[0], v3f[1])): " << length3v(add3v(v3f[0], v3f[1])) << endl; - - Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; - cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; - add4v(v4d[0], v4d[1]); - cout << setw(40) << "add4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "length4v(add4v(v4d[0], v4d[1])): " << length4v(add4v(v4d[0], v4d[1])) << endl; - + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + cout << boolalpha; + cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl; + cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl; + cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl; + cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl; + cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl; + cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl; } - // Vector::normalize*() { cout << "===============================================================" << endl << - "Testing Vector::normalize*()" << endl; + "Testing Vector addition" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2(3,4); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + Vector2i v2i_3; + Vector3f v3f_3 ; + Vector4d v4d_3; - Vector2f v2f = { 1.1, 2.2 }; - cout << setw(40) << "v2f: " << getstring2v(v2f, s1) << endl; - normalize2v(v2f); - cout << setw(40) << "normalize2v(v2f): " << getstring2v(v2f, s1) << endl; - scale2v(normalize2v(v2f), 2.0); - cout << setw(40) << "scale(normalize2v(v2f), 2.0): " << getstring2v(v2f, s1) << endl; - - Vector3f v3f = { 1.1f, 2.2f, 3.3f }; - cout << setw(40) << "v3f: " << getstring3v(v3f, s1) << endl; - normalize3v(v3f); - cout << setw(40) << "normalize3v(v3f): " << getstring3v(v3f, s1) << endl; - scale3v(normalize3v(v3f), 2.0); - cout << setw(40) << "scale(normalize3v(v3f), 2.0): " << getstring3v(v3f, s1) << endl; - - Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; - cout << setw(40) << "v4d: " << getstring4v(v4d, s1) << endl; - normalize4v(v4d); - cout << setw(40) << "normalize4v(v4d): " << getstring4v(v4d, s1) << endl; - scale4v(normalize4v(v4d), 2.0); - cout << setw(40) << "scale4v(normalize4v(v4d), 2.0): " << getstring4v(v4d, s1) << endl; - + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + v2i_3 = v2i + v2i_2; + v3f_3 = v3f + v3f_2; + v4d_3 = v4d + v4d_2; + cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.getstring(s1) << endl; + cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.getstring(s1) << endl; + v2i_3 += v2i_2; + v3f_3 += v3f_2; + v4d_3 += v4d_3; + cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.getstring(s1) << endl; + cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.getstring(s1) << endl; } - // Vector::cross() { cout << "===============================================================" << endl << - "Testing Vector::cross()" << endl; + "Testing Vector subtraction" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2(3,4); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + Vector2i v2i_3; + Vector3f v3f_3; + Vector4d v4d_3; - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 0.0f, 0.0f, 0.0f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - cross(v3f[0], v3f[1], v3f[2]); - cout << setw(40) << "cross(v3f[0], v3f[1], v3f[2]): " << getstring3v(v3f[2], s1) << endl; - - Vector3d v3d[3] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 0.0, 0.0, 0.0 } }; - cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; - cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; - cross(v3d[0], v3d[1], v3d[2]); - cout << setw(40) << "cross(v3d[0], v3d[1], v3d[2]): " << getstring3v(v3d[2], s1) << endl; - + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + v2i_3 = v2i - v2i_2; + v3f_3 = v3f - v3f_2; + v4d_3 = v4d - v4d_2; + cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.getstring(s1) << endl; + cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.getstring(s1) << endl; + v2i_3 -= v2i_2; + v3f_3 -= v3f_2; + v4d_3 -= v4d_3; + cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.getstring(s1) << endl; + cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.getstring(s1) << endl; + cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.getstring(s1) << endl; } - - // Vector::cross() { cout << "===============================================================" << endl << - "Testing Vector::get_angle*()" << endl; + "Testing Vector scalar multiplication" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2; + Vector3f v3f_2; + Vector4d v4d_2; + int i = 2; + float f = 2.f; + double d = 2.0; - Vector3i v3i[2] = { { 1, 2, 3 }, { 4, 5, 6 } }; - cout << setw(40) << "v3i[0]: " << getstring3v(v3i[0], s1) << endl; - cout << setw(40) << "v3i[1]: " << getstring3v(v3i[1], s1) << endl; - cout << setw(40) << "get_angle3v(v3i[0], v3i[1]): " << get_angle3v(v3i[0], v3i[1]) << endl; - - Vector3f v3f[2] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - cout << setw(40) << "get_angle3v(v3f[0], v3f[1]): " << get_angle3v(v3f[0], v3f[1]) << endl; - normalize3v(v3f[0]); - normalize3v(v3f[1]); - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - cout << setw(40) << "get_angle3n(v3f[0], v3f[1]): " << get_angle3n(v3f[0], v3f[1]) << endl; - - Vector3d v3d[2] = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } }; - cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; - cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; - cout << setw(40) << "get_angle3v(v3d[0], v3d[1]): " << get_angle3v(v3d[0], v3d[1]) << endl; - normalize3v(v3d[0]); - normalize3v(v3d[1]); - cout << setw(40) << "v3d[0]: " << getstring3v(v3d[0], s1) << endl; - cout << setw(40) << "v3d[1]: " << getstring3v(v3d[1], s1) << endl; - cout << setw(40) << "get_angle3n(v3d[0], v3d[1]): " << get_angle3n(v3d[0], v3d[1]) << endl; + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + v2i_2 = v2i * i; + v3f_2 = v3f * f; + v4d_2 = v4d * d; + cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.getstring(s1) << endl; + v2i_2 *= i; + v3f_2 *= f; + v4d_2 *= d; + cout << setw(40) << "v2i_2 *= i: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2 *= f: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2 *= d: " << v4d_2.getstring(s1) << endl; } - // Vector::subtract*() { cout << "===============================================================" << endl << - "Testing Vector::subtract*()" << endl; + "Testing Vector scalar division" << endl; + Vector2i v2i(1,2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector2i v2i_2; + Vector3f v3f_2; + Vector4d v4d_2; + int i = 2; + float f = 2.f; + double d = 2.0; - Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; - cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; - subtract2v(v2i[0], v2i[1]); - cout << setw(40) << "subtract2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "length2v(subtract2v(v2i[0], v2i[1])): " << length2v(subtract2v(v2i[0], v2i[1])) << endl; - - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - subtract3v(v3f[0], v3f[1]); - cout << setw(40) << "subtract3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "length3v(subtract3v(v3f[0], v3f[1])): " << length3v(subtract3v(v3f[0], v3f[1])) << endl; - - Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; - cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; - subtract4v(v4d[0], v4d[1]); - cout << setw(40) << "subtract4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "length4v(subtract4v(v4d[0], v4d[1])): " << length4v(subtract4v(v4d[0], v4d[1])) << endl; - + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + v2i_2 = v2i / i; + v3f_2 = v3f / f; + v4d_2 = v4d / d; + cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.getstring(s1) << endl; + v2i_2 /= i; + v3f_2 /= f; + v4d_2 /= d; + cout << setw(40) << "v2i_2 /= i: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f_2 /= f: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d_2 /= d: " << v4d_2.getstring(s1) << endl; } - // Vector::assign*() { cout << "===============================================================" << endl << - "Testing Vector::assign*()" << endl; - - Vector2i v2i[3] = { { 1, 2 }, { 3, 4 } }; - cout << setw(40) << "v2i[0]: " << getstring2v(v2i[0], s1) << endl; - cout << setw(40) << "v2i[1]: " << getstring2v(v2i[1], s1) << endl; - assign2v(v2i[0], v2i[1]); - cout << setw(40) << "assign2v(v2i[0], v2i[1]): " << getstring2v(v2i[0], s1) << endl; - - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - assign3v(v3f[0], v3f[1]); - cout << setw(40) << "assign3v(v3f[0], v3f[1]): " << getstring3v(v3f[0], s1) << endl; - - Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; - cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; - assign4v(v4d[0], v4d[1]); - cout << setw(40) << "assign4v(v4d[0], v4d[1]): " << getstring4v(v4d[0], s1) << endl; - + "Testing Vector cross product" << endl; + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector3f v3f_3; + Vector3f v3f_4; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl; + v3f.cross(v3f_2, v3f_3); + cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; + v3f_4 = 2.0 * v3f.cross(v3f_2); + cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.getstring(s1) << endl; + v3f_4.assign(0,0,0); + v3f.cross(v3f_2, v3f_4); + cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.getstring(s1) << endl; } - // Vector::proj*() { cout << "===============================================================" << endl << - "Testing Vector::proj*()" << endl; + "Testing Vector dot product" << endl; + Vector2i v2i(1, 2); + Vector2i v2i_2(3, 4); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + int i; + float f; + double d; + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + i = v2i.dot(v2i_2); + cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl; + f = v3f.dot(v3f_2); + cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl; + d = v4d.dot(v4d_2); + cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl; + } - Vector2f v2f[3] = { { 1.1f, 2.2f }, { 3.3f, 4.4f } }; - Vector2f v2fres; - cout << setw(40) << "v2f[0]: " << getstring2v(v2f[0], s1) << endl; - cout << setw(40) << "v2f[1]: " << getstring2v(v2f[1], s1) << endl; - proj3v(v2f[0], v2f[1], v2fres); - cout << setw(40) << "proj3v(v2f[0], v2f[1], v2fres): " << getstring2v(v2fres, s1) << endl; + { + cout << "===============================================================" << endl << + "Testing Vector length" << endl; + Vector2i v2i(1, 2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2i.length(): " << v2i.length() << endl; + cout << setw(40) << "v3f.length(): " << v3f.length() << endl; + cout << setw(40) << "v4d.length(): " << v4d.length() << endl; + } - Vector3f v3f[3] = { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f } }; - Vector3f v3fres; - cout << setw(40) << "v3f[0]: " << getstring3v(v3f[0], s1) << endl; - cout << setw(40) << "v3f[1]: " << getstring3v(v3f[1], s1) << endl; - proj3v(v3f[0], v3f[1], v3fres); - cout << setw(40) << "proj3v(v3f[0], v3f[1], v3fres): " << getstring3v(v3fres, s1) << endl; + { + cout << "===============================================================" << endl << + "Testing Vector normalize" << endl; + Vector2f v2f(1.1, 2.2); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + v2f.normalize(); + cout << setw(40) << "v2f.normalize() " << v2f.getstring(s1) << endl; + v3f.normalize(); + cout << setw(40) << "v3f.normalize() " << v3f.getstring(s1) << endl; + v4d.normalize(); + cout << setw(40) << "v4d.normalize() " << v4d.getstring(s1) << endl; + cout << setw(40) << "v2f.length(): " << v2f.length() << endl; + cout << setw(40) << "v3f.length(): " << v3f.length() << endl; + cout << setw(40) << "v4d.length(): " << v4d.length() << endl; + } - Vector4d v4d[3] = { { 1.1, 2.2, 3.3, 4.4 }, { 5.5, 6.6, 7.7, 8.8 } }; - Vector4d v4dres; - cout << setw(40) << "v4d[0]: " << getstring4v(v4d[0], s1) << endl; - cout << setw(40) << "v4d[1]: " << getstring4v(v4d[1], s1) << endl; - proj4v(v4d[0], v4d[1], v4dres); - cout << setw(40) << "proj4v(v4d[0], v4d[1], v4dres): " << getstring4v(v4dres, s1) << endl; + { + cout << "===============================================================" << endl << + "Testing Vector get_angle" << endl; + Vector2i v2i(1, 2); + Vector2i v2i_2(3, 4); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + double d; + cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl; + cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + d = v2i.get_angle(v2i_2); + cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl; + d = v3f.get_angle(v3f_2); + cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl; + d = v4d.get_angle(v4d_2); + cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl; + } + { + cout << "===============================================================" << endl << + "Testing Vector get_anglen" << endl; + Vector2f v2f(1.1, 2.2); + Vector2f v2f_2(3.3, 4.4); + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + double d; + v2f.normalize(); + v2f_2.normalize(); + v3f.normalize(); + v3f_2.normalize(); + v4d.normalize(); + v4d_2.normalize(); + cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; + cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + d = v2f.get_anglen(v2f_2); + cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl; + d = v3f.get_anglen(v3f_2); + cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl; + d = v4d.get_anglen(v4d_2); + cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl; + } + + { + cout << "===============================================================" << endl << + "Testing Vector get_proj" << endl; + Vector2f v2f(1.1, 2.2); + Vector2f v2f_2(3.3, 4.4); + Vector2f v2f_3; + Vector3f v3f(1.1f, 2.2f, 3.3f); + Vector3f v3f_2(4.4, 5.5, 6.6); + Vector3f v3f_3; + Vector4d v4d(1.1, 2.2, 3.3, 4.4); + Vector4d v4d_2(5.5, 6.6, 7.7, 8.8); + Vector4d v4d_3; + cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl; + cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl; + cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl; + cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl; + cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl; + cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl; + v2f_3 = v2f.proj(v2f_2); + cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.getstring(s1) << endl; + v3f_3 = v3f.proj(v3f_2); + cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.getstring(s1) << endl; + v4d_3 = v4d.proj(v4d_2); + cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.getstring(s1) << endl; + v2f_3.assign(0,0); + v3f_3.assign(0,0,0); + v4d_3.assign(0,0,0,0); + v2f.proj(v2f_2, v2f_3); + cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.getstring(s1) << endl; + v3f.proj(v3f_2, v3f_3); + cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl; + v4d.proj(v4d_2, v4d_3); + cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.getstring(s1) << endl; } } @@ -278,254 +423,7 @@ //////////////////////////////////////////////////////////////////////////////// void test_matrix(void) { - std::string s; - - { - cout << "===============================================================" << endl << - "Testing Matrix::assign*()" << endl; - Matrix2i m2i[2] = { { 0, 0, - 0, 0 }, - { 1, 2, - 3, 4 } }; - Matrix3f m3f[2] = { { 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f }, - { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f } }; - Matrix4d m4d[2] = { { 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0 }, - { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 } }; - cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; - cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; - assign2m(m2i[0], m2i[1]); - cout << setw(40) << "assign2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; - - cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; - cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; - assign3m(m3f[0], m3f[1]); - cout << setw(40) << "assign3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; - - cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; - cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; - assign4m(m4d[0], m4d[1]); - cout << setw(40) << "assign4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; - } - - { - cout << "===============================================================" << endl << - "Testing Matrix::add*()" << endl; - Matrix2i m2i[2] = { { 1, 2, - 3, 4 }, - { 5, 6, - 7, 8 } }; - Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }, - { 10.10f, 11.11f, 12.12f, - 13.13f, 14.14f, 15.15f, - 16.16f, 17.17f, 18.18f } }; - Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }, - { 17.17, 18.18, 19.19, 20.20, - 21.21, 22.22, 23.23, 24.24, - 25.25, 26.26, 27.27, 28.28, - 29.29, 30.30, 31.31, 32.32 } }; - cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; - cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; - add2m(m2i[0], m2i[1]); - cout << setw(40) << "add2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; - - cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; - cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; - add3m(m3f[0], m3f[1]); - cout << setw(40) << "add3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; - - cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; - cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; - add4m(m4d[0], m4d[1]); - cout << setw(40) << "add4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; - } - - { - cout << "===============================================================" << endl << - "Testing Matrix::subtract*()" << endl; - Matrix2i m2i[2] = { { 1, 2, - 3, 4 }, - { 5, 6, - 7, 8 } }; - Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }, - { 10.10f, 11.11f, 12.12f, - 13.13f, 14.14f, 15.15f, - 16.16f, 17.17f, 18.18f } }; - Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }, - { 17.17, 18.18, 19.19, 20.20, - 21.21, 22.22, 23.23, 24.24, - 25.25, 26.26, 27.27, 28.28, - 29.29, 30.30, 31.31, 32.32 } }; - cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; - cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; - subtract2m(m2i[0], m2i[1]); - cout << setw(40) << "subtract2m(m2i[0], m2i[1])" << getstring2m(m2i[0], s) << endl; - - cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; - cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; - subtract3m(m3f[0], m3f[1]); - cout << setw(40) << "subtract3m(m3f[0], m3f[1])" << getstring3m(m3f[0], s) << endl; - - cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; - cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; - subtract4m(m4d[0], m4d[1]); - cout << setw(40) << "subtract4m(m3d[0], m3d[1])" << getstring4m(m4d[0], s) << endl; - } - - { - cout << "===============================================================" << endl << - "Testing Matrix::scale*()" << endl; - Matrix2i m2i = { 1, 2, - 3, 4 }; - Matrix3f m3f = { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }; - Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }; - cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; - cout << setw(40) << "scale2m(m2i, 2)" << getstring2m(scale2m(m2i, 2), s) << endl; - - cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; - cout << setw(40) << "scale3m(m3f, 2.2f)" << getstring3m(scale3m(m3f, 2.2f), s) << endl; - - cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; - cout << setw(40) << "scale4m(m3d, 2.2)" << getstring4m(scale4m(m4d, 2.2), s) << endl; - } - - { - cout << "===============================================================" << endl << - "Testing Matrix::multvec*()" << endl; - Vector2i v2ires; - Vector3f v3fres; - Vector4d v4dres; - Vector2i v2i = { 1, 2 }; - Vector3f v3f = { 1.1f, 2.2f, 3.3f }; - Vector4d v4d = { 1.1, 2.2, 3.3, 4.4 }; - Matrix2i m2i = { 1, 2, - 3, 4 }; - Matrix3f m3f = { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }; - Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }; - cout << setw(40) << "v2i" << getstring2v(v2i, s) << endl; - cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; - cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" << - getstring2v(multvec2mv(m2i, v2i, v2ires), s) << endl; - cout << setw(40) << "multvec2mv(m2i, v2i, v2ires)" << - getstring2v(multvec2vm(v2i, m2i, v2ires), s) << endl; - - cout << setw(40) << "v3f" << getstring3v(v3f, s) << endl; - cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; - cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" << - getstring3v(multvec3mv(m3f, v3f, v3fres), s) << endl; - cout << setw(40) << "multvec3mv(m3f, v3f, v3fres)" << - getstring3v(multvec3vm(v3f, m3f, v3fres), s) << endl; - - cout << setw(40) << "v4d" << getstring4v(v4d, s) << endl; - cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; - cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" << - getstring4v(multvec4mv(m4d, v4d, v4dres), s) << endl; - cout << setw(40) << "multvec4mv(m4d, v4d, v4dres)" << - getstring4v(multvec4vm(v4d, m4d, v4dres), s) << endl; - - } - - - { - cout << "===============================================================" << endl << - "Testing Matrix::multmat*()" << endl; - Matrix2i m2ires; - Matrix3f m3fres; - Matrix4d m4dres; - Matrix2i m2i[2] = { { 1, 2, - 3, 4 }, - { 5, 6, - 7, 8 } }; - Matrix3f m3f[2] = { { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }, - { 10.10f, 11.11f, 12.12f, - 13.13f, 14.14f, 15.15f, - 16.16f, 17.17f, 18.18f } }; - Matrix4d m4d[2] = { { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }, - { 17.17, 18.18, 19.19, 20.20, - 21.21, 22.22, 23.23, 24.24, - 25.25, 26.26, 27.27, 28.28, - 29.29, 30.30, 31.31, 32.32 } }; - cout << setw(40) << "m2i[0]" << getstring2m(m2i[0], s) << endl; - cout << setw(40) << "m2i[1]" << getstring2m(m2i[1], s) << endl; - multmat2(m2i[0], m2i[1], m2ires); - cout << setw(40) << "multmat2(m2i[0], m2i[1], m21res)" << - getstring2m(m2ires, s) << endl; - - cout << setw(40) << "m3f[0]" << getstring3m(m3f[0], s) << endl; - cout << setw(40) << "m3f[1]" << getstring3m(m3f[1], s) << endl; - multmat3(m3f[0], m3f[1], m3fres); - cout << setw(40) << "multmat3(m3f[0], m3f[1], m3fres)" << - getstring3m(m3fres, s) << endl; - - cout << setw(40) << "m4d[0]" << getstring4m(m4d[0], s) << endl; - cout << setw(40) << "m4d[1]" << getstring4m(m4d[1], s) << endl; - multmat4(m4d[0], m4d[1], m4dres); - cout << setw(40) << "multmat4(m4d[0], m4d[1], m4dres)" << - getstring4m(m4dres, s) << endl; - } - - { - cout << "===============================================================" << endl << - "Testing Matrix::transpose*()" << endl; - Matrix2i m2ires; - Matrix3f m3fres; - Matrix4d m4dres; - Matrix2i m2i = { 1, 2, - 3, 4 }; - Matrix3f m3f = { 1.1f, 2.2f, 3.3f, - 4.4f, 5.5f, 6.6f, - 7.7f, 8.8f, 9.9f }; - Matrix4d m4d = { 1.1, 2.2, 3.3, 4.4, - 5.5, 6.6, 7.7, 8.8, - 9.9, 10.10, 11.11, 12.12, - 13.13, 14.14, 15.15, 16.16 }; - cout << setw(40) << "m2i" << getstring2m(m2i, s) << endl; - cout << setw(40) << "transpose2(m2i, m2ires)" << - getstring2m(transpose2(m2i, m2ires), s) << endl; - - cout << setw(40) << "m3f" << getstring3m(m3f, s) << endl; - cout << setw(40) << "transpose3(m3f, m3fres)" << - getstring3m(transpose3(m3f, m3fres), s) << endl; - - cout << setw(40) << "m4d" << getstring4m(m4d, s) << endl; - cout << setw(40) << "transpose4(m4d, m4dres)" << - getstring4m(transpose4(m4d, m4dres), s) << endl; - - } + string s; } ////////////////////////////////////////////////////////////////////////////////