<commit_before>#ifndef INCLUDE_AL_QUAT_HPP
#define INCLUDE_AL_QUAT_HPP

#include "allocore/math/al_Constants.hpp"
#include "allocore/math/al_Vec.hpp"

#define QUAT_ACCURACY_MAX (1.000001)
#define QUAT_ACCURACY_MIN (0.999999)
#define QUAT_EPSILON (0.0000001)
//#define QUAT_DEG2RAD_BY2 (M_DEG2RAD/2.)

#ifndef ABS
	#define ABS(x) ((x)<0?-(x):(x))
#endif

namespace al {


template<class T> class Quat;

typedef Quat<float>		Quatf;	///< Single-precision quaternion
typedef Quat<double>	Quatd;	///< Double-precision quaternion


/// Quaternion
template<typename T=double>
class Quat {
public:
	union{
		struct{
			T w;			///< w component
			T x;			///< x component
			T y;			///< y component
			T z;			///< z component
		};
		T components[4];	///< component vector
	};
	
	///
	Quat(const T& w = T(1), const T& x = T(0), const T& y = T(0), const T& z = T(0));

	/// @param[in] src		quaternion to set values from
	Quat(const Quat& src);
	
	/// constructor of 'pure' quaternion
	Quat(const Vec3<T>& v) { w=0; x=v[0]; y=v[1]; z=v[2]; }

	/// Set component with index
	T& operator[](int i){ return components[i];}

	/// Get component with index
	const T& operator[](int i) const { return components[i]; }

	/// Returns true if all components are equal
	bool operator ==(const Quat& v) const { return (w==v.w) && (x==v.x) && (y==v.y) && (z==v.z); }

	/// Returns true if any components are not equal
	bool operator !=(const Quat& v) const {  return !(*this == v); }

	Quat operator - () const { return Quat(-w, -x, -y, -z); }
	Quat operator + (const Quat& v) const { return Quat(*this)+=v; }
	Quat operator + (const    T& v) const { return Quat(*this)+=v; }
	Quat operator - (const Quat& v) const { return Quat(*this)-=v; }
	Quat operator - (const    T& v) const { return Quat(*this)-=v; }
	Quat operator * (const Quat& v) const { return Quat(*this)*=v; }
	Quat operator * (const    T& v) const { return Quat(*this)*=v; }
	Quat operator / (const Quat& v) const { return Quat(*this)/=v; }
	Quat operator / (const    T& v) const { return Quat(*this)/=v; }


	Quat& operator  =(const Quat& v){ return set(v); }
	Quat& operator  =(const    T& v){ return set(v); }
	Quat& operator +=(const Quat& v){ w+=v.w; x+=v.x; y+=v.y; z+=v.z; return *this; }
	Quat& operator +=(const    T& v){ w+=  v; x+=  v; y+=  v; z+=  v; return *this; }
	Quat& operator -=(const Quat& v){ w-=v.w; x-=v.x; y-=v.y; z-=v.z; return *this; }
	Quat& operator -=(const    T& v){ w-=  v; x-=  v; y-=  v; z-=  v; return *this; }
	Quat& operator *=(const Quat& v){ return set(multiply(v)); }
	Quat& operator *=(const    T& v){ w*=  v; x*=  v; y*=  v; z*=  v; return *this; }
	Quat& operator /=(const Quat& v){ return (*this) *= v.recip(); }
	Quat& operator /=(const    T& v){ w/=v; x/=v; y/=v; z/=v; return *this; }


	/// Returns the conjugate
	Quat conj() const { return Quat(w, -x, -y, -z); }

	/// Returns dot product with another quaternion
	T dot(const Quat& v) const { return w*v.w + x*v.x + y*v.y + z*v.z; }

