Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ install(
)

if(JUNO_TESTS)
add_definitions(-DUNITY_INCLUDE_DOUBLE)
set(CMAKE_BUILD_TYPE Debug)
enable_testing()
add_library(unity ${juno_SOURCE_DIR}/deps/unity/src/unity.c)
Expand Down
36 changes: 0 additions & 36 deletions include/juno/math/juno_la.h

This file was deleted.

218 changes: 215 additions & 3 deletions include/juno/math/juno_math.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,224 @@
#ifndef JUNO_MATH_H
#define JUNO_MATH_H
#ifndef JUNO_H
#define JUNO_H

#include "juno_la.h"
#include "juno_math_types.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
Add two vecf's together
*/
static inline JUNO_VEC2_F64_T Juno_Vec2_f64_Add(JUNO_VEC2_F64_T tVec0, JUNO_VEC2_F64_T tVec1)
{
tVec0.arr[0] += tVec1.arr[0];
tVec0.arr[1] += tVec1.arr[1];
return tVec0;
}


/**
Subtract to vec2f's
@param tVec0 The vec to subtract from
@param tVec1 The vec to subtract
*/
static inline JUNO_VEC2_F64_T Juno_Vec2_f64_Sub(JUNO_VEC2_F64_T tVec0, JUNO_VEC2_F64_T tVec1)
{
tVec0.arr[0] -= tVec1.arr[0];
tVec0.arr[1] -= tVec1.arr[1];
return tVec0;
}

/**
Multiply scalar with vec2f's
*/
static inline JUNO_VEC2_F64_T Juno_Vec2_f64_Mult(JUNO_VEC2_F64_T tVec0, double dScalar)
{
tVec0.arr[0] *= dScalar;
tVec0.arr[1] *= dScalar;
return tVec0;
}

/**
Dot product of two vec2f's
*/
static inline double Juno_Vec2_f64_Dot(JUNO_VEC2_F64_T tVec0, JUNO_VEC2_F64_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[0] + tVec0.arr[1] * tVec1.arr[1];
}

/**
The cross product of two vec2f's.
The result is a psedoscalar
*/
static inline double Juno_Vec2_f64_Cross(JUNO_VEC2_F64_T tVec0, JUNO_VEC2_F64_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[1] - tVec0.arr[1] * tVec1.arr[0];
}

/// Add two vec2i's
static inline JUNO_VEC2_I32_T Juno_Vec2_i32_Add(JUNO_VEC2_I32_T tVec0, JUNO_VEC2_I32_T tVec1)
{
tVec0.arr[0] += tVec1.arr[0];
tVec0.arr[1] += tVec1.arr[1];
return tVec0;
}


/**
Subtract to vec2i's
@param tVec0 The vec to subtract from
@param tVec1 The vec to subtract
*/
static inline JUNO_VEC2_I32_T Juno_Vec2_i32_Sub(JUNO_VEC2_I32_T tVec0, JUNO_VEC2_I32_T tVec1)
{
tVec0.arr[0] -= tVec1.arr[0];
tVec0.arr[1] -= tVec1.arr[1];
return tVec0;
}

/**
Multiply scalar with vec2f's
*/
static inline JUNO_VEC2_I32_T Juno_Vec2_i32_Mult(JUNO_VEC2_I32_T tVec0, int32_t dScalar)
{
tVec0.arr[0] *= dScalar;
tVec0.arr[1] *= dScalar;
return tVec0;
}

/**
Dot product of two vec2i's
*/
static inline int32_t Juno_Vec2_i32_Dot(JUNO_VEC2_I32_T tVec0, JUNO_VEC2_I32_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[0] + tVec0.arr[1] * tVec1.arr[1];
}

/**
The cross product of two vec2i's.
The result is a psedoscalar
*/
static inline int32_t Juno_Vec2_i32_Cross(JUNO_VEC2_I32_T tVec0, JUNO_VEC2_I32_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[1] - tVec0.arr[1] * tVec1.arr[0];
}

/**
Add two vecf's together
*/
static inline JUNO_VEC3_F64_T Juno_Vec3_f64_Add(JUNO_VEC3_F64_T tVec0, JUNO_VEC3_F64_T tVec1)
{
tVec0.arr[0] += tVec1.arr[0];
tVec0.arr[1] += tVec1.arr[1];
tVec0.arr[2] += tVec1.arr[2];
return tVec0;
}


