Skip to content

Commit

Permalink
vec_math optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
MNasybullin committed Oct 10, 2020
1 parent 75b9c9e commit 9b4b80d
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions src/vec_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,57 @@
/* ::: :::::::: */
/* vec_math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sdiego <sdiego@student.42.fr> +#+ +:+ +#+ */
/* By: sdiego <sdiego@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:19:19 by aannara #+# #+# */
/* Updated: 2020/08/27 06:01:07 by sdiego ### ########.fr */
/* Updated: 2020/10/10 23:04:32 by sdiego ### ########.fr */
/* */
/* ************************************************************************** */

#include "../include/rt.h"

t_vec add(t_vec a1, t_vec a2)
{
t_vec b;

b.c[0] = a1.c[0] + a2.c[0];
b.c[1] = a1.c[1] + a2.c[1];
b.c[2] = a1.c[2] + a2.c[2];
b.c[3] = a1.c[3] + a2.c[3];
return (b);
a1.c[0] += a2.c[0];
a1.c[1] += a2.c[1];
a1.c[2] += a2.c[2];
a1.c[3] += a2.c[3];
return (a1);
}

t_vec sub(t_vec a1, t_vec a2)
{
t_vec b;

b.c[0] = a1.c[0] - a2.c[0];
b.c[1] = a1.c[1] - a2.c[1];
b.c[2] = a1.c[2] - a2.c[2];
b.c[3] = a1.c[3] - a2.c[3];
return (b);
a1.c[0] -= a2.c[0];
a1.c[1] -= a2.c[1];
a1.c[2] -= a2.c[2];
a1.c[3] -= a2.c[3];
return (a1);
}

t_vec neg(t_vec a)
{
a.c[0] = -a.c[0];
a.c[1] = -a.c[1];
a.c[2] = -a.c[2];
a.c[3] = -a.c[3];
a.c[0] *= -1;
a.c[1] *= -1;
a.c[2] *= -1;
a.c[3] *= -1;
return (a);
}

t_vec mult(t_vec a, double b)
{
a.c[0] = a.c[0] * b;
a.c[1] = a.c[1] * b;
a.c[2] = a.c[2] * b;
a.c[3] = a.c[3] * b;
a.c[0] *= b;
a.c[1] *= b;
a.c[2] *= b;
a.c[3] *= b;
return (a);
}

t_vec divi(t_vec a, double b)
{
a.c[0] = a.c[0] / b;
a.c[1] = a.c[1] / b;
a.c[2] = a.c[2] / b;
a.c[3] = a.c[3] / b;
a.c[0] /= b;
a.c[1] /= b;
a.c[2] /= b;
a.c[3] /= b;
return (a);
}

Expand All @@ -69,10 +65,10 @@ double magnitude(t_vec a)
t_vec normalize(t_vec v)
{
double mg = magnitude(v);
v.c[0] = v.c[0] / mg;
v.c[1] = v.c[1] / mg;
v.c[2] = v.c[2] / mg;
v.c[3] = v.c[3] / mg;
v.c[0] /= mg;
v.c[1] /= mg;
v.c[2] /= mg;
v.c[3] /= mg;
return (v);
}

Expand Down

0 comments on commit 9b4b80d

Please sign in to comment.