	/// Returns identity
	static Quat identity(){ return Quat(1,0,0,0); }<commit_msg>quat speedup<commit_after>#ifndef INCLUDE_AL_QUAT_HPP
#define INCLUDE_AL_QUAT_HPP

#include "allocore/math/al_Constants.hpp"
#include "allocore/math/al_Vec.hpp"

#define QUAT_ACCURACY_MAX (1.000001)
#define QUAT_ACCURACY_MIN (0.999999)
#define QUAT_EPSILON (0.0000001)
//#define QUAT_DEG2RAD_BY2 (M_DEG2RAD/2.)

#ifndef ABS
	#define ABS(x) ((x)<0?-(x):(x))
#endif

namespace al {


template<class T> class Quat;

typedef Quat<float>		Quatf;	///< Single-precision quaternion
typedef Quat<double>	Quatd;	///< Double-precision quaternion


/// Quaternion
template<typename T=double>
class Quat {
public:
	union{
		struct{
			T w;			///< w component
			T x;			///< x component
			T y;			///< y component
			T z;			///< z component
		};
		T components[4];	///< component vector
	};
	
	///
	Quat(const T& w = T(1), const T& x = T(0), const T& y = T(0), const T& z = T(0));

	/// @param[in] src		quaternion to set values from
	Quat(const Quat& src);
	
	/// constructor of 'pure' quaternion
	Quat(const Vec3<T>& v) { w=0; x=v[0]; y=v[1]; z=v[2]; }

	/// Set component with index
	T& operator[](int i){ return components[i];}

	/// Get component with index
	const T& operator[](int i) const { return components[i]; }

	/// Returns true if all components are equal
	bool operator ==(const Quat& v) const { return (w==v.w) && (x==v.x) && (y==v.y) && (z==v.z); }

	/// Returns true if any components are not equal
	bool operator !=(const Quat& v) const {  return !(*this == v); }

	Quat operator - () const { return Quat(-w, -x, -y, -z); }
	Quat operator + (const Quat& v) const { return Quat(*this)+=v; }
	Quat operator + (const    T& v) const { return Quat(*this)+=v; }
	Quat operator - (const Quat& v) const { return Quat(*this)-=v; }
	Quat operator - (const    T& v) const { return Quat(*this)-=v; }
	Quat operator / (const Quat& v) const { return Quat(*this)/=v; }
	Quat operator / (const    T& v) const { return Quat(*this)/=v; }
	Quat operator * (const Quat& v) const { return Quat(*this)*=v; }
	Vec3<3,T> operator * (const Vec3<3,T>& v) const { return rotateVectorTransposed(v); }
	Quat operator * (const    T& v) const { return Quat(*this)*=v; }


	Quat& operator  =(const Quat& v){ return set(v); }
	Quat& operator  =(const    T& v){ return set(v); }
	Quat& operator +=(const Quat& v){ w+=v.w; x+=v.x; y+=v.y; z+=v.z; return *this; }
	Quat& operator +=(const    T& v){ w+=  v; x+=  v; y+=  v; z+=  v; return *this; }
	Quat& operator -=(const Quat& v){ w-=v.w; x-=v.x; y-=v.y; z-=v.z; return *this; }
	Quat& operator -=(const    T& v){ w-=  v; x-=  v; y-=  v; z-=  v; return *this; }
	Quat& operator *=(const Quat& v){ return set(multiply(v)); }
	Quat& operator *=(const    T& v){ w*=  v; x*=  v; y*=  v; z*=  v; return *this; }
	Quat& operator /=(const Quat& v){ return (*this) *= v.recip(); }
	Quat& operator /=(const    T& v){ w/=v; x/=v; y/=v; z/=v; return *this; }


	/// Returns the conjugate
	Quat conj() const { return Quat(w, -x, -y, -z); }

	/// Returns dot product with another quaternion
	T dot(const Quat& v) const { return w*v.w + x*v.x + y*v.y + z*v.z; }

	/// Returns identity
	static Quat identity(){ return Quat(1,0,0,0); }
{'fraction_non_alphanumeric': 0.19789983844911146, 'fraction_numerical': 0.013893376413570274, 'mean_word_length': 3.2873961218836567, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4802833', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2518, 'n_words': 759}