changeset 13:e00321d11fe1

to_string simplified. Added Vector constructors from smaller vectors. Added rotation and transform matrix calculation functions.
author Eris Caffee <discordia@eldalin.com>
date Wed, 08 May 2013 22:50:09 -0500
parents 1d2b25d4517f
children c029247daf0e
files include/Math.h include/Matrix.h include/Vector.h
diffstat 3 files changed, 474 insertions(+), 441 deletions(-) [+]
line diff
     1.1 --- a/include/Math.h	Mon May 06 01:06:12 2013 -0500
     1.2 +++ b/include/Math.h	Wed May 08 22:50:09 2013 -0500
     1.3 @@ -105,7 +105,7 @@
     1.4  	 Vector4<T> vres(0);
     1.5  	 vres[0] = v[0]*m[0] + v[1]*m[1] + v[2]*m[2] + v[3]*m[3];
     1.6  	 vres[1] = v[0]*m[4] + v[1]*m[5] + v[2]*m[6] + v[3]*m[7];
     1.7 -	 vres[8] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11];
     1.8 +	 vres[2] = v[0]*m[8] + v[1]*m[9] + v[2]*m[10] + v[3]*m[11];
     1.9  	 vres[3] = v[0]*m[12] + v[1]*m[13] + v[2]*m[14] + v[3]*m[15];
    1.10  	 v = vres;
    1.11  	 return v;
    1.12 @@ -133,7 +133,10 @@
    1.13        //////////////////////////////////////////////////////////////////////////
    1.14  
    1.15        template <typename T>
    1.16 -      void get_rot_mat33(Matrix33<T> & m, float rot, Vector3<T> v);
    1.17 +      void get_rot_mat33(Matrix33<T> & m, float angle, Vector3<T> v);
    1.18 +
    1.19 +      template <typename T>
    1.20 +      void get_transform_mat44(Matrix33<T> & m, float angle, Vector3<T> v, Vector3<T> o);
    1.21  
    1.22  
    1.23        //////////////////////////////////////////////////////////////////////////
    1.24 @@ -147,20 +150,20 @@
    1.25  
    1.26  ////////////////////////////////////////////////////////////////////////////////
    1.27  template <typename T>
    1.28 -void arda::Math::get_rot_mat33(arda::Math::Matrix33<T> & m, float theta, arda::Math::Vector3<T> v)
    1.29 +void arda::Math::get_rot_mat33(arda::Math::Matrix33<T> & m, float angle, arda::Math::Vector3<T> v)
    1.30      {
    1.31 -    m.setidentity();
    1.32 +    // TODO Replace == comparision of floating point number!
    1.33      if (0.0 == v.length())
    1.34          return;
    1.35  
    1.36 -    // TODO: I should also immediately return identity if theta is a multiple of 2*PI but I'm not
    1.37 +    // TODO: I should also immediately return identity if angle is a multiple of 2*PI but I'm not
    1.38      // yet sure how I should I check for that (taking into account floating point imprecision).
    1.39  
    1.40  
    1.41      v.normalize();
    1.42  
    1.43 -    float c = cos(theta);
    1.44 -    float s = sin(theta);
    1.45 +    float c = cos(angle);
    1.46 +    float s = sin(angle);
    1.47      float one_minus_c = 1.0f - c;
    1.48  
    1.49      m.assign(
    1.50 @@ -170,4 +173,35 @@
    1.51      );
    1.52      }
    1.53  
    1.54 +////////////////////////////////////////////////////////////////////////////////
    1.55 +template <typename T>
    1.56 +void arda::Math::get_transform_mat44(arda::Math::Matrix44<T> & m, 
    1.57 +    float angle, arda::Math::Vector3<T> v,
    1.58 +    arda::Math::Vector3<T> p)
    1.59 +    {
    1.60 +    arda::Math::Matrix33f m33(0);
    1.61 +    get_rot_mat33(m33, angle, v);
    1.62 +    arda::Math::Vector3f p1 = m33 * p;
    1.63 +
    1.64 +    m[0] = m33[0];
    1.65 +    m[1] = m33[1];
    1.66 +    m[2] = m33[2];
    1.67 +    m[3] = 0.0f;
    1.68 +
    1.69 +    m[4] = m33[3];
    1.70 +    m[5] = m33[4];
    1.71 +    m[6] = m33[5];
    1.72 +    m[7] = 0.0f;
    1.73 +
    1.74 +    m[8] = m33[6];
    1.75 +    m[9] = m33[7];
    1.76 +    m[10] = m33[8];
    1.77 +    m[11] = 0.0f;
    1.78 +
    1.79 +    m[12] = p.x - p1.x;
    1.80 +    m[13] = p.y - p1.y;
    1.81 +    m[14] = p.z - p1.z;
    1.82 +    m[15] = 1.0f;
    1.83 +    }
    1.84 +
    1.85  #endif
     2.1 --- a/include/Matrix.h	Mon May 06 01:06:12 2013 -0500
     2.2 +++ b/include/Matrix.h	Wed May 08 22:50:09 2013 -0500
     2.3 @@ -236,7 +236,7 @@
     2.4  	    return *this;
     2.5  	    }
     2.6  
     2.7 -	 std::string & to_string(std::string & s) const;
     2.8 +	 std::string to_string(void) const;
     2.9  
    2.10  	 inline Matrix22<T>& setidentity()
    2.11  	    {
    2.12 @@ -487,7 +487,7 @@
    2.13  	    return *this;
    2.14  	    }
    2.15  
    2.16 -	 std::string & to_string(std::string & s) const;
    2.17 +	 std::string to_string(void) const;
    2.18  
    2.19  	 inline Matrix33<T>& setidentity()
    2.20  	    {
    2.21 @@ -758,7 +758,7 @@
    2.22  	    return *this;
    2.23  	    }
    2.24  
    2.25 -	 std::string & to_string(std::string & s) const;
    2.26 +	 std::string to_string(void) const;
    2.27  
    2.28  	 inline Matrix44<T>& setidentity()
    2.29  	    {
    2.30 @@ -891,43 +891,37 @@
    2.31  // Matrix methods
    2.32  
    2.33  template <typename T> 
    2.34 -std::string & arda::Math::Matrix22<T>::to_string(std::string & s) const
    2.35 +std::string arda::Math::Matrix22<T>::to_string(void) const
    2.36     {
    2.37 -   s.clear();
    2.38     std::stringstream ss;
    2.39     ss << "[ "
    2.40  	 "[ " << m[0] << ", " << m[1] << " ], "
    2.41  	 "[ " << m[2] << ", " << m[3] << " ] ]";
    2.42 -   s = ss.str();
    2.43 -   return s;   
    2.44 +   return ss.str();
    2.45     }
    2.46  
    2.47  template <typename T> 
    2.48 -std::string & arda::Math::Matrix33<T>::to_string(std::string & s) const
    2.49 +std::string arda::Math::Matrix33<T>::to_string(void) const
    2.50     {
    2.51 -   s.clear();
    2.52     std::stringstream ss;
    2.53     ss << "[ "
    2.54  	 "[ " << m[0] << ", " << m[1] << ", " << m[2] << " ], "
    2.55  	 "[ " << m[3] << ", " << m[4] << ", " << m[5] << " ], "
    2.56  	 "[ " << m[6] << ", " << m[7] << ", " << m[8] << " ], ""]";
    2.57 -   s = ss.str();
    2.58 -   return s;   
    2.59 +   return ss.str();
    2.60     }
    2.61  
    2.62  
    2.63  template <typename T> 
    2.64 -std::string & arda::Math::Matrix44<T>::to_string(std::string & s) const
    2.65 +std::string arda::Math::Matrix44<T>::to_string(void) const
    2.66     {
    2.67 -   s.clear();
    2.68     std::stringstream ss;
    2.69     ss << "[ "
    2.70  	 "[ " << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << " ], "
    2.71  	 "[ " << m[4] << ", " << m[5] << ", " << m[6] << ", " << m[7] << " ], "
    2.72  	 "[ " << m[8] << ", " << m[9] << ", " << m[10] << ", " << m[11] << " ], "
    2.73  	 "[ " << m[12] << ", " << m[13] << ", " << m[14] << ", " << m[15] << " ], ""]";
    2.74 -   s = ss.str();
    2.75 -   return s;   
    2.76 +   return ss.str();
    2.77     }
    2.78  
    2.79  #endif // MATRIX_H_
     3.1 --- a/include/Vector.h	Mon May 06 01:06:12 2013 -0500
     3.2 +++ b/include/Vector.h	Wed May 08 22:50:09 2013 -0500
     3.3 @@ -9,512 +9,517 @@
     3.4  
     3.5  
     3.6  namespace arda 
     3.7 -   {
     3.8 -   namespace Math
     3.9 -      {
    3.10 -      ////////////////////////////////////////////////////////////////////////////////
    3.11 -      // Vectors
    3.12 -      //
    3.13 -      // Templated classes for 2, 3, and 4 dimensional vectors of any type,
    3.14 -      //     although these types are really intended to be int, float, and double 
    3.15 -      //     only.  (i.e. if you roll your own base type, it had better act like
    3.16 -      //     a numeric scalar.)
    3.17 -      //
    3.18 -      // Supported operations on vectors
    3.19 -      //
    3.20 -      // Construction
    3.21 -      //     Vector v;             // Default zero vector.
    3.22 -      //     Vector v2(v);         // Construct from other vector.
    3.23 -      //     T a, b;
    3.24 -      //     Vector v(a, b)        // Construct from values.
    3.25 -      // []
    3.26 -      //     If you have a Vector named v you can access it's member elements as
    3.27 -      //     v[0], v[1], v[2], and v[3]. in addtion to v.x, v.y, v.z, and v.w
    3.28 -      // == != + += - -=
    3.29 -      //     Defined for operations on two vectors of the same type.
    3.30 -      // * *= / /=
    3.31 -      //     Defined for scalar multiplication/division with int, float, and double.
    3.32 -      //     * is defined as a standalone template operator for the scalar * Vector form.
    3.33 -      // assign(T a, T b [, T b [, T d]])
    3.34 -      //     Directly assign values to the vector.
    3.35 -      // cross(Vector3& v2)
    3.36 -      // cross(Vector3& v2, Vector3& vres)
    3.37 -      //     Cross product of the vector with v2.  Only defined for Vector3 types.
    3.38 -      //     The version that takes two arguments stores the result in the second
    3.39 -      //     argument.  This may be faster since no temporary object is created
    3.40 -      //     during the operation.
    3.41 -      // dot(Vector& v2)
    3.42 -      //     The dot product of the vector with v2.
    3.43 -      // get_angle(Vector& v2)
    3.44 -      //     Returns the angle (in radians) between the vector and v2.
    3.45 -      //     Not meaningful for int vectors.
    3.46 -      // get_anglen(Vector& v2)
    3.47 -      //     Like get_angle(), but the vectors must already be normalized.
    3.48 -      //     Not meaningful for int vectors.
    3.49 -      // to_string(std::string & s)
    3.50 -      //     Returns a C string representation of the vector.
    3.51 -      //     This is one of the few non-inline Vector functions.
    3.52 -      // length()
    3.53 -      //     Get the length of a vector.
    3.54 -      //     Returns a double for all vector types.
    3.55 -      // normalize()
    3.56 -      //     Normalizes the vector.
    3.57 -      //     Not meaningful for int vectors.
    3.58 -      // proj(Vector& v2, Vector& vres)
    3.59 -      //     Calculates the projection of the vector onto v2 and returns the result 
    3.60 -      //     in vres. 
    3.61 -      //     Not meaningful for int vectors.
    3.62 -      //     Returns vres.
    3.63 -      //
    3.64 -      //
    3.65 -      // Note that the following typedefs are defined for convenience:
    3.66 -      //
    3.67 -      // typedef Vector2<int> Vector2i;
    3.68 -      // typedef Vector2<float> Vector2f;
    3.69 -      // typedef Vector2<double> Vector2d;
    3.70 -      // typedef Vector3<int> Vector3i;
    3.71 -      // typedef Vector3<float> Vector3f;
    3.72 -      // typedef Vector3<double> Vector3d;
    3.73 -      // typedef Vector4<int> Vector4i;
    3.74 -      // typedef Vector4<float> Vector4f;
    3.75 -      // typedef Vector4<double> Vector4d;
    3.76 -      //
    3.77 -      //
    3.78 -      //
    3.79 -      // Scalar multiplication and division are overloaded.  Why?
    3.80 -      // I'm not sure I need this.  The idea is to support all likely scalar
    3.81 -      // types without having to rely on implicit or explicit type conversion,
    3.82 -      // especially not a conversion that might result in loss of precision.
    3.83 -      // Multiplying a float Vector by a double scalar, for example.
    3.84 -      //
    3.85 -      // Is there a better way to do this?  Am I worrying about nothing?
    3.86 -      //
    3.87 -      //
    3.88 -      //
    3.89 -      // I suppose I could make this into a single Vector template on two parameters
    3.90 -      // template <typename T, unsigned int N> class Vector
    3.91 -      //    {
    3.92 -      //    T v[N];
    3.93 -      //
    3.94 -      //    etc...
    3.95 -      //
    3.96 -      // This might buy perfect generality, but it would come at the expense of
    3.97 -      // loops in all of the code, so I don't think it would really be worth it.
    3.98 +    {
    3.99 +    namespace Math
   3.100 +        {
   3.101 +        ////////////////////////////////////////////////////////////////////////////////
   3.102 +        // Vectors
   3.103 +        //
   3.104 +        // Templated classes for 2, 3, and 4 dimensional vectors of any type,
   3.105 +        //     although these types are really intended to be int, float, and double 
   3.106 +        //     only.  (i.e. if you roll your own base type, it had better act like
   3.107 +        //     a numeric scalar.)
   3.108 +        //
   3.109 +        // Supported operations on vectors
   3.110 +        //
   3.111 +        // Construction
   3.112 +        //     Vector v;             // Default zero vector.
   3.113 +        //     Vector v2(v);         // Construct from other vector.
   3.114 +        //     T a, b;
   3.115 +        //     Vector v(a, b)        // Construct from values.
   3.116 +        // []
   3.117 +        //     If you have a Vector named v you can access it's member elements as
   3.118 +        //     v[0], v[1], v[2], and v[3]. in addtion to v.x, v.y, v.z, and v.w
   3.119 +        // == != + += - -=
   3.120 +        //     Defined for operations on two vectors of the same type.
   3.121 +        // * *= / /=
   3.122 +        //     Defined for scalar multiplication/division with int, float, and double.
   3.123 +        //     * is defined as a standalone template operator for the scalar * Vector form.
   3.124 +        // assign(T a, T b [, T b [, T d]])
   3.125 +        //     Directly assign values to the vector.
   3.126 +        // cross(Vector3& v2)
   3.127 +        // cross(Vector3& v2, Vector3& vres)
   3.128 +        //     Cross product of the vector with v2.  Only defined for Vector3 types.
   3.129 +        //     The version that takes two arguments stores the result in the second
   3.130 +        //     argument.  This may be faster since no temporary object is created
   3.131 +        //     during the operation.
   3.132 +        // dot(Vector& v2)
   3.133 +        //     The dot product of the vector with v2.
   3.134 +        // get_angle(Vector& v2)
   3.135 +        //     Returns the angle (in radians) between the vector and v2.
   3.136 +        //     Not meaningful for int vectors.
   3.137 +        // get_anglen(Vector& v2)
   3.138 +        //     Like get_angle(), but the vectors must already be normalized.
   3.139 +        //     Not meaningful for int vectors.
   3.140 +        // to_string(std::string & s)
   3.141 +        //     Returns a C string representation of the vector.
   3.142 +        //     This is one of the few non-inline Vector functions.
   3.143 +        // length()
   3.144 +        //     Get the length of a vector.
   3.145 +        //     Returns a double for all vector types.
   3.146 +        // normalize()
   3.147 +        //     Normalizes the vector.
   3.148 +        //     Not meaningful for int vectors.
   3.149 +        // proj(Vector& v2, Vector& vres)
   3.150 +        //     Calculates the projection of the vector onto v2 and returns the result 
   3.151 +        //     in vres. 
   3.152 +        //     Not meaningful for int vectors.
   3.153 +        //     Returns vres.
   3.154 +        //
   3.155 +        //
   3.156 +        // Note that the following typedefs are defined for convenience:
   3.157 +        //
   3.158 +        // typedef Vector2<int> Vector2i;
   3.159 +        // typedef Vector2<float> Vector2f;
   3.160 +        // typedef Vector2<double> Vector2d;
   3.161 +        // typedef Vector3<int> Vector3i;
   3.162 +        // typedef Vector3<float> Vector3f;
   3.163 +        // typedef Vector3<double> Vector3d;
   3.164 +        // typedef Vector4<int> Vector4i;
   3.165 +        // typedef Vector4<float> Vector4f;
   3.166 +        // typedef Vector4<double> Vector4d;
   3.167 +        //
   3.168 +        //
   3.169 +        //
   3.170 +        // Scalar multiplication and division are overloaded.  Why?
   3.171 +        // I'm not sure I need this.  The idea is to support all likely scalar
   3.172 +        // types without having to rely on implicit or explicit type conversion,
   3.173 +        // especially not a conversion that might result in loss of precision.
   3.174 +        // Multiplying a float Vector by a double scalar, for example.
   3.175 +        //
   3.176 +        // Is there a better way to do this?  Am I worrying about nothing?
   3.177 +        //
   3.178 +        //
   3.179 +        //
   3.180 +        // I suppose I could make this into a single Vector template on two parameters
   3.181 +        // template <typename T, unsigned int N> class Vector
   3.182 +        //    {
   3.183 +        //    T v[N];
   3.184 +        //
   3.185 +        //    etc...
   3.186 +        //
   3.187 +        // This might buy perfect generality, but it would come at the expense of
   3.188 +        // loops in all of the code, so I don't think it would really be worth it.
   3.189        
   3.190        
   3.191 -      /////////////////////////////////////////////////////////////////////////////
   3.192 -      template <typename T> 
   3.193 -      class Vector2
   3.194 -	 {
   3.195 -	 public:
   3.196 -	 T x, y;
   3.197 +        /////////////////////////////////////////////////////////////////////////////
   3.198 +        template <typename T> 
   3.199 +        class Vector2
   3.200 +            {
   3.201 +        public:
   3.202 +            T x, y;
   3.203  	 
   3.204 -	 // Constructors
   3.205 -	 Vector2() {}
   3.206 -	 explicit Vector2(T a) : x (a), y(a) {}
   3.207 -	 Vector2(T a, T b) : x (a), y(b) {}
   3.208 +            // Constructors
   3.209 +            Vector2() {}
   3.210 +            explicit Vector2(T a) : x (a), y(a) {}
   3.211 +            Vector2(T a, T b) : x (a), y(b) {}
   3.212  
   3.213 -	 // Array indexing
   3.214 -	 inline T& operator[](unsigned int const i)
   3.215 -	    { assert (i<2); if (i==0) return x; return y; }
   3.216 -	 inline T operator[](unsigned int const i) const
   3.217 -	    { assert (i<2); if (i==0) return x; return y; }
   3.218 +            // Array indexing
   3.219 +            inline T& operator[](unsigned int const i)
   3.220 +                { assert (i<2); if (i==0) return x; return y; }
   3.221 +            inline T operator[](unsigned int const i) const
   3.222 +                { assert (i<2); if (i==0) return x; return y; }
   3.223  
   3.224 -	 // Assignment
   3.225 -	 inline Vector2<T>& operator=(Vector2<T> const & v2)
   3.226 -	    { x = v2.x; y = v2.y; return *this; }
   3.227 -	 inline Vector2<T>& assign(T const a, T const b)
   3.228 -	    { x = a; y = b; return *this; }
   3.229 +            // Assignment
   3.230 +            inline Vector2<T>& operator=(Vector2<T> const & v2)
   3.231 +                { x = v2.x; y = v2.y; return *this; }
   3.232 +            inline Vector2<T>& assign(T const a, T const b)
   3.233 +                { x = a; y = b; return *this; }
   3.234  
   3.235 -	 // Comparison
   3.236 -	 inline bool operator==(Vector2<T> const & v2) const
   3.237 -	    { return ((x == v2.x) && (y == v2.y)); }
   3.238 -	 inline bool operator!=(Vector2<T> const & v2) const
   3.239 -	    { return ! (*this == v2); }
   3.240 +            // Comparison
   3.241 +            inline bool operator==(Vector2<T> const & v2) const
   3.242 +                { return ((x == v2.x) && (y == v2.y)); }
   3.243 +            inline bool operator!=(Vector2<T> const & v2) const
   3.244 +                { return ! (*this == v2); }
   3.245  
   3.246 -	 // Vector addition
   3.247 -	 inline Vector2<T>& operator+=(Vector2<T> const & v2)
   3.248 -	    { x += v2.x; y += v2.y; return *this; }
   3.249 -	 inline Vector2<T> operator+(Vector2<T> const & v2) const
   3.250 -	    { return Vector2<T>(*this) += v2; }
   3.251 +            // Vector addition
   3.252 +            inline Vector2<T>& operator+=(Vector2<T> const & v2)
   3.253 +                { x += v2.x; y += v2.y; return *this; }
   3.254 +            inline Vector2<T> operator+(Vector2<T> const & v2) const
   3.255 +                { return Vector2<T>(*this) += v2; }
   3.256  
   3.257 -	 // Vector subtraction
   3.258 -	 inline Vector2<T>& operator-=(Vector2<T> const & v2)
   3.259 -	    { x -= v2.x; y -= v2.y; return *this; }
   3.260 -	 inline Vector2<T> operator-(Vector2<T> const & v2) const
   3.261 -	    { return Vector2<T>(*this) -= v2; }
   3.262 +            // Vector subtraction
   3.263 +            inline Vector2<T>& operator-=(Vector2<T> const & v2)
   3.264 +                { x -= v2.x; y -= v2.y; return *this; }
   3.265 +            inline Vector2<T> operator-(Vector2<T> const & v2) const
   3.266 +                { return Vector2<T>(*this) -= v2; }
   3.267  
   3.268 -	 // Scalar multiplication
   3.269 -	 inline Vector2<T>& operator*=(int const a)
   3.270 -	    { x *= a; y *= a; return *this; }
   3.271 -	 inline Vector2<T>& operator*=(float const a)
   3.272 -	    { x *= a; y *= a; return *this; }
   3.273 -	 inline Vector2<T>& operator*=(double const a)
   3.274 -	    { x *= a; y *= a; return *this; }
   3.275 +            // Scalar multiplication
   3.276 +            inline Vector2<T>& operator*=(int const a)
   3.277 +                { x *= a; y *= a; return *this; }
   3.278 +            inline Vector2<T>& operator*=(float const a)
   3.279 +                { x *= a; y *= a; return *this; }
   3.280 +            inline Vector2<T>& operator*=(double const a)
   3.281 +                { x *= a; y *= a; return *this; }
   3.282  
   3.283 -	 inline Vector2<T> operator*(int const a) const
   3.284 -	    { return Vector2<T>(*this) *= a;}
   3.285 -	 inline Vector2<T> operator*(float const a) const
   3.286 -	    { return Vector2<T>(*this) *= a;}
   3.287 -	 inline Vector2<T> operator*(double const a) const
   3.288 -	    { return Vector2<T>(*this) *= a;}
   3.289 +            inline Vector2<T> operator*(int const a) const
   3.290 +                { return Vector2<T>(*this) *= a;}
   3.291 +            inline Vector2<T> operator*(float const a) const
   3.292 +                { return Vector2<T>(*this) *= a;}
   3.293 +            inline Vector2<T> operator*(double const a) const
   3.294 +                { return Vector2<T>(*this) *= a;}
   3.295  
   3.296 -	 // Scalar division
   3.297 -	 inline Vector2<T>& operator/=(int const a)
   3.298 -	    { assert(a!=0); x /= a; y /= a; return *this; }
   3.299 -	 inline Vector2<T>& operator/=(float const a)
   3.300 -	    { assert(a!=0); x /= a; y /= a; return *this; }
   3.301 -	 inline Vector2<T>& operator/=(double const a)
   3.302 -	    { assert(a!=0); x /= a; y /= a; return *this; }
   3.303 +            // Scalar division
   3.304 +            inline Vector2<T>& operator/=(int const a)
   3.305 +                { assert(a!=0); x /= a; y /= a; return *this; }
   3.306 +            inline Vector2<T>& operator/=(float const a)
   3.307 +                { assert(a!=0); x /= a; y /= a; return *this; }
   3.308 +            inline Vector2<T>& operator/=(double const a)
   3.309 +                { assert(a!=0); x /= a; y /= a; return *this; }
   3.310  
   3.311 -	 inline Vector2<T> operator/(int const a) const
   3.312 -	    { return Vector2<T>(*this) /= a;}
   3.313 -	 inline Vector2<T> operator/(float const a) const
   3.314 -	    { return Vector2<T>(*this) /= a;}
   3.315 -	 inline Vector2<T> operator/(double const a) const
   3.316 -	    { return Vector2<T>(*this) /= a;}
   3.317 +            inline Vector2<T> operator/(int const a) const
   3.318 +                { return Vector2<T>(*this) /= a;}
   3.319 +            inline Vector2<T> operator/(float const a) const
   3.320 +                { return Vector2<T>(*this) /= a;}
   3.321 +            inline Vector2<T> operator/(double const a) const
   3.322 +                { return Vector2<T>(*this) /= a;}
   3.323  
   3.324  
   3.325 -	 // methods
   3.326 +            // methods
   3.327  
   3.328 -	 inline T dot(Vector2<T> const & v2) const
   3.329 -	    { return x*v2.x + y*v2.y; }
   3.330 +            inline T dot(Vector2<T> const & v2) const
   3.331 +                { return x*v2.x + y*v2.y; }
   3.332  
   3.333 -	 inline double get_angle(Vector2<T> const & v2)
   3.334 -	    { 
   3.335 -	    double tmp = dot(v2); 
   3.336 -	    return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.337 -	    }
   3.338 +            inline double get_angle(Vector2<T> const & v2)
   3.339 +                { 
   3.340 +                double tmp = dot(v2); 
   3.341 +                return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.342 +                }
   3.343  
   3.344 -	 inline double get_anglen(Vector2<T> const & v2)
   3.345 -	    { return acos((double) dot(v2)); }
   3.346 +            inline double get_anglen(Vector2<T> const & v2)
   3.347 +                { return acos((double) dot(v2)); }
   3.348  
   3.349 -	 std::string & to_string(std::string & s) const;
   3.350 +            std::string to_string(void) const;
   3.351  
   3.352 -	 inline double length(void) const
   3.353 -	    { return sqrt((dot(*this))); }
   3.354 +            inline double length(void) const
   3.355 +                { return sqrt((dot(*this))); }
   3.356  
   3.357 -	 inline Vector2<T>& normalize()
   3.358 -	    { 
   3.359 -	    double l = length(); 
   3.360 -	    if (l == 0.0) return *this; 
   3.361 -	    x /= l; y /= l; 
   3.362 -	    return *this; }
   3.363 +            inline Vector2<T>& normalize()
   3.364 +                { 
   3.365 +                double l = length(); 
   3.366 +                if (l == 0.0) return *this; 
   3.367 +                x /= l; y /= l; 
   3.368 +                return *this; }
   3.369  
   3.370 -	 inline Vector2<T> proj(Vector2<T> const & v2)
   3.371 -	    { Vector2<T> vres; vres = v2 * (dot(v2)/v2.dot(v2)); return vres; }
   3.372 -	 inline Vector2<T>& proj(Vector2<T> const & v2, Vector2<T>& vres)
   3.373 -	    { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.374 -	 };
   3.375 +            inline Vector2<T> proj(Vector2<T> const & v2)
   3.376 +                { Vector2<T> vres; vres = v2 * (dot(v2)/v2.dot(v2)); return vres; }
   3.377 +            inline Vector2<T>& proj(Vector2<T> const & v2, Vector2<T>& vres)
   3.378 +                { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.379 +            };
   3.380  
   3.381 -      // Scalar multiplication, continued
   3.382 -      template <typename T> 
   3.383 -      inline Vector2<T> operator*(int const a, Vector2<T> const & v)
   3.384 -	 { return Vector2<T>(v) *= a;}
   3.385 +        // Scalar multiplication, continued
   3.386 +        template <typename T> 
   3.387 +        inline Vector2<T> operator*(int const a, Vector2<T> const & v)
   3.388 +            { return Vector2<T>(v) *= a;}
   3.389  
   3.390 -      template <typename T> 
   3.391 -      inline Vector2<T> operator*(float const a, Vector2<T> const & v)
   3.392 -	 { return Vector2<T>(v) *= a;}
   3.393 +        template <typename T> 
   3.394 +        inline Vector2<T> operator*(float const a, Vector2<T> const & v)
   3.395 +            { return Vector2<T>(v) *= a;}
   3.396  
   3.397 -      template <typename T> 
   3.398 -      inline Vector2<T> operator*(double const a, Vector2<T> const & v)
   3.399 -	 { return Vector2<T>(v) *= a;}
   3.400 +        template <typename T> 
   3.401 +        inline Vector2<T> operator*(double const a, Vector2<T> const & v)
   3.402 +            { return Vector2<T>(v) *= a;}
   3.403  
   3.404  
   3.405 -      /////////////////////////////////////////////////////////////////////////////
   3.406 -      template <typename T> 
   3.407 -      class Vector3
   3.408 -	 {
   3.409 -	 public:
   3.410 -	 T x, y, z;
   3.411 +        /////////////////////////////////////////////////////////////////////////////
   3.412 +        template <typename T> 
   3.413 +        class Vector3
   3.414 +            {
   3.415 +        public:
   3.416 +            T x, y, z;
   3.417  
   3.418 -	 // Constructors
   3.419 -	 Vector3() {}
   3.420 -	 explicit Vector3(T a) : x (a), y(a), z(a) {}
   3.421 -	 Vector3(T a, T b, T c) : x (a), y(b), z(c) {}
   3.422 +            // Constructors
   3.423 +            Vector3() {}
   3.424 +            explicit Vector3(T a) : x (a), y(a), z(a) {}
   3.425 +            Vector3(T a, T b, T c) : x (a), y(b), z(c) {}
   3.426 +            Vector3(Vector2<T> v) : x (v.x), y (v.y), z (0) {}
   3.427  
   3.428 -	 // Array indexing
   3.429 -	 inline T& operator[](unsigned int const i)
   3.430 -	    { assert (i<3); if (i==0) return x; if (i==1) return y; return z; }
   3.431 -	 inline T operator[](unsigned int const i) const
   3.432 -	    { assert (i<3); if (i==0) return x; if (i==1) return y; return z; }
   3.433 +            // Array indexing
   3.434 +            inline T& operator[](unsigned int const i)
   3.435 +                { assert (i<3); if (i==0) return x; if (i==1) return y; return z; }
   3.436 +            inline T operator[](unsigned int const i) const
   3.437 +                { assert (i<3); if (i==0) return x; if (i==1) return y; return z; }
   3.438  
   3.439 -	 // Assignment
   3.440 -	 inline Vector3<T>& operator=(Vector3<T> const & v2)
   3.441 -	    { x = v2.x; y = v2.y; z = v2.z; return *this; }
   3.442 -	 inline Vector3<T>& assign(T const a, T const b, T const c)
   3.443 -	    { x = a; y = b; z = c; return *this; }
   3.444 +            // Assignment
   3.445 +            inline Vector3<T>& operator=(Vector2<T> const & v2)
   3.446 +                { x = v2.x; y = v2.y; z = 0; return *this; }
   3.447 +            inline Vector3<T>& operator=(Vector3<T> const & v2)
   3.448 +                { x = v2.x; y = v2.y; z = v2.z; return *this; }
   3.449  
   3.450 -	 // Comparison
   3.451 -	 inline bool operator==(Vector3<T> const & v2) const
   3.452 -	    { return ((x == v2.x) && (y == v2.y) && (z == v2.z)); }
   3.453 -	 inline bool operator!=(Vector3<T> const & v2) const
   3.454 -	    { return ! (*this == v2); }
   3.455 +            inline Vector3<T>& assign(T const a, T const b, T const c)
   3.456 +                { x = a; y = b; z = c; return *this; }
   3.457  
   3.458 -	 // Vector addition
   3.459 -	 inline Vector3<T>& operator+=(Vector3<T> const & v2)
   3.460 -	    { x += v2.x; y += v2.y; z += v2.z; return *this; }
   3.461 -	 inline Vector3<T> operator+(Vector3<T> const & v2) const
   3.462 -	    { return Vector3<T>(*this) += v2; }
   3.463 +            // Comparison
   3.464 +            inline bool operator==(Vector3<T> const & v2) const
   3.465 +                { return ((x == v2.x) && (y == v2.y) && (z == v2.z)); }
   3.466 +            inline bool operator!=(Vector3<T> const & v2) const
   3.467 +                { return ! (*this == v2); }
   3.468  
   3.469 -	 // Vector subtraction
   3.470 -	 inline Vector3<T>& operator-=(Vector3<T> const & v2)
   3.471 -	    { x -= v2.x; y -= v2.y; z -= v2.z; return *this; }
   3.472 -	 inline Vector3<T> operator-(Vector3<T> const & v2) const
   3.473 -	    { return Vector3<T>(*this) -= v2; }
   3.474 +            // Vector addition
   3.475 +            inline Vector3<T>& operator+=(Vector3<T> const & v2)
   3.476 +                { x += v2.x; y += v2.y; z += v2.z; return *this; }
   3.477 +            inline Vector3<T> operator+(Vector3<T> const & v2) const
   3.478 +                { return Vector3<T>(*this) += v2; }
   3.479  
   3.480 -	 // Scalar multiplication
   3.481 -	 inline Vector3<T>& operator*=(int const a)
   3.482 -	    { x *= a; y *= a; z *= a; return *this; }
   3.483 -	 inline Vector3<T>& operator*=(float const a)
   3.484 -	    { x *= a; y *= a; z *= a; return *this; }
   3.485 -	 inline Vector3<T>& operator*=(double const a)
   3.486 -	    { x *= a; y *= a; z *= a; return *this; }
   3.487 +            // Vector subtraction
   3.488 +            inline Vector3<T>& operator-=(Vector3<T> const & v2)
   3.489 +                { x -= v2.x; y -= v2.y; z -= v2.z; return *this; }
   3.490 +            inline Vector3<T> operator-(Vector3<T> const & v2) const
   3.491 +                { return Vector3<T>(*this) -= v2; }
   3.492  
   3.493 -	 inline Vector3<T> operator*(int const a) const
   3.494 -	    { return Vector3<T>(*this) *= a;}
   3.495 -	 inline Vector3<T> operator*(float const a) const
   3.496 -	    { return Vector3<T>(*this) *= a;}
   3.497 -	 inline Vector3<T> operator*(double const a) const
   3.498 -	    { return Vector3<T>(*this) *= a;}
   3.499 +            // Scalar multiplication
   3.500 +            inline Vector3<T>& operator*=(int const a)
   3.501 +                { x *= a; y *= a; z *= a; return *this; }
   3.502 +            inline Vector3<T>& operator*=(float const a)
   3.503 +                { x *= a; y *= a; z *= a; return *this; }
   3.504 +            inline Vector3<T>& operator*=(double const a)
   3.505 +                { x *= a; y *= a; z *= a; return *this; }
   3.506  
   3.507 -	 // Scalar division
   3.508 -	 inline Vector3<T>& operator/=(int const a)
   3.509 -	    { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.510 -	 inline Vector3<T>& operator/=(float const a)
   3.511 -	    { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.512 -	 inline Vector3<T>& operator/=(double const a)
   3.513 -	    { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.514 +            inline Vector3<T> operator*(int const a) const
   3.515 +                { return Vector3<T>(*this) *= a;}
   3.516 +            inline Vector3<T> operator*(float const a) const
   3.517 +                { return Vector3<T>(*this) *= a;}
   3.518 +            inline Vector3<T> operator*(double const a) const
   3.519 +                { return Vector3<T>(*this) *= a;}
   3.520  
   3.521 -	 inline Vector3<T> operator/(int const a) const
   3.522 -	    { return Vector3<T>(*this) /= a;}
   3.523 -	 inline Vector3<T> operator/(float const a) const
   3.524 -	    { return Vector3<T>(*this) /= a;}
   3.525 -	 inline Vector3<T> operator/(double const a) const
   3.526 -	    { return Vector3<T>(*this) /= a;}
   3.527 +            // Scalar division
   3.528 +            inline Vector3<T>& operator/=(int const a)
   3.529 +                { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.530 +            inline Vector3<T>& operator/=(float const a)
   3.531 +                { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.532 +            inline Vector3<T>& operator/=(double const a)
   3.533 +                { assert(a!=0); x /= a; y /= a; z /= a; return *this; }
   3.534  
   3.535 +            inline Vector3<T> operator/(int const a) const
   3.536 +                { return Vector3<T>(*this) /= a;}
   3.537 +            inline Vector3<T> operator/(float const a) const
   3.538 +                { return Vector3<T>(*this) /= a;}
   3.539 +            inline Vector3<T> operator/(double const a) const
   3.540 +                { return Vector3<T>(*this) /= a;}
   3.541  
   3.542 -	 // methods
   3.543  
   3.544 -	 inline Vector3<T>& cross(Vector3<T> const & v2, Vector3<T>& vres)
   3.545 -	    { 
   3.546 -	    vres.x =  y*v2.z - v2.y*z;
   3.547 -	    vres.y = -x*v2.z + v2.x*z;
   3.548 -	    vres.z =  x*v2.y - v2.x*y;
   3.549 -	    return vres;
   3.550 -	    }
   3.551 -	 inline Vector3<T> cross(Vector3<T> const & v2)
   3.552 -	    { 
   3.553 -	    Vector3<T> vres;
   3.554 -	    vres.x =  y*v2.z - v2.y*z;
   3.555 -	    vres.y = -x*v2.z + v2.x*z;
   3.556 -	    vres.z =  x*v2.y - v2.x*y;
   3.557 -	    return vres;
   3.558 -	    }
   3.559 +            // methods
   3.560  
   3.561 -	 inline T dot(Vector3<T> const & v2) const
   3.562 -	    { return x*v2.x + y*v2.y + z*v2.z; }
   3.563 +            inline Vector3<T>& cross(Vector3<T> const & v2, Vector3<T>& vres)
   3.564 +                { 
   3.565 +                vres.x =  y*v2.z - v2.y*z;
   3.566 +                vres.y = -x*v2.z + v2.x*z;
   3.567 +                vres.z =  x*v2.y - v2.x*y;
   3.568 +                return vres;
   3.569 +                }
   3.570 +            inline Vector3<T> cross(Vector3<T> const & v2)
   3.571 +                { 
   3.572 +                Vector3<T> vres;
   3.573 +                vres.x =  y*v2.z - v2.y*z;
   3.574 +                vres.y = -x*v2.z + v2.x*z;
   3.575 +                vres.z =  x*v2.y - v2.x*y;
   3.576 +                return vres;
   3.577 +                }
   3.578  
   3.579 -	 inline double get_angle(Vector3<T> const & v2)
   3.580 -	    { 
   3.581 -	    double tmp = dot(v2); 
   3.582 -	    return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.583 -	    }
   3.584 +            inline T dot(Vector3<T> const & v2) const
   3.585 +                { return x*v2.x + y*v2.y + z*v2.z; }
   3.586  
   3.587 -	 inline double get_anglen(Vector3<T> const & v2)
   3.588 -	    { return acos((double) dot(v2)); }
   3.589 +            inline double get_angle(Vector3<T> const & v2)
   3.590 +                { 
   3.591 +                double tmp = dot(v2); 
   3.592 +                return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.593 +                }
   3.594  
   3.595 -	 std::string & to_string(std::string & s) const;
   3.596 +            inline double get_anglen(Vector3<T> const & v2)
   3.597 +                { return acos((double) dot(v2)); }
   3.598  
   3.599 -	 inline double length(void) const
   3.600 -	    { return sqrt((dot(*this))); }
   3.601 +            std::string to_string(void) const;
   3.602  
   3.603 -	 inline Vector3<T>& normalize()
   3.604 -	    { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; return *this; }
   3.605 +            inline double length(void) const
   3.606 +                { return sqrt((dot(*this))); }
   3.607  
   3.608 -	 inline Vector3<T> proj(Vector3<T> const & v2)
   3.609 -	    { Vector3<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.610 -	 inline Vector3<T>& proj(Vector3<T> const & v2, Vector3<T>& vres)
   3.611 -	    { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.612 -	 };
   3.613 +            inline Vector3<T>& normalize()
   3.614 +                { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; return *this; }
   3.615  
   3.616 -      // Scalar multiplication, continued
   3.617 -      template <typename T> 
   3.618 -      inline Vector3<T> operator*(int const a, Vector3<T> const & v)
   3.619 -	 { return Vector3<T>(v) *= a;}
   3.620 +            inline Vector3<T> proj(Vector3<T> const & v2)
   3.621 +                { Vector3<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.622 +            inline Vector3<T>& proj(Vector3<T> const & v2, Vector3<T>& vres)
   3.623 +                { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.624 +            };
   3.625 +
   3.626 +        // Scalar multiplication, continued
   3.627 +        template <typename T> 
   3.628 +        inline Vector3<T> operator*(int const a, Vector3<T> const & v)
   3.629 +            { return Vector3<T>(v) *= a;}
   3.630        
   3.631 -      template <typename T> 
   3.632 -      inline Vector3<T> operator*(float const a, Vector3<T> const & v)
   3.633 -	 { return Vector3<T>(v) *= a;}
   3.634 +        template <typename T> 
   3.635 +        inline Vector3<T> operator*(float const a, Vector3<T> const & v)
   3.636 +            { return Vector3<T>(v) *= a;}
   3.637  
   3.638 -      template <typename T> 
   3.639 -      inline Vector3<T> operator*(double const a, Vector3<T> const & v)
   3.640 -	 { return Vector3<T>(v) *= a;}
   3.641 +        template <typename T> 
   3.642 +        inline Vector3<T> operator*(double const a, Vector3<T> const & v)
   3.643 +            { return Vector3<T>(v) *= a;}
   3.644  
   3.645 -      /////////////////////////////////////////////////////////////////////////////
   3.646 -      template <typename T> 
   3.647 -      class Vector4
   3.648 -	 {
   3.649 -	 public:
   3.650 -	 T x, y, z, w;
   3.651 +        /////////////////////////////////////////////////////////////////////////////
   3.652 +        template <typename T> 
   3.653 +        class Vector4
   3.654 +            {
   3.655 +        public:
   3.656 +            T x, y, z, w;
   3.657  
   3.658 -	 // Constructors
   3.659 -	 Vector4() {}
   3.660 -	 explicit Vector4(T a) : x (a), y(a), z(a), w(a) {}
   3.661 -	 Vector4(T a, T b, T c, T d) : x (a), y(b), z(c), w(d) {}
   3.662 +            // Constructors
   3.663 +            Vector4() {}
   3.664 +            explicit Vector4(T a) : x (a), y(a), z(a), w(a) {}
   3.665 +            Vector4(T a, T b, T c, T d) : x (a), y(b), z(c), w(d) {}
   3.666 +            Vector4(Vector2<T> v) : x (v.x), y (v.y), z (0), w (0) {}
   3.667 +            Vector4(Vector3<T> v) : x (v.x), y (v.y), z (v.z), w (0) {}
   3.668  
   3.669 -	 // Array indexing
   3.670 -	 inline T& operator[](unsigned int const i)
   3.671 -	    { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; }
   3.672 -	 inline T operator[](unsigned int const i) const
   3.673 -	    { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; }
   3.674 +            // Array indexing
   3.675 +            inline T& operator[](unsigned int const i)
   3.676 +                { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; }
   3.677 +            inline T operator[](unsigned int const i) const
   3.678 +                { assert (i<4); if (i==0) return x; if (i==1) return y; if (i==2) return z; return w; }
   3.679  
   3.680 -	 // Assignment
   3.681 -	 inline Vector4<T>& operator=(Vector4<T> const & v2)
   3.682 -	    { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; }
   3.683 -	 inline Vector4<T>& assign(T const a, T const b, T const c, T const d)
   3.684 -	    { x = a; y = b; z = c; w = d; return *this; }
   3.685 +            // Assignment
   3.686 +            inline Vector4<T>& operator=(Vector2<T> const & v2)
   3.687 +                { x = v2.x; y = v2.y; z = 0; w = 0; return *this; }
   3.688 +            inline Vector4<T>& operator=(Vector3<T> const & v2)
   3.689 +                { x = v2.x; y = v2.y; z = v2.z; w = 0; return *this; }
   3.690 +            inline Vector4<T>& operator=(Vector4<T> const & v2)
   3.691 +                { x = v2.x; y = v2.y; z = v2.z; w = v2.w; return *this; }
   3.692  
   3.693 -	 // Comparison
   3.694 -	 inline bool operator==(Vector4<T> const & v2) const
   3.695 -	    { return ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); }
   3.696 -	 inline bool operator!=(Vector4<T> const & v2) const
   3.697 -	    { return ! (*this == v2); }
   3.698 +            inline Vector4<T>& assign(T const a, T const b, T const c, T const d)
   3.699 +                { x = a; y = b; z = c; w = d; return *this; }
   3.700  
   3.701 -	 // Vector addition
   3.702 -	 inline Vector4<T>& operator+=(Vector4<T> const & v2)
   3.703 -	    { x += v2.x; y += v2.y; z += v2.z; w += v2.w; return *this; }
   3.704 -	 inline Vector4<T> operator+(Vector4<T> const & v2) const
   3.705 -	    { return Vector4<T>(*this) += v2; }
   3.706 +            // Comparison
   3.707 +            inline bool operator==(Vector4<T> const & v2) const
   3.708 +                { return ((x == v2.x) && (y == v2.y) && (z == v2.z) && (w == v2.w)); }
   3.709 +            inline bool operator!=(Vector4<T> const & v2) const
   3.710 +                { return ! (*this == v2); }
   3.711  
   3.712 -	 // Vector subtraction
   3.713 -	 inline Vector4<T>& operator-=(Vector4<T> const & v2)
   3.714 -	    { x -= v2.x; y -= v2.y; z -= v2.z; w -= v2.w; return *this; }
   3.715 -	 inline Vector4<T> operator-(Vector4<T> const & v2) const
   3.716 -	    { return Vector4<T>(*this) -= v2; }
   3.717 +            // Vector addition
   3.718 +            inline Vector4<T>& operator+=(Vector4<T> const & v2)
   3.719 +                { x += v2.x; y += v2.y; z += v2.z; w += v2.w; return *this; }
   3.720 +            inline Vector4<T> operator+(Vector4<T> const & v2) const
   3.721 +                { return Vector4<T>(*this) += v2; }
   3.722  
   3.723 -	 // Scalar multiplication
   3.724 -	 inline Vector4<T>& operator*=(int const a)
   3.725 -	    { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.726 -	 inline Vector4<T>& operator*=(float const a)
   3.727 -	    { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.728 -	 inline Vector4<T>& operator*=(double const a)
   3.729 -	    { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.730 +            // Vector subtraction
   3.731 +            inline Vector4<T>& operator-=(Vector4<T> const & v2)
   3.732 +                { x -= v2.x; y -= v2.y; z -= v2.z; w -= v2.w; return *this; }
   3.733 +            inline Vector4<T> operator-(Vector4<T> const & v2) const
   3.734 +                { return Vector4<T>(*this) -= v2; }
   3.735  
   3.736 -	 inline Vector4<T> operator*(int const a) const
   3.737 -	    { return Vector4<T>(*this) *= a;}
   3.738 -	 inline Vector4<T> operator*(float const a) const
   3.739 -	    { return Vector4<T>(*this) *= a;}
   3.740 -	 inline Vector4<T> operator*(double const a) const
   3.741 -	    { return Vector4<T>(*this) *= a;}
   3.742 +            // Scalar multiplication
   3.743 +            inline Vector4<T>& operator*=(int const a)
   3.744 +                { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.745 +            inline Vector4<T>& operator*=(float const a)
   3.746 +                { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.747 +            inline Vector4<T>& operator*=(double const a)
   3.748 +                { x *= a; y *= a; z *= a; w *= a; return *this; }
   3.749  
   3.750 -	 // Scalar division
   3.751 -	 inline Vector4<T>& operator/=(int const a)
   3.752 -	    { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.753 -	 inline Vector4<T>& operator/=(float const a)
   3.754 -	    { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.755 -	 inline Vector4<T>& operator/=(double const a)
   3.756 -	    { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.757 +            inline Vector4<T> operator*(int const a) const
   3.758 +                { return Vector4<T>(*this) *= a;}
   3.759 +            inline Vector4<T> operator*(float const a) const
   3.760 +                { return Vector4<T>(*this) *= a;}
   3.761 +            inline Vector4<T> operator*(double const a) const
   3.762 +                { return Vector4<T>(*this) *= a;}
   3.763  
   3.764 -	 inline Vector4<T> operator/(int const a) const
   3.765 -	    { return Vector4<T>(*this) /= a;}
   3.766 -	 inline Vector4<T> operator/(float const a) const
   3.767 -	    { return Vector4<T>(*this) /= a;}
   3.768 -	 inline Vector4<T> operator/(double const a) const
   3.769 -	    { return Vector4<T>(*this) /= a;}
   3.770 +            // Scalar division
   3.771 +            inline Vector4<T>& operator/=(int const a)
   3.772 +                { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.773 +            inline Vector4<T>& operator/=(float const a)
   3.774 +                { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.775 +            inline Vector4<T>& operator/=(double const a)
   3.776 +                { assert(a!=0); x /= a; y /= a; z /= a; w /= a; return *this; }
   3.777  
   3.778 +            inline Vector4<T> operator/(int const a) const
   3.779 +                { return Vector4<T>(*this) /= a;}
   3.780 +            inline Vector4<T> operator/(float const a) const
   3.781 +                { return Vector4<T>(*this) /= a;}
   3.782 +            inline Vector4<T> operator/(double const a) const
   3.783 +                { return Vector4<T>(*this) /= a;}
   3.784  
   3.785 -	 // methods
   3.786  
   3.787 -	 inline T dot(Vector4<T> const & v2) const
   3.788 -	    { return x*v2.x + y*v2.y + z*v2.z + w*v2.w; }
   3.789 +            // methods
   3.790  
   3.791 -	 inline double get_angle(Vector4<T> const & v2)
   3.792 -	    { 
   3.793 -	    double tmp = dot(v2); 
   3.794 -	    return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.795 -	    }
   3.796 +            inline T dot(Vector4<T> const & v2) const
   3.797 +                { return x*v2.x + y*v2.y + z*v2.z + w*v2.w; }
   3.798  
   3.799 -	 inline double get_anglen(Vector4<T> const & v2)
   3.800 -	    { return acos((double) dot(v2)); }
   3.801 +            inline double get_angle(Vector4<T> const & v2)
   3.802 +                { 
   3.803 +                double tmp = dot(v2); 
   3.804 +                return acos(sqrt(tmp*tmp/(dot(*this)*v2.dot(v2))));
   3.805 +                }
   3.806  
   3.807 -	 std::string & to_string(std::string & s) const;
   3.808 +            inline double get_anglen(Vector4<T> const & v2)
   3.809 +                { return acos((double) dot(v2)); }
   3.810  
   3.811 -	 inline double length(void) const
   3.812 -	    { return sqrt((dot(*this))); }
   3.813 +            std::string to_string(void) const;
   3.814  
   3.815 -	 inline Vector4<T>& normalize()
   3.816 -	    { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; w /= l; return *this; }
   3.817 +            inline double length(void) const
   3.818 +                { return sqrt((dot(*this))); }
   3.819  
   3.820 -	 inline Vector4<T> proj(Vector4<T> const & v2)
   3.821 -	    { Vector4<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.822 -	 inline Vector4<T>& proj(Vector4<T> const & v2, Vector4<T>& vres)
   3.823 -	    { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.824 -	 };
   3.825 +            inline Vector4<T>& normalize()
   3.826 +                { double l = length(); if (l == 0.0) return *this; x /= l; y /= l; z /= l; w /= l; return *this; }
   3.827  
   3.828 -      // Scalar multiplication, continued
   3.829 -      template <typename T> 
   3.830 -      inline Vector4<T> operator*(int const a, Vector4<T> const & v)
   3.831 -	 { return Vector4<T>(v) *= a;}
   3.832 +            inline Vector4<T> proj(Vector4<T> const & v2)
   3.833 +                { Vector4<T> vres; vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.834 +            inline Vector4<T>& proj(Vector4<T> const & v2, Vector4<T>& vres)
   3.835 +                { vres = v2 * dot(v2)/v2.dot(v2); return vres; }
   3.836 +            };
   3.837 +
   3.838 +        // Scalar multiplication, continued
   3.839 +        template <typename T> 
   3.840 +        inline Vector4<T> operator*(int const a, Vector4<T> const & v)
   3.841 +            { return Vector4<T>(v) *= a;}
   3.842        
   3.843 -      template <typename T> 
   3.844 -      inline Vector4<T> operator*(float const a, Vector4<T> const & v)
   3.845 -	 { return Vector4<T>(v) *= a;}
   3.846 +        template <typename T> 
   3.847 +        inline Vector4<T> operator*(float const a, Vector4<T> const & v)
   3.848 +            { return Vector4<T>(v) *= a;}
   3.849        
   3.850 -      template <typename T> 
   3.851 -      inline Vector4<T> operator*(double const a, Vector4<T> const & v)
   3.852 -	 { return Vector4<T>(v) *= a;}
   3.853 +        template <typename T> 
   3.854 +        inline Vector4<T> operator*(double const a, Vector4<T> const & v)
   3.855 +            { return Vector4<T>(v) *= a;}
   3.856  
   3.857 -      /////////////////////////////////////////////////////////////////////////////
   3.858 +        /////////////////////////////////////////////////////////////////////////////
   3.859  
   3.860 -      typedef Vector2<int> Vector2i;
   3.861 -      typedef Vector2<float> Vector2f;
   3.862 -      typedef Vector2<double> Vector2d;
   3.863 +        typedef Vector2<int> Vector2i;
   3.864 +        typedef Vector2<float> Vector2f;
   3.865 +        typedef Vector2<double> Vector2d;
   3.866  
   3.867 -      typedef Vector3<int> Vector3i;
   3.868 -      typedef Vector3<float> Vector3f;
   3.869 -      typedef Vector3<double> Vector3d;
   3.870 +        typedef Vector3<int> Vector3i;
   3.871 +        typedef Vector3<float> Vector3f;
   3.872 +        typedef Vector3<double> Vector3d;
   3.873  
   3.874 -      typedef Vector4<int> Vector4i;
   3.875 -      typedef Vector4<float> Vector4f;
   3.876 -      typedef Vector4<double> Vector4d;
   3.877 +        typedef Vector4<int> Vector4i;
   3.878 +        typedef Vector4<float> Vector4f;
   3.879 +        typedef Vector4<double> Vector4d;
   3.880  
   3.881 -      } // namespace Math
   3.882 +        } // namespace Math
   3.883  
   3.884 -   } // namespace arda
   3.885 +    } // namespace arda
   3.886  
   3.887  ////////////////////////////////////////////////////////////////////////////////
   3.888  template <typename T> 
   3.889 -std::string & arda::Math::Vector2<T>::to_string(std::string & s) const
   3.890 -   {
   3.891 -   s.clear();
   3.892 -   std::stringstream ss;
   3.893 -   ss << "[ " << x << ", " << y << " ]";
   3.894 -   s = ss.str();
   3.895 -   return s;   
   3.896 -   }
   3.897 +std::string arda::Math::Vector2<T>::to_string(void) const
   3.898 +    {
   3.899 +    std::stringstream ss;
   3.900 +    ss << "[ " << x << ", " << y << " ]";
   3.901 +    return ss.str();
   3.902 +    }
   3.903  
   3.904  ////////////////////////////////////////////////////////////////////////////////
   3.905  template <typename T> 
   3.906 -std::string & arda::Math::Vector3<T>::to_string(std::string & s) const
   3.907 -   {
   3.908 -   s.clear();
   3.909 -   std::stringstream ss;
   3.910 -   ss << "[ " << x << ", " << y << ", " << z << " ]";
   3.911 -   s = ss.str();
   3.912 -   return s;   
   3.913 -   }
   3.914 +std::string arda::Math::Vector3<T>::to_string(void) const
   3.915 +    {
   3.916 +    std::stringstream ss;
   3.917 +    ss << "[ " << x << ", " << y << ", " << z << " ]";
   3.918 +    return ss.str();
   3.919 +    }
   3.920  
   3.921  ////////////////////////////////////////////////////////////////////////////////
   3.922  template <typename T> 
   3.923 -std::string & arda::Math::Vector4<T>::to_string(std::string & s) const
   3.924 -   {
   3.925 -   s.clear();
   3.926 -   std::stringstream ss;
   3.927 -   ss << "[ " << x << ", " << y << ", " << z << ", " << w << " ]";
   3.928 -   s = ss.str();
   3.929 -   return s;   
   3.930 -   }
   3.931 +std::string arda::Math::Vector4<T>::to_string(void) const
   3.932 +    {
   3.933 +    std::stringstream ss;
   3.934 +    ss << "[ " << x << ", " << y << ", " << z << ", " << w << " ]";
   3.935 +    return ss.str();
   3.936 +    }
   3.937  
   3.938  
   3.939  #endif // VECTOR_H_