<commit_before>// $Id: quaternion.h,v 1.10 2000/03/07 10:20:31 oliver Exp $

#ifndef BALL_MATHS_QUATERNION_H
#define BALL_MATHS_QUATERNION_H

#ifndef BALL_COMMON_H
#	include <BALL/common.h>
#endif

#include <iostream>

#ifndef BALL_MATHS_MATRIX44_H
#	include <BALL/MATHS/matrix44.h>
#endif

#ifndef BALL_MATHS_VECTOR3_H
#	include <BALL/MATHS/vector3.h>
#endif

namespace BALL 
{

	/**	@name Quaternion
			@memo representing a rotation in three dimensional space: class \Ref{TQuaternion} and class \Ref{Quaternion}
	*/
	//@{
			

	/**	Generic Quaternion Class.
      {\bf Definition:} \URL{BALL/MATHS/.h}
      \\
	*/
	template <class T>
	class TQuaternion
	{
		public:

		BALL_CREATE(TQuaternion<T>)
		

		/**	@name	Constructors and Destructors
		*/
		//@{

		/**	Default constructor.
				This method creates a new TQuaternion object. The axis-components
				are initialized to {\tt 0}, the angle is set to  {\tt 1}.
		*/
		TQuaternion();

		/**	Copy constructor.
				Create a new TQuaternion object from another.
				@param TQuaternion the TQuaternion object to be copied
				@param bool ignored - just for interface consistency
		*/	
		TQuaternion(const TQuaternion& q, bool deep = true);

		/**	Detailled constructor.
				Create a new TQuaternion object from a TVector3 and an angle.
				@param axis assigned to the axis
				@param angle assigned to the angle
		*/
		TQuaternion(const TVector3<T>& axis, const T &angle);

		/**	Detailled constructor.
				Create a new TQuaternion object from three {\tt T} values and an angle.
				@param x assigned to the x-component of the axis
				@param y assigned to the y-component of the axis
				@param z assigned to the z-component of the axis
				@param angle assigned to the angle
		*/
		TQuaternion(const T& x, const T& y, const T& z, const T& angle);

		/**	Destructor.	
				Destructs the TQuaternion object. As there are no dynamic
				data structures, nothing happens.
		*/
		virtual ~TQuaternion();
		//@}

		/**	@name	Assignment
		*/
		//@{
		///
		void set(const TQuaternion& q, bool deep = true);

		/**	Assign the TQuaternion components.
				@param axis the new axis component
				@param angle the new angle component
		*/
		void set(const TVector3<T>& axis, const T& angle);

		/**	Assign the TQuaternion components.
				@param x assigned to the x-component of the axis
				@param y assigned to the y-component of the axis
				@param z assigned to the z-component of the axis
				@param angle assigned to the angle
		*/
		void set(const T& x, const T& y, const T& z, const T& angle);

		/**	Assign from another TQuaternion.
				@param q the TQuaternion object to assign from
				@param deep ignored
		*/
		TQuaternion& operator = (const TQuaternion& q);

		/**	Assign to another TQuaternion.
				Assigns the components to another TQuaternion.
				@param q the TQuaternion to be asigned to
				@param deep ignored
		*/
		void get(TQuaternion& q, bool deep = true);

		/**	Assign the components to the standard values.
				The axis-compnents are set to {\tt 0}, the angle is set to {\tt 1}.
		*/
		void setIdentity();

		/**	Swap the contents of two TQuaternion.
				@param q the TQuaternion to swap contents with
		*/
		void swap(TQuaternion& q);
		//@}


		/**	@name	Accessors
		*/
		//@{
		/**	Get the positive angle rotation.
				@return T the angle value
		*/
		T getAngle() const;

		/**	Get the normalized direction vector of axis of rotation.
				@return TVector3 the Axis
		*/
		TVector3<T> getAxis();

		/**	Get the rotation matrix.
				@return TMatrix4x4 the matrix
		*/
		TMatrix4x4<T>& getRotationMatrix(TMatrix4x4<T>& m) const;

		/**	Negative sign.
		*/
		TQuaternion operator - () const;

		/**	Get the inverse TQuaternion.
				@return TQuaternion the inverse TQuaternion
		*/
		TQuaternion getInverse() const;

		/**	Return the conjugate TQuaternion.
				(The axis components are negated.)
				@return TQuaternion&, the conjugate TQuaternion
		*/
		TQuaternion getConjugate() const;

		/**	Add a TQuaternion to this TQuaternion.
				@param q the TQuaternion to add
				@return TQuaternion&, {\tt *this}
		*/
		TQuaternion& operator += (const TQuaternion& q);

		/**	Substract a TQuaternion from this TQuaternion.
				@param q the TQuaternion to substract
				@return TQuaternion&, {\tt *this}
		*/
		TQuaternion& operator -= (const TQuaternion& q);

		//@}