/**
Subtract to vec2f's
@param tVec0 The vec to subtract from
@param tVec1 The vec to subtract
*/
static inline JUNO_VEC3_F64_T Juno_Vec3_f64_Sub(JUNO_VEC3_F64_T tVec0, JUNO_VEC3_F64_T tVec1)
{
tVec0.arr[0] -= tVec1.arr[0];
tVec0.arr[1] -= tVec1.arr[1];
tVec0.arr[2] -= tVec1.arr[2];
return tVec0;
}

/**
Multiply scalar with vec2f's
*/
static inline JUNO_VEC3_F64_T Juno_Vec3_f64_Mult(JUNO_VEC3_F64_T tVec0, double dScalar)
{
tVec0.arr[0] *= dScalar;
tVec0.arr[1] *= dScalar;
tVec0.arr[2] *= dScalar;
return tVec0;
}

/**
Dot product of two vec2f's
*/
static inline double Juno_Vec3_f64_Dot(JUNO_VEC3_F64_T tVec0, JUNO_VEC3_F64_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[0] + tVec0.arr[1] * tVec1.arr[1] + tVec0.arr[2] * tVec1.arr[2];
}

/**
The cross product of two vec2f's.
The result is a psedoscalar
*/
static inline JUNO_VEC3_F64_T Juno_Vec3_f64_Cross(JUNO_VEC3_F64_T tVec0, JUNO_VEC3_F64_T tVec1)
{
JUNO_VEC3_F64_T tRes = {
.arr[0] = tVec0.arr[1] * tVec1.arr[2] - tVec0.arr[2] * tVec1.arr[1],
.arr[1] = tVec0.arr[2] * tVec1.arr[0] - tVec0.arr[0] * tVec1.arr[2],
.arr[2] = tVec0.arr[0] * tVec1.arr[1] - tVec0.arr[1] * tVec1.arr[0]
};
return tRes;
}

/// Add two vec2i's
static inline JUNO_VEC3_I32_T Juno_Vec3_i32_Add(JUNO_VEC3_I32_T tVec0, JUNO_VEC3_I32_T tVec1)
{
tVec0.arr[0] += tVec1.arr[0];
tVec0.arr[1] += tVec1.arr[1];
tVec0.arr[2] += tVec1.arr[2];
return tVec0;
}


/**
Subtract to vec2i's
@param tVec0 The vec to subtract from
@param tVec1 The vec to subtract
*/
static inline JUNO_VEC3_I32_T Juno_Vec3_i32_Sub(JUNO_VEC3_I32_T tVec0, JUNO_VEC3_I32_T tVec1)
{
tVec0.arr[0] -= tVec1.arr[0];
tVec0.arr[1] -= tVec1.arr[1];
tVec0.arr[2] -= tVec1.arr[2];
return tVec0;
}

/**
Multiply scalar with vec2f's
*/
static inline JUNO_VEC3_I32_T Juno_Vec3_i32_Mult(JUNO_VEC3_I32_T tVec0, int32_t dScalar)
{
tVec0.arr[0] *= dScalar;
tVec0.arr[1] *= dScalar;
tVec0.arr[2] *= dScalar;
return tVec0;
}

/**
Dot product of two vec2i's
*/
static inline int32_t Juno_Vec3_i32_Dot(JUNO_VEC3_I32_T tVec0, JUNO_VEC3_I32_T tVec1)
{
return tVec0.arr[0] * tVec1.arr[0] + tVec0.arr[1] * tVec1.arr[1] + tVec0.arr[2] * tVec1.arr[2];
}

/**
The cross product of two vec2i's.
The result is a psedoscalar
*/
static inline JUNO_VEC3_I32_T Juno_Vec3_i32_Cross(JUNO_VEC3_I32_T tVec0, JUNO_VEC3_I32_T tVec1)
{
JUNO_VEC3_I32_T tRes = {
.arr[0] = tVec0.arr[1] * tVec1.arr[2] - tVec0.arr[2] * tVec1.arr[1],
.arr[1] = tVec0.arr[2] * tVec1.arr[0] - tVec0.arr[0] * tVec1.arr[2],
.arr[2] = tVec0.arr[0] * tVec1.arr[1] - tVec0.arr[1] * tVec1.arr[0]
};
return tRes;
}

#ifdef __cplusplus
}
Expand Down
18 changes: 18 additions & 0 deletions include/juno/math/juno_math_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef JUNO_CONST_H
#define JUNO_CONST_H

#include "juno/module.h"

#ifdef __cplusplus
extern "C" {
#endif

#define JUNO_PI 3.141592653589793
#define JUNO_HALF_PI 1.5707963267948966
#define JUNO_QUART_PI 0.7853981633974483
#define JUNO_E 2.718281828459045

#ifdef __cplusplus
}
#endif
#endif
Loading