<commit_before>#ifndef GLISY_QUAT_H
#define GLISY_QUAT_H

#include <glisy/mat3.h>
#include <glisy/vec4.h>

#ifdef __cplusplus
extern "C" {
#endif

#define VAR_PTR_ACCESS(m, x) (*((float *) (&(m) + (x)))
#define VAR_PTR_SET(m, x, v) ({         \
  float *ptr = ((float *) (&(m) + (x)); \
  *ptr = v;                             \
})

/**
 * quat struct type.
 */

typedef struct quat quat;
struct quat { float x; float y; float z; float w; };

/**
 * quat initializers.
 */

#define quat(...)  { __VA_ARGS__ }
#define quat_create() quat(0, 0, 0, 1)
#define quat_identity(q) quat_set(q, 0, 0, 0, 1)

/**
 * Inherit vec4 routines.
 */

#define quat_length_squared(...) vec4_length_squared(__VA_ARGS__)
#define quat_normalize(...) vec4_normalize(__VA_ARGS__)
#define quat_length(...) vec4_length(__VA_ARGS__)
#define quat_clone(...) vec4_clone(__VA_ARGS__)
#define quat_scale(...) vec4_scale(__VA_ARGS__)
#define quat_copy(...) vec4_copy(__VA_ARGS__)
#define quat_lerp(...) vec4_lerp(__VA_ARGS__)
#define quat_set(...) vec4_set(__VA_ARGS__)
#define quat_add(...) vec4_add(__VA_ARGS__)
#define quat_dot(...) vec4_dot(__VA_ARGS__)

/**
 * Sets the specified quaternion with values corresponding to the given
 * axes with the view, right, and up vec3 vectors.
 */

#define quat_set_axes(q, view, right, up)  ({       \
  mat3 a = mat3(0);                                 \
  a.m11 = (right).x;                                \
  a.m21 = (right).y;                                \
  a.m31 = (right).z;                                \
  a.m12 = (up).x;                                   \
  a.m22 = (up).y;                                   \
  a.m32 = (up).z;                                   \
  a.m13 = -(view).x;                                \
  a.m23 = -(view).y;                                \
  a.m33 = -(view).z;                                \
  (quat_normalize((q), quat_from_mat3((a)));        \<commit_msg>fix quat_set<commit_after>#ifndef GLISY_QUAT_H
#define GLISY_QUAT_H

#include <glisy/mat3.h>
#include <glisy/vec4.h>

#ifdef __cplusplus
extern "C" {
#endif

#define VAR_PTR_ACCESS(m, x) (*((float *) (&(m) + (x)))
#define VAR_PTR_SET(m, x, v) ({         \
  float *ptr = ((float *) (&(m) + (x)); \
  *ptr = v;                             \
})

/**
 * quat struct type.
 */

typedef struct quat quat;
struct quat { float x; float y; float z; float w; };

/**
 * quat initializers.
 */

#define quat(...) ((quat) { __VA_ARGS__ })
#define quat_create() quat(0, 0, 0, 1)
#define quat_identity(q) quat_set(q, 0, 0, 0, 1)

/**
 * Inherit vec4 routines.
 */

#define quat_length_squared(...) vec4_length_squared(__VA_ARGS__)
#define quat_normalize(...) vec4_normalize(__VA_ARGS__)
#define quat_length(...) vec4_length(__VA_ARGS__)
#define quat_clone(...) vec4_clone(__VA_ARGS__)
#define quat_scale(...) vec4_scale(__VA_ARGS__)
#define quat_copy(...) vec4_copy(__VA_ARGS__)
#define quat_lerp(...) vec4_lerp(__VA_ARGS__)
#define quat_add(...) vec4_add(__VA_ARGS__)
#define quat_dot(...) vec4_dot(__VA_ARGS__)

/**
 * Setd quat components
 */

#define quat_set(q, a, b, c, d) ({ \
  (q).x = (a);                     \
  (q).y = (b);                     \
  (q).z = (c);                     \
  (q).w = (d);                     \
  (q);                             \
})

/**
 * Sets the specified quaternion with values corresponding to the given
 * axes with the view, right, and up vec3 vectors.
 */

#define quat_set_axes(q, view, right, up)  ({       \
  mat3 a = mat3(0);                                 \
  a.m11 = (right).x;                                \
  a.m21 = (right).y;                                \
  a.m31 = (right).z;                                \
  a.m12 = (up).x;                                   \
  a.m22 = (up).y;                                   \
  a.m32 = (up).z;                                   \
  a.m13 = -(view).x;                                \
  a.m23 = -(view).y;                                \
  a.m33 = -(view).z;                                \
  (quat_normalize((q), quat_from_mat3((a)));        \
{'fraction_non_alphanumeric': 0.16272189349112426, 'fraction_numerical': 0.021449704142011833, 'mean_word_length': 1.6023091725465042, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3786029', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1453, 'n_words': 307}