		/**	@name	Predicates
		*/
		//@{
		/**	Equality operator.
				@return bool, {\bf true} if all components are equal, {\bf false} otherwise
		*/
		bool operator == (const TQuaternion& q) const;

		/**	Inequality operator.
				@return bool, {\bf true} if the two TQuaternion differ in at least on component, {\bf false} otherwise
		*/
		bool operator != (const TQuaternion& q) const;
		//@}


		/**	@name	Debugging and Diagnostics
		*/
		//@{
		///
		void dump(std::ostream& s = std::cout, Size depth = 0) const;
		//@}


		/**	@name	Attributes
		*/
		//@{
		/**	x component of the axis.
		*/
		T i;

		/**	y component of the axis.
		*/
		T j;

		/**	z component of the axis.
		*/
		T k;

		/**	angle component.
		*/
		T angle;
		//@}

	};

	template <class T>
	TQuaternion<T>::TQuaternion()
		:	i((T)0), 
			j((T)0), 
			k((T)0),
			angle((T)1)
	{
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const TQuaternion& q, bool /* deep */)
		:	i(q.i),
			j(q.j),
			k(q.k),
			angle(q.angle)
	{
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const TVector3<T>& axis, const T& angle)
	{
		set(axis.x, axis.y, axis.z, angle);
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const T& x, const T& y, const T& z, const T& angle)
	{
		set(x, y, z, angle);
	}

	template <class T>
	TQuaternion<T>::~TQuaternion()
	{
	}

	template <class T>
	void TQuaternion<T>::set(const TQuaternion<T>& q, bool /* deep */)
	{
		if (this != &q)
		{
			i = q.i;
			j = q.j;
			k = q.k;
			angle = q.angle;
		}
	}

	template <class T>
	BALL_INLINE 
	void TQuaternion<T>::set(const TVector3<T>& axis, const T& angle)
	{
		set(axis.x, axis.y, axis.z, angle);
	}

