<commit_before>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   quaternion.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: angagnie <<EMAIL>>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2016/02/22 13:04:21 by angagnie          #+#    #+#             */
/*   Updated: 2016/05/17 16:46:21 by angagnie         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "geometry.h"
#include "ggl.h"

/*
** Quaternion :: Constructors
*/

t_qtrn	qtrn_new(const t_real a, const t_real b, const t_real c, const t_real d)
{
	return (NEW_QTRN(a, b, c, d));
}

t_qtrn	*qtrn_alloc(const t_real a, const t_real b,
	const t_real c, const t_real d)
{
	t_qtrn	*ans;

	if (!(ans = (t_qtrn *)malloc(sizeof(t_qtrn))))
		return (NULL);
	*ans = NEW_QTRN(a, b, c, d);
	return (ans);
}

/*
** Quaternion :: Get the external product : multiply by a scalar
*/

t_qtrn	qtrn_external_prod(const t_qtrn *const a, const t_real s)
{
	t_qtrn	ans;

	ans.type = a->type;
	if (a->type == CARTHESIAN)
	{
		QX(ans) = QXP(a) * s;
		QY(ans) = QYP(a) * s;
		QZ(ans) = QZP(a) * s;
		QW(ans) = QWP(a) * s;
	}
	else if (a->type == CYLINDRICAL)
	{
		QR(ans) = QRP(a) * s;
		QTHETA(ans) = QTHETA(a);
		QZ(ans) = QZP(a) * s;
	}
}

/*
** Quaternion :: External product : multiply by a scalar
** Side effect on the quaternion
*/

void	qtrn_external_mult(t_qtrn *const a, const t_real s)
{
	XP(a) *= s;
	YP(a) *= s;
	ZP(a) *= s;
	WP(a) *= s;
}


/*
** Quaternion :: Get the sum
*/

t_qtrn	qtrn_sum(const t_qtrn *a, const t_qtrn *b)
{
	return (NEW_QTRN(
		XP(a) + XP(b),
		YP(a) + YP(b),
		ZP(a) + ZP(b),
		WP(a) + WP(b)
	));
}

/*
** Quaternion :: Add
** Side effect on the first quaternion
*/

void	qtrn_add(t_qtrn *const a, const t_qtrn *const b)
{
	int i;

	i = 4;
	while (i-- > 0)
		a->v.m[i] += b->v.m[i];
}

/*
** Quaternion :: Get the product
*/

t_qtrn	qtrn_prod(const t_qtrn *const q, const t_qtrn *const h)
{
	return (NEW_QTRN(
		WP(q) * XP(h) + XP(q) * WP(h) + YP(q) * ZP(h) - ZP(q) * YP(h),
		WP(q) * YP(h) + YP(q) * WP(h) - XP(q) * ZP(h) + ZP(q) * XP(h),
		WP(q) * ZP(h) + ZP(q) * WP(h) + XP(q) * YP(h) - YP(q) * XP(h),
		WP(q) * WP(h) - XP(q) * XP(h) - YP(q) * YP(h) - ZP(q) * ZP(h)
		));
}<commit_msg>G2Sport<commit_after>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   quaternion.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: angagnie <<EMAIL>>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2016/02/22 13:04:21 by angagnie          #+#    #+#             */
/*   Updated: 2016/05/17 17:50:50 by angagnie         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "geometry.h"
#include "ggl.h"

/*
** Quaternion :: Constructors
*/

t_qtrn	qtrn_new(const t_real a, const t_real b, const t_real c, const t_real d)
{
	return (NEW_QTRN(a, b, c, d));
}

t_qtrn	*qtrn_alloc(const t_real a, const t_real b,
	const t_real c, const t_real d)
{
	t_qtrn	*ans;

	if (!(ans = (t_qtrn *)malloc(sizeof(t_qtrn))))
		return (NULL);
	*ans = NEW_QTRN(a, b, c, d);
	return (ans);
}

/*
** Quaternion :: Get the external product : multiplied by a scalar
*/

t_qtrn	qtrn_external_prod(const t_qtrn *const a, const t_real s)
{
	t_qtrn	ans;

	ans.type = a->type;
	if (a->type == CARTHESIAN)
	{
		X(ans) = XP(a) * s;
		Y(ans) = YP(a) * s;
		Z(ans) = ZP(a) * s;
		W(ans) = WP(a) * s;
	}
	else if (a->type == CYLINDRICAL)
	{
		QR(ans) = QRP(a) * s;
		QTHETA(ans) = QTHETA(a);
		Z(ans) = ZP(a) * s;
		W(ans) = WP(a) * s;
	}
	else
	{
		QRHO(ans) = QRHOP(a) * s;
		QTHETA(ans) = QTHETAP(a);
		QPHI(ans) = QPHIP(a);
		W(ans) = WP(a) * s;
	}
	return (ans);
}

/*
** Quaternion :: External product : multiply by a scalar
** Side effect on the quaternion
*/

void	qtrn_external_mult(t_qtrn *const a, const t_real s)
{
	if (a->type == CARTHESIAN)
	{
		XP(a) *= s;
		YP(a) *= s;
		ZP(a) *= s;
		WP(a) *= s;
	}
	else if (a->type == CYLINDRICAL)
	{
		QRP(a) *= s;
		ZP(a) *= s;
		QWP(a) *= s;
	}
	else
	{
		QRHOP(a) *= s;
		WP(a) *= s;
	}
}


/*
** Quaternion :: Get the sum
*/

t_qtrn	qtrn_sum(const t_qtrn *a, const t_qtrn *b)
{
	t_qtrn ans;
	t_qtrn tmp;

	ans = *a;
	tmp = *b;
	if (ans.type == CYLINDRICAL)
		cylin2carth(&ans);
	else if (ans.type == SPERICAL)
		spher2carth(&ans);
	if (tmp.type == CYLINDRICAL)
		cylin2carth(&tmp);
	else if (tmp.type == SPERICAL)
		spher2carth(&tmp);
	X(ans) += X(tmp);
	Y(ans) += Y(tmp);
	Z(ans) += Z(tmp);
	W(ans) += W(tmp);
	return (ans);
}

/*
** Quaternion :: Add
** Side effect on the first quaternion
*/

void	qtrn_add(t_qtrn *const a, const t_qtrn *const b)
{
	int		i;
	t_type	;

	if (a->type == CYLINDRICAL)
		cylin2carth(a);
	else if (a->type == SPERICAL)
		spher2carth(a);
	if (b->type == CYLINDRICAL)
		cylin2carth(b);
	else if (a->type == SPERICAL)
		spher2carth(b);
	i = 4;
	while (i-- > 0)
		a->v.m[i] += b->v.m[i];
}

/*
** Quaternion :: Get the product
*/

t_qtrn	qtrn_prod(const t_qtrn *const q, const t_qtrn *const h)
{
	return (NEW_QTRN(
		WP(q) * XP(h) + XP(q) * WP(h) + YP(q) * ZP(h) - ZP(q) * YP(h),
		WP(q) * YP(h) + YP(q) * WP(h) - XP(q) * ZP(h) + ZP(q) * XP(h),
		WP(q) * ZP(h) + ZP(q) * WP(h) + XP(q) * YP(h) - YP(q) * XP(h),
		WP(q) * WP(h) - XP(q) * XP(h) - YP(q) * YP(h) - ZP(q) * ZP(h)
		));
}
{'fraction_non_alphanumeric': 0.24294975688816856, 'fraction_numerical': 0.011183144246353322, 'mean_word_length': 1.908105560791706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4910843', 'n_tokens_mistral': 2863, 'n_tokens_neox': 2679, 'n_words': 551}