<commit_before>--- @classmod core.Quaternion
--- @alias Quat
---
--
-- A set of imaginary numbers which describe a rotation in 3d space.
-- More information on them can be found e.g. on [wikipedia](http://en.wikipedia.org/wiki/Quaternion).
--
-- To cut it short, in contrast to euler rotation quaternions have ...
--
-- - ... less computational overhead.
-- - ... no [Gimbal Lock](http://en.wikipedia.org/wiki/Gimbal_lock).
-- - ... [better interpolation](https://www.youtube.com/watch?v=QxIdIZ0eKCE).


local assert = assert
local class  = require 'middleclass'
local Object = class.Object
local Vec    = require 'core/Vector'
local Mat4   = require 'core/Matrix4'
local CreateQuaternion                = ENGINE.CreateQuaternion
local CreateQuaternionFromEulerAngles = ENGINE.CreateQuaternionFromEulerAngles
local CreateQuaternionFromMatrix      = ENGINE.CreateQuaternionFromMatrix
local CopyQuaternion                  = ENGINE.CopyQuaternion
local NormalizeQuaternion             = ENGINE.NormalizeQuaternion
local InvertQuaternion                = ENGINE.InvertQuaternion
local QuaternionOp                    = ENGINE.QuaternionOp
local LerpQuaternion                  = ENGINE.LerpQuaternion
local QuaternionXVector3              = ENGINE.QuaternionXVector3
local Vector3XQuaternion              = ENGINE.Vector3XQuaternion
local CreateMatrix4FromQuaternion     = ENGINE.CreateMatrix4FromQuaternion


local Quat = class('core/Quaternion')

--- Create a new quaternion.
--
-- @usage
-- Quat() -- New identity quaternion.
-- Quat( quat ) -- Copy quaternion.
-- Quat( vec ) or Quat( x, y, z ) -- Create quaternion from euler angles.
-- Quat( mat ) -- Create quaternion from matrix.
function Quat:initialize( arg )
    arg = arg or CreateQuaternion()

    if type(arg) == 'userdata' then
        self.handle = arg
    elseif Object.isInstanceOf(arg, Quat) then
        self.handle = CopyQuaternion(arg.handle)
    elseif Vec:isInstance(arg) then
        self.handle = CreateQuaternionFromEulerAngles(arg:unpack(3))
    elseif Object.isInstanceOf(arg, Mat4) then
        self.handle = CreateQuaternionFromMatrix(arg.handle)
    else
        error('Invalid constructor use.')
    end
end

--- Create an independent copy of the instance.
function Quat:clone()<commit_msg>Quaternion can be created using Euler angles directly.<commit_after>--- @classmod core.Quaternion
--- @alias Quat
---
--
-- A set of imaginary numbers which describe a rotation in 3d space.
-- More information on them can be found e.g. on [wikipedia](http://en.wikipedia.org/wiki/Quaternion).
--
-- To cut it short, in contrast to euler rotation quaternions have ...
--
-- - ... less computational overhead.
-- - ... no [Gimbal Lock](http://en.wikipedia.org/wiki/Gimbal_lock).
-- - ... [better interpolation](https://www.youtube.com/watch?v=QxIdIZ0eKCE).


local assert = assert
local class  = require 'middleclass'
local Object = class.Object
local Vec    = require 'core/Vector'
local Mat4   = require 'core/Matrix4'
local CreateQuaternion                = ENGINE.CreateQuaternion
local CreateQuaternionFromEulerAngles = ENGINE.CreateQuaternionFromEulerAngles
local CreateQuaternionFromMatrix      = ENGINE.CreateQuaternionFromMatrix
local CopyQuaternion                  = ENGINE.CopyQuaternion
local NormalizeQuaternion             = ENGINE.NormalizeQuaternion
local InvertQuaternion                = ENGINE.InvertQuaternion
local QuaternionOp                    = ENGINE.QuaternionOp
local LerpQuaternion                  = ENGINE.LerpQuaternion
local QuaternionXVector3              = ENGINE.QuaternionXVector3
local Vector3XQuaternion              = ENGINE.Vector3XQuaternion
local CreateMatrix4FromQuaternion     = ENGINE.CreateMatrix4FromQuaternion


local Quat = class('core/Quaternion')

--- Create a new quaternion.
--
-- @usage
-- Quat() -- New identity quaternion.
-- Quat( quat ) -- Copy quaternion.
-- Quat( vec ) or Quat( x, y, z ) -- Create quaternion from euler angles.
-- Quat( mat ) -- Create quaternion from matrix.
function Quat:initialize( arg, y, z )
    arg = arg or CreateQuaternion()

    if type(arg) == 'userdata' then
        self.handle = arg
    elseif Object.isInstanceOf(arg, Quat) then
        self.handle = CopyQuaternion(arg.handle)
    elseif Vec:isInstance(arg) then
        self.handle = CreateQuaternionFromEulerAngles(arg:unpack(3))
    elseif type(arg) == 'number' then
        self.handle = CreateQuaternionFromEulerAngles(arg, y, z)
    elseif Object.isInstanceOf(arg, Mat4) then
        self.handle = CreateQuaternionFromMatrix(arg.handle)
    else
        error('Invalid constructor use.')
    end
end

--- Create an independent copy of the instance.
function Quat:clone()
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.00511727078891258, 'mean_word_length': 3.016267123287671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6569435', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1390, 'n_words': 368}