	template <class T>
	void TQuaternion<T>::set(const T& x, const T& y, const T& z, const T& phi)
	{
		T length = (T)sqrt(x * x + y * y + z * z);

		if (Maths::isEqual(length, (T)0))
		{
			i = j = k = (T)0;
			angle = (T)1;
		} else {<commit_msg>fixed: removed warnings due to a member hidden by a parameter of the same name<commit_after>// $Id: quaternion.h,v 1.11 2000/03/07 10:45:38 oliver Exp $

#ifndef BALL_MATHS_QUATERNION_H
#define BALL_MATHS_QUATERNION_H

#ifndef BALL_COMMON_H
#	include <BALL/common.h>
#endif

#include <iostream>

#ifndef BALL_MATHS_MATRIX44_H
#	include <BALL/MATHS/matrix44.h>
#endif

#ifndef BALL_MATHS_VECTOR3_H
#	include <BALL/MATHS/vector3.h>
#endif

namespace BALL 
{

	/**	@name Quaternion
			@memo representing a rotation in three dimensional space: class \Ref{TQuaternion} and class \Ref{Quaternion}
	*/
	//@{
			

	/**	Generic Quaternion Class.
      {\bf Definition:} \URL{BALL/MATHS/.h}
      \\
	*/
	template <class T>
	class TQuaternion
	{
		public:

		BALL_CREATE(TQuaternion<T>)
		

		/**	@name	Constructors and Destructors
		*/
		//@{

		/**	Default constructor.
				This method creates a new TQuaternion object. The axis-components
				are initialized to {\tt 0}, the angle is set to  {\tt 1}.
		*/
		TQuaternion();

		/**	Copy constructor.
				Create a new TQuaternion object from another.
				@param TQuaternion the TQuaternion object to be copied
				@param bool ignored - just for interface consistency
		*/	
		TQuaternion(const TQuaternion& q, bool deep = true);

		/**	Detailled constructor.
				Create a new TQuaternion object from a TVector3 and an angle.
				@param axis assigned to the axis
				@param angle assigned to the angle
		*/
		TQuaternion(const TVector3<T>& axis, const T &angle);

		/**	Detailled constructor.
				Create a new TQuaternion object from three {\tt T} values and an angle.
				@param x assigned to the x-component of the axis
				@param y assigned to the y-component of the axis
				@param z assigned to the z-component of the axis
				@param angle assigned to the angle
		*/
		TQuaternion(const T& x, const T& y, const T& z, const T& angle);

		/**	Destructor.	
				Destructs the TQuaternion object. As there are no dynamic
				data structures, nothing happens.
		*/
		virtual ~TQuaternion();
		//@}

		/**	@name	Assignment
		*/
		//@{
		///
		void set(const TQuaternion& q, bool deep = true);

		/**	Assign the TQuaternion components.
				@param axis the new axis component
				@param angle the new angle component
		*/
		void set(const TVector3<T>& axis, const T& angle);

		/**	Assign the TQuaternion components.
				@param x assigned to the x-component of the axis
				@param y assigned to the y-component of the axis
				@param z assigned to the z-component of the axis
				@param angle assigned to the angle
		*/
		void set(const T& x, const T& y, const T& z, const T& angle);

		/**	Assign from another TQuaternion.
				@param q the TQuaternion object to assign from
				@param deep ignored
		*/
		TQuaternion& operator = (const TQuaternion& q);

		/**	Assign to another TQuaternion.
				Assigns the components to another TQuaternion.
				@param q the TQuaternion to be asigned to
				@param deep ignored
		*/
		void get(TQuaternion& q, bool deep = true);

		/**	Assign the components to the standard values.
				The axis-compnents are set to {\tt 0}, the angle is set to {\tt 1}.
		*/
		void setIdentity();

		/**	Swap the contents of two TQuaternion.
				@param q the TQuaternion to swap contents with
		*/
		void swap(TQuaternion& q);
		//@}


		/**	@name	Accessors
		*/
		//@{
		/**	Get the positive angle rotation.
				@return T the angle value
		*/
		T getAngle() const;

		/**	Get the normalized direction vector of axis of rotation.
				@return TVector3 the Axis
		*/
		TVector3<T> getAxis();

		/**	Get the rotation matrix.
				@return TMatrix4x4 the matrix
		*/
		TMatrix4x4<T>& getRotationMatrix(TMatrix4x4<T>& m) const;

		/**	Negative sign.
		*/
		TQuaternion operator - () const;

		/**	Get the inverse TQuaternion.
				@return TQuaternion the inverse TQuaternion
		*/
		TQuaternion getInverse() const;

		/**	Return the conjugate TQuaternion.
				(The axis components are negated.)
				@return TQuaternion&, the conjugate TQuaternion
		*/
		TQuaternion getConjugate() const;

		/**	Add a TQuaternion to this TQuaternion.
				@param q the TQuaternion to add
				@return TQuaternion&, {\tt *this}
		*/
		TQuaternion& operator += (const TQuaternion& q);

		/**	Substract a TQuaternion from this TQuaternion.
				@param q the TQuaternion to substract
				@return TQuaternion&, {\tt *this}
		*/
		TQuaternion& operator -= (const TQuaternion& q);

		//@}


		/**	@name	Predicates
		*/
		//@{
		/**	Equality operator.
				@return bool, {\bf true} if all components are equal, {\bf false} otherwise
		*/
		bool operator == (const TQuaternion& q) const;

		/**	Inequality operator.
				@return bool, {\bf true} if the two TQuaternion differ in at least on component, {\bf false} otherwise
		*/
		bool operator != (const TQuaternion& q) const;
		//@}


		/**	@name	Debugging and Diagnostics
		*/
		//@{
		///
		void dump(std::ostream& s = std::cout, Size depth = 0) const;
		//@}


		/**	@name	Attributes
		*/
		//@{
		/**	x component of the axis.
		*/
		T i;

		/**	y component of the axis.
		*/
		T j;

		/**	z component of the axis.
		*/
		T k;

		/**	angle component.
		*/
		T angle;
		//@}

	};

	template <class T>
	TQuaternion<T>::TQuaternion()
		:	i((T)0), 
			j((T)0), 
			k((T)0),
			angle((T)1)
	{
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const TQuaternion& q, bool /* deep */)
		:	i(q.i),
			j(q.j),
			k(q.k),
			angle(q.angle)
	{
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const TVector3<T>& axis, const T& angle)
	{
		set(axis.x, axis.y, axis.z, angle);
	}

	template <class T>
	TQuaternion<T>::TQuaternion(const T& x, const T& y, const T& z, const T& new_angle)
	{
		set(x, y, z, new_angle);
	}

	template <class T>
	TQuaternion<T>::~TQuaternion()
	{
	}

	template <class T>
	void TQuaternion<T>::set(const TQuaternion<T>& q, bool /* deep */)
	{
		if (this != &q)
		{
			i = q.i;
			j = q.j;
			k = q.k;
			angle = q.angle;
		}
	}

	template <class T>
	BALL_INLINE 
	void TQuaternion<T>::set(const TVector3<T>& axis, const T& new_angle)
	{
		set(axis.x, axis.y, axis.z, new_angle);
	}

	template <class T>
	void TQuaternion<T>::set(const T& x, const T& y, const T& z, const T& phi)
	{
		T length = (T)sqrt(x * x + y * y + z * z);

		if (Maths::isEqual(length, (T)0))
		{
			i = j = k = (T)0;
			angle = (T)1;
		} else {
{'fraction_non_alphanumeric': 0.12796359862696574, 'fraction_numerical': 0.007663446954578111, 'mean_word_length': 2.865473619253317, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1662128', 'n_tokens_mistral': 5242, 'n_tokens_neox': 4557, 'n_words': 1458}