Большое переименование
This commit is contained in:
parent
e354b2425c
commit
e7616ae80c
30 changed files with 1356 additions and 1348 deletions
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<ActiveTarget name="Release" />
|
||||
<File name="main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3793" topLine="116" />
|
||||
|
|
42
dev/main.c
42
dev/main.c
|
@ -9,36 +9,36 @@
|
|||
#include <time.h>
|
||||
#endif // _WINDOWS_
|
||||
|
||||
SPVersor * allocate_versors(const unsigned int amount)
|
||||
BgFP32Versor * allocate_versors(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(SPVersor));
|
||||
return calloc(amount, sizeof(BgFP32Versor));
|
||||
}
|
||||
|
||||
SPVersor * make_zero_versors(const unsigned int amount)
|
||||
BgFP32Versor * make_zero_versors(const unsigned int amount)
|
||||
{
|
||||
SPVersor * list = allocate_versors(amount);
|
||||
BgFP32Versor * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
sp_versor_reset(&list[i]);
|
||||
bg_fp32_versor_reset(&list[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
SPVersor * make_random_versors(const unsigned int amount)
|
||||
BgFP32Versor * make_random_versors(const unsigned int amount)
|
||||
{
|
||||
SPVersor * list = allocate_versors(amount);
|
||||
BgFP32Versor * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
sp_versor_set(
|
||||
bg_fp32_versor_set_values(
|
||||
(2.0f * rand()) / RAND_MAX - 1.0f,
|
||||
(2.0f * rand()) / RAND_MAX - 1.0f,
|
||||
(2.0f * rand()) / RAND_MAX - 1.0f,
|
||||
|
@ -50,14 +50,14 @@ SPVersor * make_random_versors(const unsigned int amount)
|
|||
return list;
|
||||
}
|
||||
|
||||
void print_versor(const SPVersor* versor)
|
||||
void print_versor(const BgFP32Versor* versor)
|
||||
{
|
||||
printf("(%f, %f, %f, %f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
|
||||
}
|
||||
|
||||
void print_vector(const SPVector3* vector)
|
||||
void print_vector(const BgFP32Vector3* vector)
|
||||
{
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, sp_vector3_get_module(vector));
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_module(vector));
|
||||
}
|
||||
/*
|
||||
int main()
|
||||
|
@ -74,17 +74,17 @@ int main()
|
|||
srand((unsigned int)(now.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
SPVersor * versors = make_random_versors(amount);
|
||||
BgFP32Versor * versors = make_random_versors(amount);
|
||||
|
||||
if (versors == 0) {
|
||||
printf("Cannot allocate memory for versors");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPVector3 initial, result;
|
||||
BgFP32Vector3 initial, result;
|
||||
|
||||
sp_vector3_set_values(1, 2, 3, &initial);
|
||||
sp_vector3_copy(&initial, &result);
|
||||
bg_fp32_vector3_set_values(1, 2, 3, &initial);
|
||||
bg_fp32_vector3_copy(&initial, &result);
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG start, end;
|
||||
|
@ -94,11 +94,11 @@ int main()
|
|||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
sp_versor_turn2(&versors[i], &result, &result);
|
||||
bg_fp32_versor_turn2(&versors[i], &result, &result);
|
||||
}
|
||||
|
||||
for (unsigned int i = amount; i > 0; i--) {
|
||||
sp_versor_turn_back2(&versors[i - 1], &result, &result);
|
||||
bg_fp32_versor_turn_back2(&versors[i - 1], &result, &result);
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
|
@ -135,14 +135,14 @@ int main()
|
|||
srand((unsigned int)(now.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
SPVersor * versors1 = make_random_versors(amount);
|
||||
BgFP32Versor * versors1 = make_random_versors(amount);
|
||||
|
||||
if (versors1 == 0) {
|
||||
printf("Cannot allocate memory for versors1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPVersor * versors2 = make_random_versors(amount);
|
||||
BgFP32Versor * versors2 = make_random_versors(amount);
|
||||
|
||||
if (versors2 == 0) {
|
||||
printf("Cannot allocate memory for versors2");
|
||||
|
@ -150,7 +150,7 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
SPVersor * results = make_zero_versors(amount);
|
||||
BgFP32Versor * results = make_zero_versors(amount);
|
||||
|
||||
if (results == 0) {
|
||||
printf("Cannot allocate memory for results");
|
||||
|
@ -168,7 +168,7 @@ int main()
|
|||
#endif // _WIN64
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
sp_versor_combine(&versors1[i], &versors2[i], &results[i]);
|
||||
bg_fp32_versor_combine(&versors1[i], &versors2[i], &results[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
720
src/angle.h
720
src/angle.h
|
@ -4,34 +4,34 @@
|
|||
#include <math.h>
|
||||
#include "basis.h"
|
||||
|
||||
#define SP_PI 3.1415926536f
|
||||
#define SP_TWO_PI 6.2831853072f
|
||||
#define SP_HALF_OF_PI 1.5707963268f
|
||||
#define SP_THIRD_OF_PI 1.0471975512f
|
||||
#define SP_FOURTH_OF_PI 0.7853981634f
|
||||
#define SP_SIXTH_OF_PI 0.5235987756f
|
||||
#define BG_FP32_PI 3.1415926536f
|
||||
#define BG_FP32_TWO_PI 6.2831853072f
|
||||
#define BG_FP32_HALF_OF_PI 1.5707963268f
|
||||
#define BG_FP32_THIRD_OF_PI 1.0471975512f
|
||||
#define BG_FP32_FOURTH_OF_PI 0.7853981634f
|
||||
#define BG_FP32_SIXTH_OF_PI 0.5235987756f
|
||||
|
||||
#define SP_DEGREES_IN_RADIAN 57.295779513f
|
||||
#define SP_TURNS_IN_RADIAN 0.1591549431f
|
||||
#define SP_RADIANS_IN_DEGREE 1.745329252E-2f
|
||||
#define SP_TURNS_IN_DEGREE 2.7777777778E-3f
|
||||
#define BG_FP32_DEGREES_IN_RADIAN 57.295779513f
|
||||
#define BG_FP32_TURNS_IN_RADIAN 0.1591549431f
|
||||
#define BG_FP32_RADIANS_IN_DEGREE 1.745329252E-2f
|
||||
#define BG_FP32_TURNS_IN_DEGREE 2.7777777778E-3f
|
||||
|
||||
#define DP_PI 3.14159265358979324
|
||||
#define DP_TWO_PI 6.28318530717958648
|
||||
#define DP_HALF_OF_PI 1.57079632679489662
|
||||
#define DP_THIRD_OF_PI 1.04719755119659775
|
||||
#define DP_FOURTH_OF_PI 0.78539816339744831
|
||||
#define DP_SIXTH_OF_PI 0.523598775598298873
|
||||
#define BG_FP64_PI 3.14159265358979324
|
||||
#define BG_FP64_TWO_PI 6.28318530717958648
|
||||
#define BG_FP64_HALF_OF_PI 1.57079632679489662
|
||||
#define BG_FP64_THIRD_OF_PI 1.04719755119659775
|
||||
#define BG_FP64_FOURTH_OF_PI 0.78539816339744831
|
||||
#define BG_FP64_SIXTH_OF_PI 0.523598775598298873
|
||||
|
||||
#define DP_DEGREES_IN_RADIAN 57.2957795130823209
|
||||
#define DP_TURNS_IN_RADIAN 0.159154943091895336
|
||||
#define DP_RADIANS_IN_DEGREE 1.74532925199432958E-2
|
||||
#define DP_TURNS_IN_DEGREE 2.77777777777777778E-3
|
||||
#define BG_FP64_DEGREES_IN_RADIAN 57.2957795130823209
|
||||
#define BG_FP64_TURNS_IN_RADIAN 0.159154943091895336
|
||||
#define BG_FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2
|
||||
#define BG_FP64_TURNS_IN_DEGREE 2.77777777777777778E-3
|
||||
|
||||
typedef enum {
|
||||
ANGLE_UNIT_RADIANS = 1,
|
||||
ANGLE_UNIT_DEGREES = 2,
|
||||
ANGLE_UNIT_TURNS = 3
|
||||
BG_ANGLE_UNIT_RADIANS = 1,
|
||||
BG_ANGLE_UNIT_DEGREES = 2,
|
||||
BG_ANGLE_UNIT_TURNS = 3
|
||||
} angle_unit_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -39,394 +39,178 @@ typedef enum {
|
|||
* The measure of an angle with a range of:
|
||||
* [0, 360) degrees, [0, 2xPI) radians, [0, 1) turns, [0, 400) gradians
|
||||
*/
|
||||
ANGLE_RANGE_UNSIGNED = 1,
|
||||
BG_ANGLE_RANGE_UNSIGNED = 1,
|
||||
|
||||
/**
|
||||
* The measure of an angle with a range of:
|
||||
* (-180, 180] degrees, (-PI, PI] radians, (-0.5, 0.5] turns, (-200, 200] gradians
|
||||
*/
|
||||
ANGLE_RANGE_SIGNED = 2
|
||||
BG_ANGLE_RANGE_SIGNED = 2
|
||||
} angle_range_t;
|
||||
|
||||
// !================= Radians ==================! //
|
||||
|
||||
// ========= Convert radians to degrees ========= //
|
||||
|
||||
static inline float sp_radians_to_degrees(const float radians)
|
||||
static inline float bg_fp32_radians_to_degrees(const float radians)
|
||||
{
|
||||
return radians * SP_DEGREES_IN_RADIAN;
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double dp_radians_to_degrees(const double radians)
|
||||
static inline double bg_fp64_radians_to_degrees(const double radians)
|
||||
{
|
||||
return radians * DP_DEGREES_IN_RADIAN;
|
||||
return radians * BG_FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========== Convert radians to turns ========== //
|
||||
|
||||
static inline float sp_radians_to_turns(const float radians)
|
||||
static inline float bg_fp32_radians_to_turns(const float radians)
|
||||
{
|
||||
return radians * SP_TURNS_IN_RADIAN;
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double dp_radians_to_turns(const double radians)
|
||||
static inline double bg_fp64_radians_to_turns(const double radians)
|
||||
{
|
||||
return radians * DP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========= Convert degrees to radians ========= //
|
||||
|
||||
static inline float sp_degrees_to_radians(const float degrees)
|
||||
{
|
||||
return degrees * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double dp_degrees_to_radians(const double degrees)
|
||||
{
|
||||
return degrees * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert degrees to turns ========== //
|
||||
|
||||
static inline float sp_degrees_to_turns(const float radians)
|
||||
{
|
||||
return radians * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double dp_degrees_to_turns(const double radians)
|
||||
{
|
||||
return radians * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert turns to radians ========== //
|
||||
|
||||
static inline float sp_turns_to_radians(const float turns)
|
||||
{
|
||||
return turns * SP_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double dp_turns_to_radians(const double turns)
|
||||
{
|
||||
return turns * DP_TWO_PI;
|
||||
}
|
||||
|
||||
// ========== Convert turns to degrees ========== //
|
||||
|
||||
static inline float sp_turns_to_degrees(const float turns)
|
||||
{
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double dp_turns_to_degrees(const double turns)
|
||||
{
|
||||
return turns * 360.0;
|
||||
return radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========= Convert radians to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_radians(const float radians, const angle_unit_t to_unit)
|
||||
static inline float bg_fp32_radians_to_units(const float radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return radians * SP_DEGREES_IN_RADIAN;
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return radians * SP_TURNS_IN_RADIAN;
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_radians(const double radians, const angle_unit_t to_unit)
|
||||
static inline double bg_fp64_radians_to_units(const double radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return radians * DP_DEGREES_IN_RADIAN;
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return radians * BG_FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return radians * DP_TURNS_IN_RADIAN;
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
// ========= Convert degreess to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_degrees(const float degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return degrees * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return degrees * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_degrees(const double degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return degrees * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return degrees * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
// ========= Convert turns to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_turns(const float turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return turns * SP_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_turns(const double turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return turns * DP_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to radians ======== //
|
||||
|
||||
static inline float sp_convert_to_radians(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * SP_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_radians(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * DP_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to degreess ======== //
|
||||
|
||||
static inline float sp_convert_to_degrees(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0f;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_degrees(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * DP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to turns ======== //
|
||||
|
||||
static inline float sp_convert_to_turns(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * SP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_turns(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * DP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ============= Get Full Circle ============== //
|
||||
|
||||
static inline float sp_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_TWO_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 360.0f;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
static inline double dp_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_TWO_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 360.0;
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float sp_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 180.0f;
|
||||
}
|
||||
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
static inline double dp_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 180.0;
|
||||
}
|
||||
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float sp_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_HALF_OF_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 90.0f;
|
||||
}
|
||||
|
||||
return 0.25f;
|
||||
}
|
||||
|
||||
static inline double dp_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_HALF_OF_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 90.0;
|
||||
}
|
||||
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
// ============ Normalize radians ============= //
|
||||
|
||||
static inline float sp_normalize_radians(const float radians, const angle_range_t range)
|
||||
static inline float bg_fp32_radians_normalize(const float radians, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= radians && radians < SP_TWO_PI) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= radians && radians < BG_FP32_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-SP_PI < radians && radians <= SP_PI) {
|
||||
if (-BG_FP32_PI < radians && radians <= BG_FP32_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
float turns = radians * SP_TURNS_IN_RADIAN;
|
||||
float turns = radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * SP_TWO_PI;
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_radians(const double radians, const angle_range_t range)
|
||||
static inline double bg_fp64_radians_normalize(const double radians, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= radians && radians < DP_TWO_PI) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= radians && radians < BG_FP64_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-DP_PI < radians && radians <= DP_PI) {
|
||||
if (-BG_FP64_PI < radians && radians <= BG_FP64_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
double turns = radians * DP_TURNS_IN_RADIAN;
|
||||
double turns = radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * DP_TWO_PI;
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// !================= Degrees ==================! //
|
||||
|
||||
// ========= Convert degrees to radians ========= //
|
||||
|
||||
static inline float bg_fp32_degrees_to_radians(const float degrees)
|
||||
{
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_radians(const double degrees)
|
||||
{
|
||||
return degrees * BG_FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert degrees to turns ========== //
|
||||
|
||||
static inline float bg_fp32_degrees_to_turns(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_turns(const double radians)
|
||||
{
|
||||
return radians * BG_FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========= Convert degreess to any unit ======== //
|
||||
|
||||
static inline float bg_fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return degrees * BG_FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
// ============ Normalize degrees ============= //
|
||||
|
||||
static inline float sp_normalize_degrees(const float degrees, const angle_range_t range)
|
||||
static inline float bg_fp32_degrees_normalize(const float degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= degrees && degrees < 360.0f) {
|
||||
return degrees;
|
||||
}
|
||||
|
@ -437,20 +221,20 @@ static inline float sp_normalize_degrees(const float degrees, const angle_range_
|
|||
}
|
||||
}
|
||||
|
||||
float turns = degrees * SP_TURNS_IN_DEGREE;
|
||||
float turns = degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_degrees(const double degrees, const angle_range_t range)
|
||||
static inline double bg_fp64_degrees_normalize(const double degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= degrees && degrees < 360.0) {
|
||||
return degrees;
|
||||
}
|
||||
|
@ -461,22 +245,76 @@ static inline double dp_normalize_degrees(const double degrees, const angle_rang
|
|||
}
|
||||
}
|
||||
|
||||
double turns = degrees * DP_TURNS_IN_DEGREE;
|
||||
double turns = degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// !================== Turns ===================! //
|
||||
|
||||
// ========== Convert turns to radians ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_radians(const float turns)
|
||||
{
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_radians(const double turns)
|
||||
{
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ========== Convert turns to degrees ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_degrees(const float turns)
|
||||
{
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_degrees(const double turns)
|
||||
{
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// ========= Convert turns to any unit ======== //
|
||||
|
||||
static inline float bg_fp32_turns_to_units(const float turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_units(const double turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
// ============= Normalize turns ============== //
|
||||
|
||||
static inline float sp_normalize_turns(const float turns, const angle_range_t range)
|
||||
static inline float bg_fp32_turns_normalize(const float turns, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= turns && turns < 1.0f) {
|
||||
return turns;
|
||||
}
|
||||
|
@ -489,16 +327,16 @@ static inline float sp_normalize_turns(const float turns, const angle_range_t ra
|
|||
|
||||
float rest = turns - floorf(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && rest > 0.5f) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5f) {
|
||||
return rest - 1.0f;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_turns(const double turns, const angle_range_t range)
|
||||
static inline double bg_fp64_turns_normalize(const double turns, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= turns && turns < 1.0) {
|
||||
return turns;
|
||||
}
|
||||
|
@ -511,39 +349,209 @@ static inline double dp_normalize_turns(const double turns, const angle_range_t
|
|||
|
||||
double rest = turns - floor(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && rest > 0.5) {
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5) {
|
||||
return rest - 1.0;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
// ================ Normalize ================= //
|
||||
// !================== Angle ===================! //
|
||||
|
||||
static inline float sp_normalize_angle(const float angle, const angle_unit_t unit, const angle_range_t range)
|
||||
// ========= Convert any unit to radians ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_radians(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return sp_normalize_degrees(angle, range);
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return sp_normalize_turns(angle, range);
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
return sp_normalize_radians(angle, range);
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_angle(const double angle, const angle_unit_t unit, const angle_range_t range)
|
||||
static inline double bg_fp64_angle_to_radians(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return dp_normalize_degrees(angle, range);
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return dp_normalize_turns(angle, range);
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
return dp_normalize_radians(angle, range);
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to degreess ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_degrees(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0f;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_to_degrees(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to turns ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_turns(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_to_turns(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ============= Get Full Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
return BG_FP32_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
return BG_FP64_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.25f;
|
||||
}
|
||||
|
||||
return BG_FP32_HALF_OF_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
return BG_FP64_HALF_OF_PI;
|
||||
}
|
||||
|
||||
// ================ Normalize ================= //
|
||||
|
||||
static inline float bg_fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp32_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp32_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_fp32_radians_normalize(angle, range);
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp64_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp64_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_fp64_radians_normalize(angle, range);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
56
src/basis.h
56
src/basis.h
|
@ -1,56 +1,56 @@
|
|||
#ifndef __GEOMETRY__TYPES_H_
|
||||
#define __GEOMETRY__TYPES_H_
|
||||
|
||||
#define SP_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
|
||||
#define BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
|
||||
|
||||
#define SP_EPSYLON 5E-7f
|
||||
#define SP_TWO_EPSYLON 1E-6f
|
||||
#define SP_SQUARE_EPSYLON 2.5E-13f
|
||||
#define BG_FP32_EPSYLON 5E-7f
|
||||
#define BG_FP32_TWO_EPSYLON 1E-6f
|
||||
#define BG_FP32_SQUARE_EPSYLON 2.5E-13f
|
||||
|
||||
#define SP_ONE_THIRD 0.333333333f
|
||||
#define SP_ONE_SIXTH 0.166666667f
|
||||
#define SP_ONE_NINETH 0.111111111f
|
||||
#define BG_FP32_ONE_THIRD 0.333333333f
|
||||
#define BG_FP32_ONE_SIXTH 0.166666667f
|
||||
#define BG_FP32_ONE_NINETH 0.111111111f
|
||||
|
||||
#define SP_GOLDEN_RATIO_HIGH 1.618034f
|
||||
#define SP_GOLDEN_RATIO_LOW 0.618034f
|
||||
#define BG_FP32_GOLDEN_RATIO_HIGH 1.618034f
|
||||
#define BG_FP32_GOLDEN_RATIO_LOW 0.618034f
|
||||
|
||||
#define DP_EPSYLON_EFFECTIVENESS_LIMIT 10.0
|
||||
#define BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0
|
||||
|
||||
#define DP_EPSYLON 5E-14
|
||||
#define DP_TWO_EPSYLON 1E-13
|
||||
#define DP_SQUARE_EPSYLON 2.5E-27
|
||||
#define BG_FP64_EPSYLON 5E-14
|
||||
#define BG_FP64_TWO_EPSYLON 1E-13
|
||||
#define BG_FP64_SQUARE_EPSYLON 2.5E-27
|
||||
|
||||
#define DP_ONE_THIRD 0.333333333333333333
|
||||
#define DP_ONE_SIXTH 0.166666666666666667
|
||||
#define DP_ONE_NINETH 0.111111111111111111
|
||||
#define BG_FP64_ONE_THIRD 0.333333333333333333
|
||||
#define BG_FP64_ONE_SIXTH 0.166666666666666667
|
||||
#define BG_FP64_ONE_NINETH 0.111111111111111111
|
||||
|
||||
#define DP_GOLDEN_RATIO_HIGH 1.61803398874989485
|
||||
#define DP_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
#define BG_FP64_GOLDEN_RATIO_HIGH 1.61803398874989485
|
||||
#define BG_FP64_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
|
||||
static inline int sp_are_equal(const float value1, const float value2)
|
||||
static inline int bg_fp32_are_equal(const float value1, const float value2)
|
||||
{
|
||||
if (-SP_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < SP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -SP_EPSYLON <= (value1 - value2) && (value1 - value2) <= SP_EPSYLON;
|
||||
if (-BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -BG_FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP32_EPSYLON;
|
||||
}
|
||||
|
||||
if (value1 < 0.0f) {
|
||||
return (1.0f + SP_EPSYLON) * value2 <= value1 && (1.0f + SP_EPSYLON) * value1 <= value2;
|
||||
return (1.0f + BG_FP32_EPSYLON) * value2 <= value1 && (1.0f + BG_FP32_EPSYLON) * value1 <= value2;
|
||||
}
|
||||
|
||||
return value2 <= value1 * (1.0f + SP_EPSYLON) && value1 <= value2 * (1.0f + SP_EPSYLON);
|
||||
return value2 <= value1 * (1.0f + BG_FP32_EPSYLON) && value1 <= value2 * (1.0f + BG_FP32_EPSYLON);
|
||||
}
|
||||
|
||||
static inline int dp_are_equal(const double value1, const double value2)
|
||||
static inline int bg_fp64_are_equal(const double value1, const double value2)
|
||||
{
|
||||
if (-DP_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < DP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -DP_EPSYLON <= (value1 - value2) && (value1 - value2) <= DP_EPSYLON;
|
||||
if (-BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -BG_FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP64_EPSYLON;
|
||||
}
|
||||
|
||||
if (value1 < 0.0) {
|
||||
return (1.0 + DP_EPSYLON) * value2 <= value1 && (1.0 + DP_EPSYLON) * value1 <= value2;
|
||||
return (1.0 + BG_FP64_EPSYLON) * value2 <= value1 && (1.0 + BG_FP64_EPSYLON) * value1 <= value2;
|
||||
}
|
||||
|
||||
return value2 <= value1 * (1.0 + DP_EPSYLON) && value1 <= value2 * (1.0 + DP_EPSYLON);
|
||||
return value2 <= value1 * (1.0 + BG_FP64_EPSYLON) && value1 <= value2 * (1.0 + BG_FP64_EPSYLON);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,11 +2,76 @@
|
|||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="matrix2x3.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1596" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1849" topLine="187" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="24" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="13404" topLine="440" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="556" topLine="12" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="24" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="504" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="154" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="27" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="103" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="20" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1082" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x2.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="897" topLine="52" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6789" topLine="145" />
|
||||
|
@ -14,67 +79,7 @@
|
|||
</File>
|
||||
<File name="matrix3x3.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="18608" topLine="582" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x2.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="897" topLine="52" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="556" topLine="12" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="305" topLine="29" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="16048" topLine="102" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="quaternion.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1849" topLine="187" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="103" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="504" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="23" topLine="72" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1082" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="versor.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="27" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="154" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x3.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1596" topLine="0" />
|
||||
<Cursor1 position="17612" topLine="537" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="geometry.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
@ -82,29 +87,24 @@
|
|||
<Cursor1 position="316" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="15169" topLine="102" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="rotation3.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="305" topLine="29" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix3x3.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="23" topLine="72" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector3.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="24" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="matrix2x2.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="18276" topLine="538" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="basis.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="20" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="vector2.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="24" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="angle.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
|
128
src/matrix2x2.h
128
src/matrix2x2.h
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix2x2_reset(SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_reset(BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -15,7 +15,7 @@ static inline void sp_matrix2x2_reset(SPMatrix2x2* matrix)
|
|||
matrix->r2c2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_reset(DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_reset(BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -25,7 +25,7 @@ static inline void dp_matrix2x2_reset(DPMatrix2x2* matrix)
|
|||
|
||||
// ================== Identity ================== //
|
||||
|
||||
static inline void sp_matrix2x2_make_identity(SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_to_identity(BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -33,7 +33,7 @@ static inline void sp_matrix2x2_make_identity(SPMatrix2x2* matrix)
|
|||
matrix->r2c2 = 1.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_make_identity(DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_to_identity(BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -43,7 +43,7 @@ static inline void dp_matrix2x2_make_identity(DPMatrix2x2* matrix)
|
|||
|
||||
// ================ Make Diagonal =============== //
|
||||
|
||||
static inline void sp_matrix2x2_make_diagonal(const float d1, const float d2, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_to_diagonal(const float d1, const float d2, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -51,7 +51,7 @@ static inline void sp_matrix2x2_make_diagonal(const float d1, const float d2, SP
|
|||
matrix->r2c2 = d2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_make_diagonal(const double d1, const double d2, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_to_diagonal(const double d1, const double d2, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -61,9 +61,9 @@ static inline void dp_matrix2x2_make_diagonal(const double d1, const double d2,
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
static inline void sp_matrix2x2_make_turn(const float angle, const angle_unit_t unit, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_make_turn(const float angle, const angle_unit_t unit, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
const float radians = sp_convert_to_radians(angle, unit);
|
||||
const float radians = bg_fp32_angle_to_radians(angle, unit);
|
||||
const float cosine = cosf(radians);
|
||||
const float sine = sinf(radians);
|
||||
|
||||
|
@ -73,9 +73,9 @@ static inline void sp_matrix2x2_make_turn(const float angle, const angle_unit_t
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_make_turn(const double angle, const angle_unit_t unit, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_make_turn(const double angle, const angle_unit_t unit, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
const double radians = dp_convert_to_radians(angle, unit);
|
||||
const double radians = bg_fp64_angle_to_radians(angle, unit);
|
||||
const double cosine = cos(radians);
|
||||
const double sine = sin(radians);
|
||||
|
||||
|
@ -87,7 +87,7 @@ static inline void dp_matrix2x2_make_turn(const double angle, const angle_unit_t
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_matrix2x2_copy(const SPMatrix2x2* from, SPMatrix2x2* to)
|
||||
static inline void bg_fp32_matrix2x2_copy(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -96,7 +96,7 @@ static inline void sp_matrix2x2_copy(const SPMatrix2x2* from, SPMatrix2x2* to)
|
|||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_copy(const DPMatrix2x2* from, DPMatrix2x2* to)
|
||||
static inline void bg_fp64_matrix2x2_copy(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -107,7 +107,7 @@ static inline void dp_matrix2x2_copy(const DPMatrix2x2* from, DPMatrix2x2* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_matrix2x2_set_from_double(const DPMatrix2x2* from, SPMatrix2x2* to)
|
||||
static inline void bg_fp32_matrix2x2_set_from_fp64(const BgFP64Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
{
|
||||
to->r1c1 = (float)from->r1c1;
|
||||
to->r1c2 = (float)from->r1c2;
|
||||
|
@ -116,7 +116,7 @@ static inline void sp_matrix2x2_set_from_double(const DPMatrix2x2* from, SPMatri
|
|||
to->r2c2 = (float)from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_from_single(const SPMatrix2x2* from, DPMatrix2x2* to)
|
||||
static inline void bg_fp64_matrix2x2_set_from_fp32(const BgFP32Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -127,42 +127,42 @@ static inline void dp_matrix2x2_set_from_single(const SPMatrix2x2* from, DPMatri
|
|||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
static inline float sp_matrix2x2_get_determinant(const SPMatrix2x2* matrix)
|
||||
static inline float bg_fp32_matrix2x2_get_determinant(const BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
static inline double dp_matrix2x2_get_determinant(const DPMatrix2x2* matrix)
|
||||
static inline double bg_fp64_matrix2x2_get_determinant(const BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
// ================== Singular ================== //
|
||||
|
||||
static inline int sp_matrix2x2_is_singular(const SPMatrix2x2* matrix)
|
||||
static inline int bg_fp32_matrix2x2_is_singular(const BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
const float determinant = sp_matrix2x2_get_determinant(matrix);
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
return -SP_EPSYLON <= determinant && determinant <= SP_EPSYLON;
|
||||
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_matrix2x2_is_singular(const DPMatrix2x2* matrix)
|
||||
static inline int bg_fp64_matrix2x2_is_singular(const BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
const double determinant = dp_matrix2x2_get_determinant(matrix);
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
return -DP_EPSYLON <= determinant && determinant <= DP_EPSYLON;
|
||||
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
||||
}
|
||||
|
||||
// =============== Transposition ================ //
|
||||
|
||||
static inline void sp_matrix2x2_transpose(SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_transpose(BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
const float tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_transpose(DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
const double tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
|
@ -171,11 +171,11 @@ static inline void dp_matrix2x2_transpose(DPMatrix2x2* matrix)
|
|||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline int sp_matrix2x2_invert(SPMatrix2x2* matrix)
|
||||
static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
const float determinant = sp_matrix2x2_get_determinant(matrix);
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (-SP_EPSYLON <= determinant && determinant <= SP_EPSYLON) {
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -194,11 +194,11 @@ static inline int sp_matrix2x2_invert(SPMatrix2x2* matrix)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_matrix2x2_invert(DPMatrix2x2* matrix)
|
||||
static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
const double determinant = dp_matrix2x2_get_determinant(matrix);
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (-DP_EPSYLON <= determinant && determinant <= DP_EPSYLON) {
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ static inline int dp_matrix2x2_invert(DPMatrix2x2* matrix)
|
|||
|
||||
// =============== Set Transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x2_set_transposed(const SPMatrix2x2* from, SPMatrix2x2* to)
|
||||
static inline void bg_fp32_matrix2x2_set_transposed(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
{
|
||||
float tmp = from->r1c2;
|
||||
|
||||
|
@ -230,7 +230,7 @@ static inline void sp_matrix2x2_set_transposed(const SPMatrix2x2* from, SPMatrix
|
|||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_transposed(const DPMatrix2x2* from, DPMatrix2x2* to)
|
||||
static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
{
|
||||
double tmp = from->r1c2;
|
||||
|
||||
|
@ -243,11 +243,11 @@ static inline void dp_matrix2x2_set_transposed(const DPMatrix2x2* from, DPMatrix
|
|||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
static inline int sp_matrix2x2_set_inverted(const SPMatrix2x2* from, SPMatrix2x2* to)
|
||||
static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
{
|
||||
const float determinant = sp_matrix2x2_get_determinant(from);
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-SP_EPSYLON <= determinant && determinant <= SP_EPSYLON) {
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -266,11 +266,11 @@ static inline int sp_matrix2x2_set_inverted(const SPMatrix2x2* from, SPMatrix2x2
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_matrix2x2_set_inverted(const DPMatrix2x2* from, DPMatrix2x2* to)
|
||||
static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
{
|
||||
const double determinant = dp_matrix2x2_get_determinant(from);
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-DP_EPSYLON <= determinant && determinant <= DP_EPSYLON) {
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -291,13 +291,13 @@ static inline int dp_matrix2x2_set_inverted(const DPMatrix2x2* from, DPMatrix2x2
|
|||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void sp_matrix2x2_set_row1(const float c1, const float c2, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_row1(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_row1(const double c1, const double c2, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_row1(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
|
@ -305,13 +305,13 @@ static inline void dp_matrix2x2_set_row1(const double c1, const double c2, DPMat
|
|||
|
||||
// ================= Set Row 2 ================== //
|
||||
|
||||
static inline void sp_matrix2x2_set_row2(const float c1, const float c2, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_row2(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_row2(const double c1, const double c2, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_row2(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
|
@ -319,13 +319,13 @@ static inline void dp_matrix2x2_set_row2(const double c1, const double c2, DPMat
|
|||
|
||||
// ================ Set Column 1 ================ //
|
||||
|
||||
static inline void sp_matrix2x2_set_column1(const float r1, const float r2, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_column1(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_column1(const double r1, const double r2, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_column1(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
|
@ -333,13 +333,13 @@ static inline void dp_matrix2x2_set_column1(const double r1, const double r2, DP
|
|||
|
||||
// ================ Set Column 2 ================ //
|
||||
|
||||
static inline void sp_matrix2x2_set_column2(const float r1, const float r2, SPMatrix2x2* matrix)
|
||||
static inline void bg_fp32_matrix2x2_set_column2(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_set_column2(const double r1, const double r2, DPMatrix2x2* matrix)
|
||||
static inline void bg_fp64_matrix2x2_set_column2(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
|
@ -347,7 +347,7 @@ static inline void dp_matrix2x2_set_column2(const double r1, const double r2, DP
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_matrix2x2_append_scaled(SPMatrix2x2* basic_vector, const SPMatrix2x2* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_matrix2x2_append_scaled(BgFP32Matrix2x2* basic_vector, const BgFP32Matrix2x2* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -356,7 +356,7 @@ static inline void sp_matrix2x2_append_scaled(SPMatrix2x2* basic_vector, const S
|
|||
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_append_scaled(DPMatrix2x2* basic_vector, const DPMatrix2x2* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_matrix2x2_append_scaled(BgFP64Matrix2x2* basic_vector, const BgFP64Matrix2x2* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -367,7 +367,7 @@ static inline void dp_matrix2x2_append_scaled(DPMatrix2x2* basic_vector, const D
|
|||
|
||||
// ================== Addition ================== //
|
||||
|
||||
static inline void sp_matrix2x2_add(const SPMatrix2x2* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x2* sum)
|
||||
static inline void bg_fp32_matrix2x2_add(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -376,7 +376,7 @@ static inline void sp_matrix2x2_add(const SPMatrix2x2* matrix1, const SPMatrix2x
|
|||
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_add(const DPMatrix2x2* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x2* sum)
|
||||
static inline void bg_fp64_matrix2x2_add(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -387,7 +387,7 @@ static inline void dp_matrix2x2_add(const DPMatrix2x2* matrix1, const DPMatrix2x
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_matrix2x2_subtract(const SPMatrix2x2* minuend, const SPMatrix2x2* subtrahend, SPMatrix2x2* difference)
|
||||
static inline void bg_fp32_matrix2x2_subtract(const BgFP32Matrix2x2* minuend, const BgFP32Matrix2x2* subtrahend, BgFP32Matrix2x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -396,7 +396,7 @@ static inline void sp_matrix2x2_subtract(const SPMatrix2x2* minuend, const SPMat
|
|||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_subtract(const DPMatrix2x2* minuend, const DPMatrix2x2* subtrahend, DPMatrix2x2* difference)
|
||||
static inline void bg_fp64_matrix2x2_subtract(const BgFP64Matrix2x2* minuend, const BgFP64Matrix2x2* subtrahend, BgFP64Matrix2x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -407,7 +407,7 @@ static inline void dp_matrix2x2_subtract(const DPMatrix2x2* minuend, const DPMat
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_matrix2x2_multiply(const SPMatrix2x2* multiplicand, const float multiplier, SPMatrix2x2* product)
|
||||
static inline void bg_fp32_matrix2x2_multiply(const BgFP32Matrix2x2* multiplicand, const float multiplier, BgFP32Matrix2x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -416,7 +416,7 @@ static inline void sp_matrix2x2_multiply(const SPMatrix2x2* multiplicand, const
|
|||
product->r2c2 = multiplicand->r2c2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_multiply(const DPMatrix2x2* multiplicand, const double multiplier, DPMatrix2x2* product)
|
||||
static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplicand, const double multiplier, BgFP64Matrix2x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -427,7 +427,7 @@ static inline void dp_matrix2x2_multiply(const DPMatrix2x2* multiplicand, const
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_matrix2x2_divide(const SPMatrix2x2* dividend, const float divisor, SPMatrix2x2* quotient)
|
||||
static inline void bg_fp32_matrix2x2_divide(const BgFP32Matrix2x2* dividend, const float divisor, BgFP32Matrix2x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -436,7 +436,7 @@ static inline void sp_matrix2x2_divide(const SPMatrix2x2* dividend, const float
|
|||
quotient->r2c2 = dividend->r2c2 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_divide(const DPMatrix2x2* dividend, const double divisor, DPMatrix2x2* quotient)
|
||||
static inline void bg_fp64_matrix2x2_divide(const BgFP64Matrix2x2* dividend, const double divisor, BgFP64Matrix2x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -447,18 +447,18 @@ static inline void dp_matrix2x2_divide(const DPMatrix2x2* dividend, const double
|
|||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void sp_matrix2x2_left_product(const SPVector2* vector, const SPMatrix2x2* matrix, SPVector2* result)
|
||||
static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix2x2* matrix, BgFP32Vector2* result)
|
||||
{
|
||||
sp_vector2_set_values(
|
||||
bg_fp32_vector2_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_left_product(const DPVector2* vector, const DPMatrix2x2* matrix, DPVector2* result)
|
||||
static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix2x2* matrix, BgFP64Vector2* result)
|
||||
{
|
||||
dp_vector2_set_values(
|
||||
bg_fp64_vector2_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2,
|
||||
result
|
||||
|
@ -467,18 +467,18 @@ static inline void dp_matrix2x2_left_product(const DPVector2* vector, const DPMa
|
|||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void sp_matrix2x2_right_product(const SPMatrix2x2* matrix, const SPVector2* vector, SPVector2* result)
|
||||
static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
||||
{
|
||||
sp_vector2_set_values(
|
||||
bg_fp32_vector2_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x2_right_product(const DPMatrix2x2* matrix, const DPVector2* vector, DPVector2* result)
|
||||
static inline void bg_fp64_matrix2x2_right_product(const BgFP64Matrix2x2* matrix, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
||||
{
|
||||
dp_vector2_set_values(
|
||||
bg_fp64_vector2_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2,
|
||||
result
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix2x3_reset(SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_reset(BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -19,7 +19,7 @@ static inline void sp_matrix2x3_reset(SPMatrix2x3* matrix)
|
|||
matrix->r3c2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_reset(DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_reset(BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -33,11 +33,11 @@ static inline void dp_matrix2x3_reset(DPMatrix2x3* matrix)
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_matrix2x3_copy(const SPMatrix2x3* from, SPMatrix2x3* to)
|
||||
static inline void bg_fp32_matrix2x3_copy(const BgFP32Matrix2x3* from, BgFP32Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
||||
|
||||
to->r2c1 = from->r2c1;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
|
@ -45,7 +45,7 @@ static inline void sp_matrix2x3_copy(const SPMatrix2x3* from, SPMatrix2x3* to)
|
|||
to->r3c2 = from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_copy(const DPMatrix2x3* from, DPMatrix2x3* to)
|
||||
static inline void bg_fp64_matrix2x3_copy(const BgFP64Matrix2x3* from, BgFP64Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -59,7 +59,7 @@ static inline void dp_matrix2x3_copy(const DPMatrix2x3* from, DPMatrix2x3* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_matrix2x3_set_from_double(const DPMatrix2x3* from, SPMatrix2x3* to)
|
||||
static inline void bg_fp32_matrix2x3_set_from_fp64(const BgFP64Matrix2x3* from, BgFP32Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r1c2;
|
||||
|
@ -71,7 +71,7 @@ static inline void sp_matrix2x3_set_from_double(const DPMatrix2x3* from, SPMatri
|
|||
to->r3c2 = (float) from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_from_single(const SPMatrix2x3* from, DPMatrix2x3* to)
|
||||
static inline void bg_fp64_matrix2x3_set_from_fp32(const BgFP32Matrix2x3* from, BgFP64Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -85,7 +85,7 @@ static inline void dp_matrix2x3_set_from_single(const SPMatrix2x3* from, DPMatri
|
|||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x3_set_transposed(const SPMatrix3x2* from, SPMatrix2x3* to)
|
||||
static inline void bg_fp32_matrix2x3_set_transposed(const BgFP32Matrix3x2* from, BgFP32Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -97,7 +97,7 @@ static inline void sp_matrix2x3_set_transposed(const SPMatrix3x2* from, SPMatrix
|
|||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_transposed(const DPMatrix3x2* from, DPMatrix2x3* to)
|
||||
static inline void bg_fp64_matrix2x3_set_transposed(const BgFP64Matrix3x2* from, BgFP64Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -111,7 +111,7 @@ static inline void dp_matrix2x3_set_transposed(const DPMatrix3x2* from, DPMatrix
|
|||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix2x3_transpose_double(const DPMatrix3x2* from, SPMatrix2x3* to)
|
||||
static inline void bg_fp32_matrix2x3_set_transposed_fp64(const BgFP64Matrix3x2* from, BgFP32Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
|
@ -123,7 +123,7 @@ static inline void sp_matrix2x3_transpose_double(const DPMatrix3x2* from, SPMatr
|
|||
to->r3c2 = (float) from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_transpose_single(const SPMatrix3x2* from, DPMatrix2x3* to)
|
||||
static inline void bg_fp64_matrix2x3_set_transposed_fp32(const BgFP32Matrix3x2* from, BgFP64Matrix2x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -137,13 +137,13 @@ static inline void dp_matrix2x3_transpose_single(const SPMatrix3x2* from, DPMatr
|
|||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void sp_matrix2x3_set_row1(const float c1, const float c2, SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_set_row1(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_row1(const double c1, const double c2, DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_set_row1(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
|
@ -151,13 +151,13 @@ static inline void dp_matrix2x3_set_row1(const double c1, const double c2, DPMat
|
|||
|
||||
// ================= Set Row 2 ================== //
|
||||
|
||||
static inline void sp_matrix2x3_set_row2(const float c1, const float c2, SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_set_row2(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_row2(const double c1, const double c2, DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_set_row2(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
|
@ -165,13 +165,13 @@ static inline void dp_matrix2x3_set_row2(const double c1, const double c2, DPMat
|
|||
|
||||
// ================= Set Row 3 ================== //
|
||||
|
||||
static inline void sp_matrix2x3_set_row3(const float c1, const float c2, SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_set_row3(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r3c1 = c1;
|
||||
matrix->r3c2 = c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_row3(const double c1, const double c2, DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_set_row3(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r3c1 = c1;
|
||||
matrix->r3c2 = c2;
|
||||
|
@ -179,14 +179,14 @@ static inline void dp_matrix2x3_set_row3(const double c1, const double c2, DPMat
|
|||
|
||||
// ================ Set Column 1 ================ //
|
||||
|
||||
static inline void sp_matrix2x3_set_column1(const float r1, const float r2, const float r3, SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_set_column1(const float r1, const float r2, const float r3, BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
matrix->r3c1 = r3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_column1(const double r1, const double r2, const double r3, DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_set_column1(const double r1, const double r2, const double r3, BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
|
@ -195,14 +195,14 @@ static inline void dp_matrix2x3_set_column1(const double r1, const double r2, co
|
|||
|
||||
// ================ Set Column 2 ================ //
|
||||
|
||||
static inline void sp_matrix2x3_set_column2(const float r1, const float r2, const float r3, SPMatrix2x3* matrix)
|
||||
static inline void bg_fp32_matrix2x3_set_column2(const float r1, const float r2, const float r3, BgFP32Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
matrix->r3c2 = r3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_set_column2(const double r1, const double r2, const double r3, DPMatrix2x3* matrix)
|
||||
static inline void bg_fp64_matrix2x3_set_column2(const double r1, const double r2, const double r3, BgFP64Matrix2x3* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
|
@ -211,7 +211,7 @@ static inline void dp_matrix2x3_set_column2(const double r1, const double r2, co
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_matrix2x3_append_scaled(SPMatrix2x3* basic_vector, const SPMatrix2x3* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_matrix2x3_append_scaled(BgFP32Matrix2x3* basic_vector, const BgFP32Matrix2x3* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -223,7 +223,7 @@ static inline void sp_matrix2x3_append_scaled(SPMatrix2x3* basic_vector, const S
|
|||
basic_vector->r3c2 += scalable_vector->r3c2 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_append_scaled(DPMatrix2x3* basic_vector, const DPMatrix2x3* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_matrix2x3_append_scaled(BgFP64Matrix2x3* basic_vector, const BgFP64Matrix2x3* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -237,7 +237,7 @@ static inline void dp_matrix2x3_append_scaled(DPMatrix2x3* basic_vector, const D
|
|||
|
||||
// ================== Addition ================== //
|
||||
|
||||
static inline void sp_matrix2x3_add(const SPMatrix2x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* sum)
|
||||
static inline void bg_fp32_matrix2x3_add(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -249,7 +249,7 @@ static inline void sp_matrix2x3_add(const SPMatrix2x3* matrix1, const SPMatrix2x
|
|||
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_add(const DPMatrix2x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* sum)
|
||||
static inline void bg_fp64_matrix2x3_add(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -263,7 +263,7 @@ static inline void dp_matrix2x3_add(const DPMatrix2x3* matrix1, const DPMatrix2x
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_matrix2x3_subtract(const SPMatrix2x3* minuend, const SPMatrix2x3* subtrahend, SPMatrix2x3* difference)
|
||||
static inline void bg_fp32_matrix2x3_subtract(const BgFP32Matrix2x3* minuend, const BgFP32Matrix2x3* subtrahend, BgFP32Matrix2x3* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -275,7 +275,7 @@ static inline void sp_matrix2x3_subtract(const SPMatrix2x3* minuend, const SPMat
|
|||
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_subtract(const DPMatrix2x3* minuend, const DPMatrix2x3* subtrahend, DPMatrix2x3* difference)
|
||||
static inline void bg_fp64_matrix2x3_subtract(const BgFP64Matrix2x3* minuend, const BgFP64Matrix2x3* subtrahend, BgFP64Matrix2x3* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -289,7 +289,7 @@ static inline void dp_matrix2x3_subtract(const DPMatrix2x3* minuend, const DPMat
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_matrix2x3_multiply(const SPMatrix2x3* multiplicand, const float multiplier, SPMatrix2x3* product)
|
||||
static inline void bg_fp32_matrix2x3_multiply(const BgFP32Matrix2x3* multiplicand, const float multiplier, BgFP32Matrix2x3* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -301,7 +301,7 @@ static inline void sp_matrix2x3_multiply(const SPMatrix2x3* multiplicand, const
|
|||
product->r3c2 = multiplicand->r3c2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_multiply(const DPMatrix2x3* multiplicand, const double multiplier, DPMatrix2x3* product)
|
||||
static inline void bg_fp64_matrix2x3_multiply(const BgFP64Matrix2x3* multiplicand, const double multiplier, BgFP64Matrix2x3* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -315,7 +315,7 @@ static inline void dp_matrix2x3_multiply(const DPMatrix2x3* multiplicand, const
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_matrix2x3_divide(const SPMatrix2x3* dividend, const float divisor, SPMatrix2x3* quotient)
|
||||
static inline void bg_fp32_matrix2x3_divide(const BgFP32Matrix2x3* dividend, const float divisor, BgFP32Matrix2x3* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -327,7 +327,7 @@ static inline void sp_matrix2x3_divide(const SPMatrix2x3* dividend, const float
|
|||
quotient->r3c2 = dividend->r3c2 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_divide(const DPMatrix2x3* dividend, const double divisor, DPMatrix2x3* quotient)
|
||||
static inline void bg_fp64_matrix2x3_divide(const BgFP64Matrix2x3* dividend, const double divisor, BgFP64Matrix2x3* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -341,13 +341,13 @@ static inline void dp_matrix2x3_divide(const DPMatrix2x3* dividend, const double
|
|||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void sp_matrix2x3_left_product(const SPVector3* vector, const SPMatrix2x3* matrix, SPVector2* result)
|
||||
static inline void bg_fp32_matrix2x3_left_product(const BgFP32Vector3* vector, const BgFP32Matrix2x3* matrix, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_left_product(const DPVector3* vector, const DPMatrix2x3* matrix, DPVector2* result)
|
||||
static inline void bg_fp64_matrix2x3_left_product(const BgFP64Vector3* vector, const BgFP64Matrix2x3* matrix, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||
|
@ -355,14 +355,14 @@ static inline void dp_matrix2x3_left_product(const DPVector3* vector, const DPMa
|
|||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void sp_matrix2x3_right_product(const SPMatrix2x3* matrix, const SPVector2* vector, SPVector3* result)
|
||||
static inline void bg_fp32_matrix2x3_right_product(const BgFP32Matrix2x3* matrix, const BgFP32Vector2* vector, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
result->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix2x3_right_product(const DPMatrix2x3* matrix, const DPVector2* vector, DPVector3* result)
|
||||
static inline void bg_fp64_matrix2x3_right_product(const BgFP64Matrix2x3* matrix, const BgFP64Vector2* vector, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix3x2_reset(SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_reset(BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -18,7 +18,7 @@ static inline void sp_matrix3x2_reset(SPMatrix3x2* matrix)
|
|||
matrix->r2c3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_reset(DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_reset(BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -31,7 +31,7 @@ static inline void dp_matrix3x2_reset(DPMatrix3x2* matrix)
|
|||
|
||||
// ============= Set from twin type ============= //
|
||||
|
||||
static inline void sp_matrix3x2_set_from_double(const DPMatrix3x2* from, SPMatrix3x2* to)
|
||||
static inline void bg_fp32_matrix3x2_set_from_fp64(const BgFP64Matrix3x2* from, BgFP32Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r1c2;
|
||||
|
@ -42,7 +42,7 @@ static inline void sp_matrix3x2_set_from_double(const DPMatrix3x2* from, SPMatri
|
|||
to->r2c3 = (float) from->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_from_single(const SPMatrix3x2* from, DPMatrix3x2* to)
|
||||
static inline void bg_fp64_matrix3x2_set_from_fp32(const BgFP32Matrix3x2* from, BgFP64Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -55,7 +55,7 @@ static inline void dp_matrix3x2_set_from_single(const SPMatrix3x2* from, DPMatri
|
|||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix3x2_set_transposed(const SPMatrix2x3* from, SPMatrix3x2* to)
|
||||
static inline void bg_fp32_matrix3x2_set_transposed(const BgFP32Matrix2x3* from, BgFP32Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -66,7 +66,7 @@ static inline void sp_matrix3x2_set_transposed(const SPMatrix2x3* from, SPMatrix
|
|||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_transposed(const DPMatrix2x3* from, DPMatrix3x2* to)
|
||||
static inline void bg_fp64_matrix3x2_set_transposed(const BgFP64Matrix2x3* from, BgFP64Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -79,7 +79,7 @@ static inline void dp_matrix3x2_set_transposed(const DPMatrix2x3* from, DPMatrix
|
|||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
static inline void sp_matrix3x2_transpose_double(const DPMatrix2x3* from, SPMatrix3x2* to)
|
||||
static inline void bg_fp32_matrix3x2_set_transposed_fp64(const BgFP64Matrix2x3* from, BgFP32Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
|
@ -90,7 +90,7 @@ static inline void sp_matrix3x2_transpose_double(const DPMatrix2x3* from, SPMatr
|
|||
to->r2c3 = (float) from->r3c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_transpose_single(const SPMatrix2x3* from, DPMatrix3x2* to)
|
||||
static inline void bg_fp64_matrix3x2_set_transposed_fp32(const BgFP32Matrix2x3* from, BgFP64Matrix3x2* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
@ -103,14 +103,14 @@ static inline void dp_matrix3x2_transpose_single(const SPMatrix2x3* from, DPMatr
|
|||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void sp_matrix3x2_set_row1(const float c1, const float c2, const float c3, SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_set_row1(const float c1, const float c2, const float c3, BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
matrix->r1c3 = c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_row1(const double c1, const double c2, const double c3, DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_set_row1(const double c1, const double c2, const double c3, BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
|
@ -119,14 +119,14 @@ static inline void dp_matrix3x2_set_row1(const double c1, const double c2, const
|
|||
|
||||
// ================= Set Row 2 ================== //
|
||||
|
||||
static inline void sp_matrix3x2_set_row2(const float c1, const float c2, const float c3, SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_set_row2(const float c1, const float c2, const float c3, BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
matrix->r2c3 = c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_row2(const double c1, const double c2, const double c3, DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_set_row2(const double c1, const double c2, const double c3, BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
|
@ -135,13 +135,13 @@ static inline void dp_matrix3x2_set_row2(const double c1, const double c2, const
|
|||
|
||||
// ================ Set Column 1 ================ //
|
||||
|
||||
static inline void sp_matrix3x2_set_column1(const float r1, const float r2, SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_set_column1(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_column1(const double r1, const double r2, DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_set_column1(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
|
@ -149,13 +149,13 @@ static inline void dp_matrix3x2_set_column1(const double r1, const double r2, DP
|
|||
|
||||
// ================ Set Column 2 ================ //
|
||||
|
||||
static inline void sp_matrix3x2_set_column2(const float r1, const float r2, SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_set_column2(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_column2(const double r1, const double r2, DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_set_column2(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
|
@ -163,13 +163,13 @@ static inline void dp_matrix3x2_set_column2(const double r1, const double r2, DP
|
|||
|
||||
// ================ Set Column 3 ================ //
|
||||
|
||||
static inline void sp_matrix3x2_set_column3(const float r1, const float r2, SPMatrix3x2* matrix)
|
||||
static inline void bg_fp32_matrix3x2_set_column3(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c3 = r1;
|
||||
matrix->r2c3 = r2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_set_column3(const double r1, const double r2, DPMatrix3x2* matrix)
|
||||
static inline void bg_fp64_matrix3x2_set_column3(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
||||
{
|
||||
matrix->r1c3 = r1;
|
||||
matrix->r2c3 = r2;
|
||||
|
@ -177,7 +177,7 @@ static inline void dp_matrix3x2_set_column3(const double r1, const double r2, DP
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_matrix3x2_append_scaled(SPMatrix3x2* basic_vector, const SPMatrix3x2* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_matrix3x2_append_scaled(BgFP32Matrix3x2* basic_vector, const BgFP32Matrix3x2* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -188,7 +188,7 @@ static inline void sp_matrix3x2_append_scaled(SPMatrix3x2* basic_vector, const S
|
|||
basic_vector->r2c3 += scalable_vector->r2c3 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_append_scaled(DPMatrix3x2* basic_vector, const DPMatrix3x2* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_matrix3x2_append_scaled(BgFP64Matrix3x2* basic_vector, const BgFP64Matrix3x2* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -201,7 +201,7 @@ static inline void dp_matrix3x2_append_scaled(DPMatrix3x2* basic_vector, const D
|
|||
|
||||
// ================== Addition ================== //
|
||||
|
||||
static inline void sp_matrix3x2_add(const SPMatrix3x2* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x2* sum)
|
||||
static inline void bg_fp32_matrix3x2_add(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -212,7 +212,7 @@ static inline void sp_matrix3x2_add(const SPMatrix3x2* matrix1, const SPMatrix3x
|
|||
sum->r2c3 = matrix1->r2c3 + matrix2->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_add(const DPMatrix3x2* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x2* sum)
|
||||
static inline void bg_fp64_matrix3x2_add(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -225,7 +225,7 @@ static inline void dp_matrix3x2_add(const DPMatrix3x2* matrix1, const DPMatrix3x
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_matrix3x2_subtract(const SPMatrix3x2* minuend, const SPMatrix3x2* subtrahend, SPMatrix3x2* difference)
|
||||
static inline void bg_fp32_matrix3x2_subtract(const BgFP32Matrix3x2* minuend, const BgFP32Matrix3x2* subtrahend, BgFP32Matrix3x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -236,7 +236,7 @@ static inline void sp_matrix3x2_subtract(const SPMatrix3x2* minuend, const SPMat
|
|||
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_subtract(const DPMatrix3x2* minuend, const DPMatrix3x2* subtrahend, DPMatrix3x2* difference)
|
||||
static inline void bg_fp64_matrix3x2_subtract(const BgFP64Matrix3x2* minuend, const BgFP64Matrix3x2* subtrahend, BgFP64Matrix3x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -249,7 +249,7 @@ static inline void dp_matrix3x2_subtract(const DPMatrix3x2* minuend, const DPMat
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_matrix3x2_multiply(const SPMatrix3x2* multiplicand, const float multiplier, SPMatrix3x2* product)
|
||||
static inline void bg_fp32_matrix3x2_multiply(const BgFP32Matrix3x2* multiplicand, const float multiplier, BgFP32Matrix3x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -260,7 +260,7 @@ static inline void sp_matrix3x2_multiply(const SPMatrix3x2* multiplicand, const
|
|||
product->r2c3 = multiplicand->r2c3 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_multiply(const DPMatrix3x2* multiplicand, const double multiplier, DPMatrix3x2* product)
|
||||
static inline void bg_fp64_matrix3x2_multiply(const BgFP64Matrix3x2* multiplicand, const double multiplier, BgFP64Matrix3x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -273,7 +273,7 @@ static inline void dp_matrix3x2_multiply(const DPMatrix3x2* multiplicand, const
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_matrix3x2_divide(const SPMatrix3x2* dividend, const float divisor, SPMatrix3x2* quotient)
|
||||
static inline void bg_fp32_matrix3x2_divide(const BgFP32Matrix3x2* dividend, const float divisor, BgFP32Matrix3x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -284,7 +284,7 @@ static inline void sp_matrix3x2_divide(const SPMatrix3x2* dividend, const float
|
|||
quotient->r2c3 = dividend->r2c3 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_divide(const DPMatrix3x2* dividend, const double divisor, DPMatrix3x2* quotient)
|
||||
static inline void bg_fp64_matrix3x2_divide(const BgFP64Matrix3x2* dividend, const double divisor, BgFP64Matrix3x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -297,14 +297,14 @@ static inline void dp_matrix3x2_divide(const DPMatrix3x2* dividend, const double
|
|||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void sp_matrix3x2_left_product(const SPVector2* vector, const SPMatrix3x2* matrix, SPVector3* result)
|
||||
static inline void bg_fp32_matrix3x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix3x2* matrix, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
result->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_left_product(const DPVector2* vector, const DPMatrix3x2* matrix, DPVector3* result)
|
||||
static inline void bg_fp64_matrix3x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix3x2* matrix, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
@ -313,13 +313,13 @@ static inline void dp_matrix3x2_left_product(const DPVector2* vector, const DPMa
|
|||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void sp_matrix3x2_right_product(const SPMatrix3x2* matrix, const SPVector3* vector, SPVector2* result)
|
||||
static inline void bg_fp32_matrix3x2_right_product(const BgFP32Matrix3x2* matrix, const BgFP32Vector3* vector, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x2_right_product(const DPMatrix3x2* matrix, const DPVector3* vector, DPVector2* result)
|
||||
static inline void bg_fp64_matrix3x2_right_product(const BgFP64Matrix3x2* matrix, const BgFP64Vector3* vector, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
int sp_matrix3x3_invert(SPMatrix3x3* matrix)
|
||||
int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float determinant = sp_matrix3x3_get_determinant(matrix);
|
||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (-SP_EPSYLON <= determinant && determinant <= SP_EPSYLON) {
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,11 @@ int sp_matrix3x3_invert(SPMatrix3x3* matrix)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int dp_matrix3x3_invert(DPMatrix3x3* matrix)
|
||||
int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double determinant = dp_matrix3x3_get_determinant(matrix);
|
||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (-DP_EPSYLON <= determinant && determinant <= DP_EPSYLON) {
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,11 @@ int dp_matrix3x3_invert(DPMatrix3x3* matrix)
|
|||
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
int sp_matrix3x3_set_inverted(const SPMatrix3x3* matrix, SPMatrix3x3* result)
|
||||
int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result)
|
||||
{
|
||||
const float determinant = sp_matrix3x3_get_determinant(matrix);
|
||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (-SP_EPSYLON <= determinant && determinant <= SP_EPSYLON) {
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -109,11 +109,11 @@ int sp_matrix3x3_set_inverted(const SPMatrix3x3* matrix, SPMatrix3x3* result)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int dp_matrix3x3_set_inverted(const DPMatrix3x3* matrix, DPMatrix3x3* result)
|
||||
int bg_fp64_matrix3x3_set_inverted(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result)
|
||||
{
|
||||
const double determinant = dp_matrix3x3_get_determinant(matrix);
|
||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (-DP_EPSYLON <= determinant && determinant <= DP_EPSYLON) {
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
134
src/matrix3x3.h
134
src/matrix3x3.h
|
@ -6,7 +6,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_matrix3x3_reset(SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_reset(BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -21,7 +21,7 @@ static inline void sp_matrix3x3_reset(SPMatrix3x3* matrix)
|
|||
matrix->r3c3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_reset(DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_reset(BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -38,7 +38,7 @@ static inline void dp_matrix3x3_reset(DPMatrix3x3* matrix)
|
|||
|
||||
// ================== Identity ================== //
|
||||
|
||||
static inline void sp_matrix3x3_make_identity(SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_to_identity(BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -53,7 +53,7 @@ static inline void sp_matrix3x3_make_identity(SPMatrix3x3* matrix)
|
|||
matrix->r3c3 = 1.0f;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_make_identity(DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_to_identity(BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -70,7 +70,7 @@ static inline void dp_matrix3x3_make_identity(DPMatrix3x3* matrix)
|
|||
|
||||
// ================ Make Diagonal =============== //
|
||||
|
||||
static inline void sp_matrix3x3_make_diagonal(const float d1, const float d2, const float d3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_to_diagonal(const float d1, const float d2, const float d3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
@ -85,7 +85,7 @@ static inline void sp_matrix3x3_make_diagonal(const float d1, const float d2, co
|
|||
matrix->r3c3 = d2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_make_diagonal(const double d1, const double d2, const double d3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_to_diagonal(const double d1, const double d2, const double d3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
@ -102,7 +102,7 @@ static inline void dp_matrix3x3_make_diagonal(const double d1, const double d2,
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_matrix3x3_copy(const SPMatrix3x3* from, SPMatrix3x3* to)
|
||||
static inline void bg_fp32_matrix3x3_copy(const BgFP32Matrix3x3* from, BgFP32Matrix3x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -117,7 +117,7 @@ static inline void sp_matrix3x3_copy(const SPMatrix3x3* from, SPMatrix3x3* to)
|
|||
to->r3c3 = from->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_copy(const DPMatrix3x3* from, DPMatrix3x3* to)
|
||||
static inline void bg_fp64_matrix3x3_copy(const BgFP64Matrix3x3* from, BgFP64Matrix3x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -134,22 +134,22 @@ static inline void dp_matrix3x3_copy(const DPMatrix3x3* from, DPMatrix3x3* to)
|
|||
|
||||
// ============= Set from twin type ============= //
|
||||
|
||||
static inline void sp_matrix3x3_set_from_double(const DPMatrix3x3* from, SPMatrix3x3* to)
|
||||
static inline void bg_fp32_matrix3x3_set_from_fp64(const BgFP64Matrix3x3* from, BgFP32Matrix3x3* to)
|
||||
{
|
||||
to->r1c1 = (float)from->r1c1;
|
||||
to->r1c2 = (float)from->r1c2;
|
||||
to->r1c3 = (float)from->r1c3;
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r1c2;
|
||||
to->r1c3 = (float) from->r1c3;
|
||||
|
||||
to->r2c1 = (float)from->r2c1;
|
||||
to->r2c2 = (float)from->r2c2;
|
||||
to->r2c3 = (float)from->r2c3;
|
||||
to->r2c1 = (float) from->r2c1;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
to->r2c3 = (float) from->r2c3;
|
||||
|
||||
to->r3c1 = (float)from->r3c1;
|
||||
to->r3c2 = (float)from->r3c2;
|
||||
to->r3c3 = (float)from->r3c3;
|
||||
to->r3c1 = (float) from->r3c1;
|
||||
to->r3c2 = (float) from->r3c2;
|
||||
to->r3c3 = (float) from->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_from_single(const SPMatrix3x3* from, DPMatrix3x3* to)
|
||||
static inline void bg_fp64_matrix3x3_set_from_fp32(const BgFP32Matrix3x3* from, BgFP64Matrix3x3* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
@ -166,14 +166,14 @@ static inline void dp_matrix3x3_set_from_single(const SPMatrix3x3* from, DPMatri
|
|||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
static inline float sp_matrix3x3_get_determinant(const SPMatrix3x3* matrix)
|
||||
static inline float bg_fp32_matrix3x3_get_determinant(const BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
||||
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
||||
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
|
||||
}
|
||||
|
||||
static inline double dp_matrix3x3_get_determinant(const DPMatrix3x3* matrix)
|
||||
static inline double bg_fp64_matrix3x3_get_determinant(const BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
||||
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
||||
|
@ -182,29 +182,29 @@ static inline double dp_matrix3x3_get_determinant(const DPMatrix3x3* matrix)
|
|||
|
||||
// ================== Singular ================== //
|
||||
|
||||
static inline int sp_matrix3x3_is_singular(const SPMatrix3x3* matrix)
|
||||
static inline int bg_fp32_matrix3x3_is_singular(const BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float determinant = sp_matrix3x3_get_determinant(matrix);
|
||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
||||
|
||||
return -SP_EPSYLON <= determinant && determinant <= SP_EPSYLON;
|
||||
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_matrix3x3_is_singular(const DPMatrix3x3* matrix)
|
||||
static inline int bg_fp64_matrix3x3_is_singular(const BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double determinant = dp_matrix3x3_get_determinant(matrix);
|
||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
||||
|
||||
return -DP_EPSYLON <= determinant && determinant <= DP_EPSYLON;
|
||||
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
int sp_matrix3x3_invert(SPMatrix3x3* matrix);
|
||||
int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix);
|
||||
|
||||
int dp_matrix3x3_invert(DPMatrix3x3* matrix);
|
||||
int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix);
|
||||
|
||||
// =============== Transposition ================ //
|
||||
|
||||
static inline void sp_matrix3x3_transpose(SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_transpose(BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
float tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
|
@ -219,7 +219,7 @@ static inline void sp_matrix3x3_transpose(SPMatrix3x3* matrix)
|
|||
matrix->r3c2 = tmp;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_transpose(DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_transpose(BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
double tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
|
@ -236,16 +236,16 @@ static inline void dp_matrix3x3_transpose(DPMatrix3x3* matrix)
|
|||
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
int sp_matrix3x3_set_inverted(const SPMatrix3x3* matrix, SPMatrix3x3* result);
|
||||
int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result);
|
||||
|
||||
int dp_matrix3x3_set_inverted(const DPMatrix3x3* matrix, DPMatrix3x3* result);
|
||||
int bg_fp64_matrix3x3_set_inverted(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result);
|
||||
|
||||
// =============== Make Transposed ============== //
|
||||
|
||||
static inline void sp_matrix3x3_make_transposed(const SPMatrix3x3* matrix, SPMatrix3x3* result)
|
||||
static inline void bg_fp32_matrix3x3_set_transposed(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
sp_matrix3x3_transpose(result);
|
||||
bg_fp32_matrix3x3_transpose(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -262,10 +262,10 @@ static inline void sp_matrix3x3_make_transposed(const SPMatrix3x3* matrix, SPMat
|
|||
result->r3c3 = matrix->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_make_transposed(const DPMatrix3x3* matrix, DPMatrix3x3* result)
|
||||
static inline void bg_fp64_matrix3x3_set_transposed(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
dp_matrix3x3_transpose(result);
|
||||
bg_fp64_matrix3x3_transpose(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -284,14 +284,14 @@ static inline void dp_matrix3x3_make_transposed(const DPMatrix3x3* matrix, DPMat
|
|||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void sp_matrix3x3_set_row1(const float c1, const float c2, const float c3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_row1(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
matrix->r1c3 = c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_row1(const double c1, const double c2, const double c3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_row1(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
|
@ -300,14 +300,14 @@ static inline void dp_matrix3x3_set_row1(const double c1, const double c2, const
|
|||
|
||||
// ================= Set Row 2 ================== //
|
||||
|
||||
static inline void sp_matrix3x3_set_row2(const float c1, const float c2, const float c3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_row2(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
matrix->r2c3 = c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_row2(const double c1, const double c2, const double c3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_row2(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
|
@ -316,14 +316,14 @@ static inline void dp_matrix3x3_set_row2(const double c1, const double c2, const
|
|||
|
||||
// ================= Set Row 3 ================== //
|
||||
|
||||
static inline void sp_matrix3x3_set_row3(const float c1, const float c2, const float c3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_row3(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r3c1 = c1;
|
||||
matrix->r3c2 = c2;
|
||||
matrix->r3c3 = c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_row3(const double c1, const double c2, const double c3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_row3(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r3c1 = c1;
|
||||
matrix->r3c2 = c2;
|
||||
|
@ -332,14 +332,14 @@ static inline void dp_matrix3x3_set_row3(const double c1, const double c2, const
|
|||
|
||||
// ================ Set Column 1 ================ //
|
||||
|
||||
static inline void sp_matrix3x3_set_column1(const float r1, const float r2, const float r3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_column1(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
matrix->r3c1 = r3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_column1(const double r1, const double r2, const double r3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_column1(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
|
@ -348,14 +348,14 @@ static inline void dp_matrix3x3_set_column1(const double r1, const double r2, co
|
|||
|
||||
// ================ Set Column 2 ================ //
|
||||
|
||||
static inline void sp_matrix3x3_set_column2(const float r1, const float r2, const float r3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_column2(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
matrix->r3c2 = r3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_column2(const double r1, const double r2, const double r3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_column2(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
|
@ -364,14 +364,14 @@ static inline void dp_matrix3x3_set_column2(const double r1, const double r2, co
|
|||
|
||||
// ================ Set Column 3 ================ //
|
||||
|
||||
static inline void sp_matrix3x3_set_column3(const float r1, const float r2, const float r3, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_matrix3x3_set_column3(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c3 = r1;
|
||||
matrix->r2c3 = r2;
|
||||
matrix->r3c3 = r3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_set_column3(const double r1, const double r2, const double r3, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_matrix3x3_set_column3(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
matrix->r1c3 = r1;
|
||||
matrix->r2c3 = r2;
|
||||
|
@ -380,7 +380,7 @@ static inline void dp_matrix3x3_set_column3(const double r1, const double r2, co
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_matrix3x3_append_scaled(SPMatrix3x3* basic_vector, const SPMatrix3x3* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_matrix3x3_append_scaled(BgFP32Matrix3x3* basic_vector, const BgFP32Matrix3x3* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -395,7 +395,7 @@ static inline void sp_matrix3x3_append_scaled(SPMatrix3x3* basic_vector, const S
|
|||
basic_vector->r3c3 += scalable_vector->r3c3 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_append_scaled(DPMatrix3x3* basic_vector, const DPMatrix3x3* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_matrix3x3_append_scaled(BgFP64Matrix3x3* basic_vector, const BgFP64Matrix3x3* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
@ -412,7 +412,7 @@ static inline void dp_matrix3x3_append_scaled(DPMatrix3x3* basic_vector, const D
|
|||
|
||||
// ================== Addition ================== //
|
||||
|
||||
static inline void sp_matrix3x3_add(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* sum)
|
||||
static inline void bg_fp32_matrix3x3_add(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -427,7 +427,7 @@ static inline void sp_matrix3x3_add(const SPMatrix3x3* matrix1, const SPMatrix3x
|
|||
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_add(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* sum)
|
||||
static inline void bg_fp64_matrix3x3_add(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
@ -444,7 +444,7 @@ static inline void dp_matrix3x3_add(const DPMatrix3x3* matrix1, const DPMatrix3x
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_matrix3x3_subtract(const SPMatrix3x3* minuend, const SPMatrix3x3* subtrahend, SPMatrix3x3* difference)
|
||||
static inline void bg_fp32_matrix3x3_subtract(const BgFP32Matrix3x3* minuend, const BgFP32Matrix3x3* subtrahend, BgFP32Matrix3x3* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -459,7 +459,7 @@ static inline void sp_matrix3x3_subtract(const SPMatrix3x3* minuend, const SPMat
|
|||
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_subtract(const DPMatrix3x3* minuend, const DPMatrix3x3* subtrahend, DPMatrix3x3* difference)
|
||||
static inline void bg_fp64_matrix3x3_subtract(const BgFP64Matrix3x3* minuend, const BgFP64Matrix3x3* subtrahend, BgFP64Matrix3x3* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
@ -476,7 +476,7 @@ static inline void dp_matrix3x3_subtract(const DPMatrix3x3* minuend, const DPMat
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_matrix3x3_multiply(const SPMatrix3x3* multiplicand, const float multiplier, SPMatrix3x3* product)
|
||||
static inline void bg_fp32_matrix3x3_multiply(const BgFP32Matrix3x3* multiplicand, const float multiplier, BgFP32Matrix3x3* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -491,7 +491,7 @@ static inline void sp_matrix3x3_multiply(const SPMatrix3x3* multiplicand, const
|
|||
product->r3c3 = multiplicand->r3c3 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_multiply(const DPMatrix3x3* multiplicand, const double multiplier, DPMatrix3x3* product)
|
||||
static inline void bg_fp64_matrix3x3_multiply(const BgFP64Matrix3x3* multiplicand, const double multiplier, BgFP64Matrix3x3* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
@ -508,7 +508,7 @@ static inline void dp_matrix3x3_multiply(const DPMatrix3x3* multiplicand, const
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_matrix3x3_divide(const SPMatrix3x3* dividend, const float divisor, SPMatrix3x3* quotient)
|
||||
static inline void bg_fp32_matrix3x3_divide(const BgFP32Matrix3x3* dividend, const float divisor, BgFP32Matrix3x3* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -523,7 +523,7 @@ static inline void sp_matrix3x3_divide(const SPMatrix3x3* dividend, const float
|
|||
quotient->r3c3 = dividend->r3c3 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_divide(const DPMatrix3x3* dividend, const double divisor, DPMatrix3x3* quotient)
|
||||
static inline void bg_fp64_matrix3x3_divide(const BgFP64Matrix3x3* dividend, const double divisor, BgFP64Matrix3x3* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
@ -540,9 +540,9 @@ static inline void dp_matrix3x3_divide(const DPMatrix3x3* dividend, const double
|
|||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void sp_matrix3x3_left_product(const SPVector3* vector, const SPMatrix3x3* matrix, SPVector3* result)
|
||||
static inline void bg_fp32_matrix3x3_left_product(const BgFP32Vector3* vector, const BgFP32Matrix3x3* matrix, BgFP32Vector3* result)
|
||||
{
|
||||
sp_vector3_set_values(
|
||||
bg_fp32_vector3_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2,
|
||||
vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3,
|
||||
|
@ -550,9 +550,9 @@ static inline void sp_matrix3x3_left_product(const SPVector3* vector, const SPMa
|
|||
);
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_left_product(const DPVector3* vector, const DPMatrix3x3* matrix, DPVector3* result)
|
||||
static inline void bg_fp64_matrix3x3_left_product(const BgFP64Vector3* vector, const BgFP64Matrix3x3* matrix, BgFP64Vector3* result)
|
||||
{
|
||||
dp_vector3_set_values(
|
||||
bg_fp64_vector3_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2,
|
||||
vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3,
|
||||
|
@ -562,9 +562,9 @@ static inline void dp_matrix3x3_left_product(const DPVector3* vector, const DPMa
|
|||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void sp_matrix3x3_right_product(const SPMatrix3x3* matrix, const SPVector3* vector, SPVector3* result)
|
||||
static inline void bg_fp32_matrix3x3_right_product(const BgFP32Matrix3x3* matrix, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
sp_vector3_set_values(
|
||||
bg_fp32_vector3_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3,
|
||||
matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3,
|
||||
|
@ -572,9 +572,9 @@ static inline void sp_matrix3x3_right_product(const SPMatrix3x3* matrix, const S
|
|||
);
|
||||
}
|
||||
|
||||
static inline void dp_matrix3x3_right_product(const DPMatrix3x3* matrix, const DPVector3* vector, DPVector3* result)
|
||||
static inline void bg_fp64_matrix3x3_right_product(const BgFP64Matrix3x3* matrix, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
dp_vector3_set_values(
|
||||
bg_fp64_vector3_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3,
|
||||
matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// ========== Matrix Product 2x2 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x2_at_3x2(const SPMatrix2x2* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x2* result)
|
||||
void bg_fp32_matrix_product_2x2_at_3x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -21,7 +21,7 @@ void sp_matrix_product_2x2_at_3x2(const SPMatrix2x2* matrix1, const SPMatrix3x2*
|
|||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x2_at_3x2(const DPMatrix2x2* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x2* result)
|
||||
void bg_fp64_matrix_product_2x2_at_3x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -42,7 +42,7 @@ void dp_matrix_product_2x2_at_3x2(const DPMatrix2x2* matrix1, const DPMatrix3x2*
|
|||
|
||||
// ========== Matrix Product 2x3 at 2x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_2x2(const SPMatrix2x3* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x3* result)
|
||||
void bg_fp32_matrix_product_2x3_at_2x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x3* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -63,7 +63,7 @@ void sp_matrix_product_2x3_at_2x2(const SPMatrix2x3* matrix1, const SPMatrix2x2*
|
|||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x3_at_2x2(const DPMatrix2x3* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x3* result)
|
||||
void bg_fp64_matrix_product_2x3_at_2x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -86,7 +86,7 @@ void dp_matrix_product_2x3_at_2x2(const DPMatrix2x3* matrix1, const DPMatrix2x2*
|
|||
|
||||
// ========== Matrix Product 2x3 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_3x2(const SPMatrix2x3* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x3* result)
|
||||
void bg_fp32_matrix_product_2x3_at_3x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x3* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -101,7 +101,7 @@ void sp_matrix_product_2x3_at_3x2(const SPMatrix2x3* matrix1, const SPMatrix3x2*
|
|||
result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x3* result)
|
||||
void bg_fp64_matrix_product_2x3_at_3x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x3* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -118,7 +118,7 @@ void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2*
|
|||
|
||||
// ========== Matrix Product 3x2 at 2x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x2* result)
|
||||
void bg_fp32_matrix_product_3x2_at_2x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x2* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -127,7 +127,7 @@ void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3*
|
|||
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x2_at_2x3(const DPMatrix3x2* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x2* result)
|
||||
void bg_fp64_matrix_product_3x2_at_2x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x2* result)
|
||||
{
|
||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -138,7 +138,7 @@ void dp_matrix_product_3x2_at_2x3(const DPMatrix3x2* matrix1, const DPMatrix2x3*
|
|||
|
||||
// ========== Matrix Product 3x2 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x2_at_3x3(const SPMatrix3x2* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x2* result)
|
||||
void bg_fp32_matrix_product_3x2_at_3x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x2* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -157,7 +157,7 @@ void sp_matrix_product_3x2_at_3x3(const SPMatrix3x2* matrix1, const SPMatrix3x3*
|
|||
result->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x2_at_3x3(const DPMatrix3x2* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x2* result)
|
||||
void bg_fp64_matrix_product_3x2_at_3x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x2* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -178,7 +178,7 @@ void dp_matrix_product_3x2_at_3x3(const DPMatrix3x2* matrix1, const DPMatrix3x3*
|
|||
|
||||
// ========== Matrix Product 3x3 at 2x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_2x3(const SPMatrix3x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* result)
|
||||
void bg_fp32_matrix_product_3x3_at_2x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -199,7 +199,7 @@ void sp_matrix_product_3x3_at_2x3(const SPMatrix3x3* matrix1, const SPMatrix2x3*
|
|||
result->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x3_at_2x3(const DPMatrix3x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* result)
|
||||
void bg_fp64_matrix_product_3x3_at_2x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -222,7 +222,7 @@ void dp_matrix_product_3x3_at_2x3(const DPMatrix3x3* matrix1, const DPMatrix2x3*
|
|||
|
||||
// ========== Matrix Product 3x3 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_3x3(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result)
|
||||
void bg_fp32_matrix_product_3x3_at_3x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
@ -249,7 +249,7 @@ void sp_matrix_product_3x3_at_3x3(const SPMatrix3x3* matrix1, const SPMatrix3x3*
|
|||
result->r3c3 = r3c3;
|
||||
}
|
||||
|
||||
void dp_matrix_product_3x3_at_3x3(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result)
|
||||
void bg_fp64_matrix_product_3x3_at_3x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
typedef struct {
|
||||
float r1c1, r1c2;
|
||||
float r2c1, r2c2;
|
||||
} SPMatrix2x2;
|
||||
} BgFP32Matrix2x2;
|
||||
|
||||
typedef struct {
|
||||
double r1c1, r1c2;
|
||||
double r2c1, r2c2;
|
||||
} DPMatrix2x2;
|
||||
} BgFP64Matrix2x2;
|
||||
|
||||
// ================== Matrix2x3 ================= //
|
||||
|
||||
|
@ -19,25 +19,25 @@ typedef struct {
|
|||
float r1c1, r1c2;
|
||||
float r2c1, r2c2;
|
||||
float r3c1, r3c2;
|
||||
} SPMatrix2x3;
|
||||
} BgFP32Matrix2x3;
|
||||
|
||||
typedef struct {
|
||||
double r1c1, r1c2;
|
||||
double r2c1, r2c2;
|
||||
double r3c1, r3c2;
|
||||
} DPMatrix2x3;
|
||||
} BgFP64Matrix2x3;
|
||||
|
||||
// ================== Matrix3x2 ================= //
|
||||
|
||||
typedef struct {
|
||||
float r1c1, r1c2, r1c3;
|
||||
float r2c1, r2c2, r2c3;
|
||||
} SPMatrix3x2;
|
||||
} BgFP32Matrix3x2;
|
||||
|
||||
typedef struct {
|
||||
double r1c1, r1c2, r1c3;
|
||||
double r2c1, r2c2, r2c3;
|
||||
} DPMatrix3x2;
|
||||
} BgFP64Matrix3x2;
|
||||
|
||||
// ================== Matrix3x3 ================= //
|
||||
|
||||
|
@ -45,17 +45,17 @@ typedef struct {
|
|||
float r1c1, r1c2, r1c3;
|
||||
float r2c1, r2c2, r2c3;
|
||||
float r3c1, r3c2, r3c3;
|
||||
} SPMatrix3x3;
|
||||
} BgFP32Matrix3x3;
|
||||
|
||||
typedef struct {
|
||||
double r1c1, r1c2, r1c3;
|
||||
double r2c1, r2c2, r2c3;
|
||||
double r3c1, r3c2, r3c3;
|
||||
} DPMatrix3x3;
|
||||
} BgFP64Matrix3x3;
|
||||
|
||||
// ========== Matrix Product 2x2 at 2x2 ========= //
|
||||
|
||||
static inline void sp_matrix_product_2x2_at_2x2(const SPMatrix2x2* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x2* result)
|
||||
static inline void bg_fp32_matrix_product_2x2_at_2x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x2* result)
|
||||
{
|
||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -70,7 +70,7 @@ static inline void sp_matrix_product_2x2_at_2x2(const SPMatrix2x2* matrix1, cons
|
|||
result->r2c2 = r2c2;
|
||||
}
|
||||
|
||||
static inline void dp_matrix_product_2x2_at_2x2(const DPMatrix2x2* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x2* result)
|
||||
static inline void bg_fp64_matrix_product_2x2_at_2x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x2* result)
|
||||
{
|
||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||
|
@ -87,44 +87,44 @@ static inline void dp_matrix_product_2x2_at_2x2(const DPMatrix2x2* matrix1, cons
|
|||
|
||||
// ========== Matrix Product 2x2 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x2_at_3x2(const SPMatrix2x2* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x2* result);
|
||||
void bg_fp32_matrix_product_2x2_at_3x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* result);
|
||||
|
||||
void dp_matrix_product_2x2_at_3x2(const DPMatrix2x2* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x2* result);
|
||||
void bg_fp64_matrix_product_2x2_at_3x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* result);
|
||||
|
||||
// ========== Matrix Product 2x3 at 2x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_2x2(const SPMatrix2x3* matrix1, const SPMatrix2x2* matrix2, SPMatrix2x3* result);
|
||||
void bg_fp32_matrix_product_2x3_at_2x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x3* result);
|
||||
|
||||
void dp_matrix_product_2x3_at_2x2(const DPMatrix2x3* matrix1, const DPMatrix2x2* matrix2, DPMatrix2x3* result);
|
||||
void bg_fp64_matrix_product_2x3_at_2x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x3* result);
|
||||
|
||||
// ========== Matrix Product 2x3 at 3x2 ========= //
|
||||
|
||||
void sp_matrix_product_2x3_at_3x2(const SPMatrix2x3* matrix1, const SPMatrix3x2* matrix2, SPMatrix3x3* result);
|
||||
void bg_fp32_matrix_product_2x3_at_3x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x3* result);
|
||||
|
||||
void dp_matrix_product_2x3_at_3x2(const DPMatrix2x3* matrix1, const DPMatrix3x2* matrix2, DPMatrix3x3* result);
|
||||
void bg_fp64_matrix_product_2x3_at_3x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x3* result);
|
||||
|
||||
// ========== Matrix Product 3x2 at 2x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x2_at_2x3(const SPMatrix3x2* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x2* result);
|
||||
void bg_fp32_matrix_product_3x2_at_2x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x2* result);
|
||||
|
||||
void dp_matrix_product_3x2_at_2x3(const DPMatrix3x2* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x2* result);
|
||||
void bg_fp64_matrix_product_3x2_at_2x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x2* result);
|
||||
|
||||
// ========== Matrix Product 3x2 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x2_at_3x3(const SPMatrix3x2* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x2* result);
|
||||
void bg_fp32_matrix_product_3x2_at_3x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x2* result);
|
||||
|
||||
void dp_matrix_product_3x2_at_3x3(const DPMatrix3x2* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x2* result);
|
||||
void bg_fp64_matrix_product_3x2_at_3x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x2* result);
|
||||
|
||||
// ========== Matrix Product 3x3 at 2x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_2x3(const SPMatrix3x3* matrix1, const SPMatrix2x3* matrix2, SPMatrix2x3* result);
|
||||
void bg_fp32_matrix_product_3x3_at_2x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* result);
|
||||
|
||||
void dp_matrix_product_3x3_at_2x3(const DPMatrix3x3* matrix1, const DPMatrix2x3* matrix2, DPMatrix2x3* result);
|
||||
void bg_fp64_matrix_product_3x3_at_2x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* result);
|
||||
|
||||
// ========== Matrix Product 3x3 at 3x3 ========= //
|
||||
|
||||
void sp_matrix_product_3x3_at_3x3(const SPMatrix3x3* matrix1, const SPMatrix3x3* matrix2, SPMatrix3x3* result);
|
||||
void bg_fp32_matrix_product_3x3_at_3x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* result);
|
||||
|
||||
void dp_matrix_product_3x3_at_3x3(const DPMatrix3x3* matrix1, const DPMatrix3x3* matrix2, DPMatrix3x3* result);
|
||||
void bg_fp64_matrix_product_3x3_at_3x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* result);
|
||||
|
||||
#endif // _GEOMETRY_MATRIX_TYPES_H_
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// ============ Make Rotation Matrix ============ //
|
||||
|
||||
void sp_quaternion_make_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matrix)
|
||||
void bg_fp32_quaternion_make_rotation_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -11,9 +11,9 @@ void sp_quaternion_make_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matr
|
|||
|
||||
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-SP_EPSYLON <= square_module && square_module <= SP_EPSYLON)
|
||||
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
|
||||
{
|
||||
sp_matrix3x3_make_identity(matrix);
|
||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ void sp_quaternion_make_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matr
|
|||
matrix->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||
}
|
||||
|
||||
void dp_quaternion_make_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matrix)
|
||||
void bg_fp64_quaternion_make_rotation_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -49,9 +49,9 @@ void dp_quaternion_make_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matr
|
|||
|
||||
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-DP_EPSYLON <= square_module && square_module <= DP_EPSYLON)
|
||||
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
|
||||
{
|
||||
dp_matrix3x3_make_identity(matrix);
|
||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ void dp_quaternion_make_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matr
|
|||
|
||||
// ============ Make Reverse Matrix ============= //
|
||||
|
||||
void sp_quaternion_make_reverse_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matrix)
|
||||
void bg_fp32_quaternion_make_reverse_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -89,9 +89,9 @@ void sp_quaternion_make_reverse_matrix(const SPQuaternion* quaternion, SPMatrix3
|
|||
|
||||
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-SP_EPSYLON <= square_module && square_module <= SP_EPSYLON)
|
||||
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON)
|
||||
{
|
||||
sp_matrix3x3_make_identity(matrix);
|
||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ void sp_quaternion_make_reverse_matrix(const SPQuaternion* quaternion, SPMatrix3
|
|||
matrix->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
}
|
||||
|
||||
void dp_quaternion_make_reverse_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matrix)
|
||||
void bg_fp64_quaternion_make_reverse_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -127,9 +127,9 @@ void dp_quaternion_make_reverse_matrix(const DPQuaternion* quaternion, DPMatrix3
|
|||
|
||||
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-DP_EPSYLON <= square_module && square_module <= DP_EPSYLON)
|
||||
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON)
|
||||
{
|
||||
dp_matrix3x3_make_identity(matrix);
|
||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,15 +8,15 @@
|
|||
|
||||
typedef struct {
|
||||
float s0, x1, x2, x3;
|
||||
} SPQuaternion;
|
||||
} BgFP32Quaternion;
|
||||
|
||||
typedef struct {
|
||||
double s0, x1, x2, x3;
|
||||
} DPQuaternion;
|
||||
} BgFP64Quaternion;
|
||||
|
||||
// ==================== Reset =================== //
|
||||
|
||||
static inline void sp_quaternion_reset(SPQuaternion * quaternion)
|
||||
static inline void bg_fp32_quaternion_reset(BgFP32Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 0.0f;
|
||||
quaternion->x1 = 0.0f;
|
||||
|
@ -24,7 +24,7 @@ static inline void sp_quaternion_reset(SPQuaternion * quaternion)
|
|||
quaternion->x3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_reset(DPQuaternion * quaternion)
|
||||
static inline void bg_fp64_quaternion_reset(BgFP64Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 0.0;
|
||||
quaternion->x1 = 0.0;
|
||||
|
@ -34,7 +34,7 @@ static inline void dp_quaternion_reset(DPQuaternion * quaternion)
|
|||
|
||||
// ================== Set Unit ================== //
|
||||
|
||||
static inline void sp_quaternion_set_identity(SPQuaternion * quaternion)
|
||||
static inline void bg_fp32_quaternion_set_identity(BgFP32Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0f;
|
||||
quaternion->x1 = 0.0f;
|
||||
|
@ -42,7 +42,7 @@ static inline void sp_quaternion_set_identity(SPQuaternion * quaternion)
|
|||
quaternion->x3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_set_identity(DPQuaternion * quaternion)
|
||||
static inline void bg_fp64_quaternion_set_identity(BgFP64Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = 1.0;
|
||||
quaternion->x1 = 0.0;
|
||||
|
@ -52,7 +52,7 @@ static inline void dp_quaternion_set_identity(DPQuaternion * quaternion)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_quaternion_set_values(const float s0, const float x1, const float x2, const float x3, SPQuaternion * quaternion)
|
||||
static inline void bg_fp32_quaternion_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = s0;
|
||||
quaternion->x1 = x1;
|
||||
|
@ -60,7 +60,7 @@ static inline void sp_quaternion_set_values(const float s0, const float x1, cons
|
|||
quaternion->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_set_values(const double s0, const double x1, const double x2, const double x3, DPQuaternion * quaternion)
|
||||
static inline void bg_fp64_quaternion_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Quaternion * quaternion)
|
||||
{
|
||||
quaternion->s0 = s0;
|
||||
quaternion->x1 = x1;
|
||||
|
@ -70,7 +70,7 @@ static inline void dp_quaternion_set_values(const double s0, const double x1, co
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_quaternion_copy(const SPQuaternion* from, SPQuaternion* to)
|
||||
static inline void bg_fp32_quaternion_copy(const BgFP32Quaternion* from, BgFP32Quaternion* to)
|
||||
{
|
||||
to->s0 = from->s0;
|
||||
to->x1 = from->x1;
|
||||
|
@ -78,7 +78,7 @@ static inline void sp_quaternion_copy(const SPQuaternion* from, SPQuaternion* to
|
|||
to->x3 = from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_copy(const DPQuaternion* from, DPQuaternion* to)
|
||||
static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Quaternion* to)
|
||||
{
|
||||
to->s0 = from->s0;
|
||||
to->x1 = from->x1;
|
||||
|
@ -88,15 +88,15 @@ static inline void dp_quaternion_copy(const DPQuaternion* from, DPQuaternion* to
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_quaternion_copy_from_double(const DPQuaternion* versor, SPQuaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = (float)versor->s0;
|
||||
result->x1 = (float)versor->x1;
|
||||
result->x2 = (float)versor->x2;
|
||||
result->x3 = (float)versor->x3;
|
||||
result->s0 = (float) versor->s0;
|
||||
result->x1 = (float) versor->x1;
|
||||
result->x2 = (float) versor->x2;
|
||||
result->x3 = (float) versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_copy_from_single(const SPQuaternion* versor, DPQuaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = versor->x1;
|
||||
|
@ -106,14 +106,14 @@ static inline void dp_quaternion_copy_from_single(const SPQuaternion* versor, DP
|
|||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_quaternion_conjugate(SPQuaternion* versor)
|
||||
static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* versor)
|
||||
{
|
||||
versor->x1 = -versor->x1;
|
||||
versor->x2 = -versor->x2;
|
||||
versor->x3 = -versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_conjugate(DPQuaternion* versor)
|
||||
static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* versor)
|
||||
{
|
||||
versor->x1 = -versor->x1;
|
||||
versor->x2 = -versor->x2;
|
||||
|
@ -122,7 +122,7 @@ static inline void dp_quaternion_conjugate(DPQuaternion* versor)
|
|||
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
static inline void sp_quaternion_set_conjugate(const SPQuaternion* versor, SPQuaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* versor, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
|
@ -130,7 +130,7 @@ static inline void sp_quaternion_set_conjugate(const SPQuaternion* versor, SPQua
|
|||
result->x3 = -versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_set_conjugate(const DPQuaternion* versor, DPQuaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* versor, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
|
@ -140,15 +140,15 @@ static inline void dp_quaternion_set_conjugate(const DPQuaternion* versor, DPQua
|
|||
|
||||
// ================ Get Inverted ================ //
|
||||
|
||||
static inline void sp_quaternion_conjugate_double(const DPQuaternion* versor, SPQuaternion* result)
|
||||
static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result)
|
||||
{
|
||||
result->s0 = (float)versor->s0;
|
||||
result->x1 = -(float)versor->x1;
|
||||
result->x2 = -(float)versor->x2;
|
||||
result->x3 = -(float)versor->x3;
|
||||
result->s0 = (float) versor->s0;
|
||||
result->x1 = (float) -versor->x1;
|
||||
result->x2 = (float) -versor->x2;
|
||||
result->x3 = (float) -versor->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_conjugate_single(const SPQuaternion* versor, DPQuaternion* result)
|
||||
static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result)
|
||||
{
|
||||
result->s0 = versor->s0;
|
||||
result->x1 = -versor->x1;
|
||||
|
@ -158,19 +158,19 @@ static inline void dp_quaternion_conjugate_single(const SPQuaternion* versor, DP
|
|||
|
||||
// ============ Make Rotation Matrix ============ //
|
||||
|
||||
void sp_quaternion_make_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matrix);
|
||||
void bg_fp32_quaternion_make_rotation_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix);
|
||||
|
||||
void dp_quaternion_make_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matrix);
|
||||
void bg_fp64_quaternion_make_rotation_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix);
|
||||
|
||||
// ============ Make Reverse Matrix ============= //
|
||||
|
||||
void sp_quaternion_make_reverse_matrix(const SPQuaternion* quaternion, SPMatrix3x3* matrix);
|
||||
void bg_fp32_quaternion_make_reverse_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix);
|
||||
|
||||
void dp_quaternion_make_reverse_matrix(const DPQuaternion* quaternion, DPMatrix3x3* matrix);
|
||||
void bg_fp64_quaternion_make_reverse_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix);
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_quaternion_add(const SPQuaternion * quaternion1, const SPQuaternion * quaternion2, SPQuaternion * result)
|
||||
static inline void bg_fp32_quaternion_add(const BgFP32Quaternion * quaternion1, const BgFP32Quaternion * quaternion2, BgFP32Quaternion * result)
|
||||
{
|
||||
result->s0 = quaternion1->s0 + quaternion2->s0;
|
||||
result->x1 = quaternion1->x1 + quaternion2->x1;
|
||||
|
@ -178,7 +178,7 @@ static inline void sp_quaternion_add(const SPQuaternion * quaternion1, const SPQ
|
|||
result->x3 = quaternion1->x3 + quaternion2->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_add(const DPQuaternion * quaternion1, const DPQuaternion * quaternion2, DPQuaternion * result)
|
||||
static inline void bg_fp64_quaternion_add(const BgFP64Quaternion * quaternion1, const BgFP64Quaternion * quaternion2, BgFP64Quaternion * result)
|
||||
{
|
||||
result->s0 = quaternion1->s0 + quaternion2->s0;
|
||||
result->x1 = quaternion1->x1 + quaternion2->x1;
|
||||
|
@ -188,7 +188,7 @@ static inline void dp_quaternion_add(const DPQuaternion * quaternion1, const DPQ
|
|||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
static inline void sp_quaternion_subtract(const SPQuaternion * minuend, const SPQuaternion * subtrahend, SPQuaternion * result)
|
||||
static inline void bg_fp32_quaternion_subtract(const BgFP32Quaternion * minuend, const BgFP32Quaternion * subtrahend, BgFP32Quaternion * result)
|
||||
{
|
||||
result->s0 = minuend->s0 - subtrahend->s0;
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
|
@ -196,7 +196,7 @@ static inline void sp_quaternion_subtract(const SPQuaternion * minuend, const SP
|
|||
result->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_subtract(const DPQuaternion * minuend, const DPQuaternion * subtrahend, DPQuaternion * result)
|
||||
static inline void bg_fp64_quaternion_subtract(const BgFP64Quaternion * minuend, const BgFP64Quaternion * subtrahend, BgFP64Quaternion * result)
|
||||
{
|
||||
result->s0 = minuend->s0 - subtrahend->s0;
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
|
@ -206,7 +206,7 @@ static inline void dp_quaternion_subtract(const DPQuaternion * minuend, const DP
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_quaternion_multiply(const SPQuaternion* left, const SPQuaternion* right, SPQuaternion* result)
|
||||
static inline void bg_fp32_quaternion_multiply(const BgFP32Quaternion* left, const BgFP32Quaternion* right, BgFP32Quaternion* result)
|
||||
{
|
||||
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
|
@ -219,7 +219,7 @@ static inline void sp_quaternion_multiply(const SPQuaternion* left, const SPQuat
|
|||
result->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_quaternion_multiply(const DPQuaternion* left, const DPQuaternion* right, DPQuaternion* result)
|
||||
static inline void bg_fp64_quaternion_multiply(const BgFP64Quaternion* left, const BgFP64Quaternion* right, BgFP64Quaternion* result)
|
||||
{
|
||||
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "rotation3.h"
|
||||
|
||||
const SPRotation3 SP_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f};
|
||||
const BgFP32Rotation3 BG_FP32_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f};
|
||||
|
||||
const DPRotation3 DP_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0};
|
||||
const BgFP64Rotation3 BG_FP64_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0};
|
||||
|
|
|
@ -6,22 +6,22 @@
|
|||
#include "vector3.h"
|
||||
|
||||
typedef struct {
|
||||
SPVector3 axis;
|
||||
BgFP32Vector3 axis;
|
||||
float radians;
|
||||
} SPRotation3;
|
||||
} BgFP32Rotation3;
|
||||
|
||||
typedef struct {
|
||||
DPVector3 axis;
|
||||
BgFP64Vector3 axis;
|
||||
double radians;
|
||||
} DPRotation3;
|
||||
} BgFP64Rotation3;
|
||||
|
||||
extern const SPRotation3 SP_IDLE_ROTATION3;
|
||||
extern const BgFP32Rotation3 BG_FP32_IDLE_ROTATION3;
|
||||
|
||||
extern const DPRotation3 DP_IDLE_ROTATION3;
|
||||
extern const BgFP64Rotation3 BG_FP64_IDLE_ROTATION3;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_rotation_reset(SPRotation3* rotation)
|
||||
static inline void bg_fp32_rotation_reset(BgFP32Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = 0.0f;
|
||||
rotation->axis.x2 = 0.0f;
|
||||
|
@ -30,7 +30,7 @@ static inline void sp_rotation_reset(SPRotation3* rotation)
|
|||
rotation->radians = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_rotation_reset(DPRotation3* rotation)
|
||||
static inline void bg_fp64_rotation_reset(BgFP64Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = 0.0;
|
||||
rotation->axis.x2 = 0.0;
|
||||
|
@ -41,14 +41,14 @@ static inline void dp_rotation_reset(DPRotation3* rotation)
|
|||
|
||||
// ==================== Make ==================== //
|
||||
|
||||
static inline void sp_rotation_make(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, SPRotation3* rotation)
|
||||
static inline void bg_fp32_rotation_set_values(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = x1;
|
||||
rotation->axis.x2 = x2;
|
||||
rotation->axis.x3 = x3;
|
||||
|
||||
if (sp_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = sp_convert_to_radians(angle, unit);
|
||||
if (bg_fp32_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bg_fp32_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0f;
|
||||
|
@ -56,42 +56,42 @@ static inline void sp_rotation_make(const float x1, const float x2, const float
|
|||
}
|
||||
|
||||
|
||||
static inline void dp_rotation_make(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, DPRotation3* rotation)
|
||||
static inline void bg_fp64_rotation_set_values(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = x1;
|
||||
rotation->axis.x2 = x2;
|
||||
rotation->axis.x3 = x3;
|
||||
|
||||
if (dp_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = dp_convert_to_radians(angle, unit);
|
||||
if (bg_fp64_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bg_fp64_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void sp_rotation_make_with_vector(const SPVector3* axis, const float angle, const angle_unit_t unit, SPRotation3* rotation)
|
||||
static inline void bg_fp32_rotation_set_with_axis(const BgFP32Vector3* axis, const float angle, const angle_unit_t unit, BgFP32Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = axis->x1;
|
||||
rotation->axis.x2 = axis->x2;
|
||||
rotation->axis.x3 = axis->x3;
|
||||
|
||||
if (sp_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = sp_convert_to_radians(angle, unit);
|
||||
if (bg_fp32_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bg_fp32_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dp_rotation_make_with_vector(const DPVector3* axis, const double angle, const angle_unit_t unit, DPRotation3* rotation)
|
||||
static inline void bg_fp64_rotation_set_with_axis(const BgFP64Vector3* axis, const double angle, const angle_unit_t unit, BgFP64Rotation3* rotation)
|
||||
{
|
||||
rotation->axis.x1 = axis->x1;
|
||||
rotation->axis.x2 = axis->x2;
|
||||
rotation->axis.x3 = axis->x3;
|
||||
|
||||
if (dp_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = dp_convert_to_radians(angle, unit);
|
||||
if (bg_fp64_vector3_normalize(&rotation->axis)) {
|
||||
rotation->radians = bg_fp64_angle_to_radians(angle, unit);
|
||||
}
|
||||
else {
|
||||
rotation->radians = 0.0;
|
||||
|
|
|
@ -2,64 +2,64 @@
|
|||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float sp_vector2_angle(const SPVector2* vector1, const SPVector2* vector2, const angle_unit_t unit)
|
||||
float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const angle_unit_t unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module1 = sp_vector2_get_square_module(vector1);
|
||||
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
|
||||
|
||||
if (square_module1 <= SP_SQUARE_EPSYLON) {
|
||||
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module2 = sp_vector2_get_square_module(vector2);
|
||||
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
|
||||
|
||||
if (square_module2 <= SP_SQUARE_EPSYLON) {
|
||||
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float cosine = sp_vector2_scalar(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
const float cosine = bg_fp32_vector2_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
|
||||
if (cosine >= 1.0f - SP_EPSYLON) {
|
||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (cosine <= -1.0f + SP_EPSYLON) {
|
||||
return sp_get_half_circle(unit);
|
||||
if (cosine <= -1.0f + BG_FP32_EPSYLON) {
|
||||
return bg_fp32_angle_get_half_circle(unit);
|
||||
}
|
||||
|
||||
return sp_convert_from_radians(acosf(cosine), unit);
|
||||
return bg_fp32_radians_to_units(acosf(cosine), unit);
|
||||
}
|
||||
|
||||
double dp_vector2_angle(const DPVector2* vector1, const DPVector2* vector2, const angle_unit_t unit)
|
||||
double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const angle_unit_t unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module1 = dp_vector2_get_square_module(vector1);
|
||||
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
|
||||
|
||||
if (square_module1 <= DP_SQUARE_EPSYLON) {
|
||||
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module2 = dp_vector2_get_square_module(vector2);
|
||||
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
|
||||
|
||||
if (square_module2 <= DP_SQUARE_EPSYLON) {
|
||||
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double cosine = dp_vector2_scalar(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
const double cosine = bg_fp64_vector2_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
|
||||
if (cosine >= 1.0 - DP_EPSYLON) {
|
||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (cosine <= -1.0 + DP_EPSYLON) {
|
||||
return dp_get_half_circle(unit);
|
||||
if (cosine <= -1.0 + BG_FP64_EPSYLON) {
|
||||
return bg_fp64_angle_get_half_circle(unit);
|
||||
}
|
||||
|
||||
return dp_convert_from_radians(acos(cosine), unit);
|
||||
return bg_fp64_radians_to_units(acos(cosine), unit);
|
||||
}
|
||||
|
|
192
src/vector2.h
192
src/vector2.h
|
@ -9,22 +9,22 @@
|
|||
typedef struct
|
||||
{
|
||||
float x1, x2;
|
||||
} SPVector2;
|
||||
} BgFP32Vector2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2;
|
||||
} DPVector2;
|
||||
} BgFP64Vector2;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_vector2_reset(SPVector2* vector)
|
||||
static inline void bg_fp32_vector2_reset(BgFP32Vector2* vector)
|
||||
{
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reset(DPVector2* vector)
|
||||
static inline void bg_fp64_vector2_reset(BgFP64Vector2* vector)
|
||||
{
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
|
@ -32,13 +32,13 @@ static inline void dp_vector2_reset(DPVector2* vector)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_vector2_set_values(const float x1, const float x2, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_values(const float x1, const float x2, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_set_values(const double x1, const double x2, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_values(const double x1, const double x2, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
|
@ -46,13 +46,13 @@ static inline void dp_vector2_set_values(const double x1, const double x2, DPVec
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_vector2_copy(const SPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_copy(const BgFP32Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_copy(const DPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_copy(const BgFP64Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -60,13 +60,13 @@ static inline void dp_vector2_copy(const DPVector2* from, DPVector2* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector2_copy_from_double(const DPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_from_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_copy_from_single(const SPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_from_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -74,13 +74,13 @@ static inline void dp_vector2_copy_from_single(const SPVector2* from, DPVector2*
|
|||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
static inline void sp_vector2_reverse(const SPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_reverse(const BgFP32Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse(const DPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_reverse(const BgFP64Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -88,13 +88,13 @@ static inline void dp_vector2_reverse(const DPVector2* from, DPVector2* to)
|
|||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
static inline void sp_vector2_reverse_double(const DPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_reverse_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = -(float)from->x1;
|
||||
to->x2 = -(float)from->x2;
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse_single(const SPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -102,61 +102,61 @@ static inline void dp_vector2_reverse_single(const SPVector2* from, DPVector2* t
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
static inline float sp_vector2_get_square_module(const SPVector2* vector)
|
||||
static inline float bg_fp32_vector2_get_square_module(const BgFP32Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_square_module(const DPVector2* vector)
|
||||
static inline double bg_fp64_vector2_get_square_module(const BgFP64Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline float sp_vector2_get_module(const SPVector2* vector)
|
||||
static inline float bg_fp32_vector2_get_module(const BgFP32Vector2* vector)
|
||||
{
|
||||
return sqrtf(sp_vector2_get_square_module(vector));
|
||||
return sqrtf(bg_fp32_vector2_get_square_module(vector));
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_module(const DPVector2* vector)
|
||||
static inline double bg_fp64_vector2_get_module(const BgFP64Vector2* vector)
|
||||
{
|
||||
return sqrt(dp_vector2_get_square_module(vector));
|
||||
return sqrt(bg_fp64_vector2_get_square_module(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int sp_vector2_is_zero(const SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
|
||||
{
|
||||
return sp_vector2_get_square_module(vector) <= SP_SQUARE_EPSYLON;
|
||||
return bg_fp32_vector2_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_is_zero(const DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
|
||||
{
|
||||
return dp_vector2_get_square_module(vector) <= DP_SQUARE_EPSYLON;
|
||||
return bg_fp64_vector2_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int sp_vector2_is_unit(const SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = sp_vector2_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
|
||||
return 1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_is_unit(const DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = dp_vector2_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
|
||||
return 1.0f - DP_TWO_EPSYLON <= square_module && square_module <= 1.0f + DP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_vector2_add(const SPVector2* vector1, const SPVector2* vector2, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_add(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_add(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
|
@ -164,13 +164,13 @@ static inline void dp_vector2_add(const DPVector2* vector1, const DPVector2* vec
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_vector2_subtract(const SPVector2* minuend, const SPVector2* subtrahend, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_subtract(const BgFP32Vector2* minuend, const BgFP32Vector2* subtrahend, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_subtract(const DPVector2* minuend, const DPVector2* subtrahend, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const BgFP64Vector2* subtrahend, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
|
@ -178,13 +178,13 @@ static inline void dp_vector2_subtract(const DPVector2* minuend, const DPVector2
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_vector2_multiply(const SPVector2* multiplicand, const float multiplier, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_multiply(const BgFP32Vector2* multiplicand, const float multiplier, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_multiply(const DPVector2* multiplicand, const double multiplier, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, const double multiplier, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
|
@ -192,13 +192,13 @@ static inline void dp_vector2_multiply(const DPVector2* multiplicand, const doub
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_vector2_divide(const SPVector2* dividend, const float divisor, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_divide(const BgFP32Vector2* dividend, const float divisor, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_divide(const DPVector2* dividend, const double divisor, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_divide(const BgFP64Vector2* dividend, const double divisor, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
|
@ -206,13 +206,13 @@ static inline void dp_vector2_divide(const DPVector2* dividend, const double div
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_vector2_append_scaled(SPVector2* basic_vector, const SPVector2* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_vector2_append_scaled(BgFP32Vector2* basic_vector, const BgFP32Vector2* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_append_scaled(DPVector2* basic_vector, const DPVector2* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_vector2_append_scaled(BgFP64Vector2* basic_vector, const BgFP64Vector2* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
|
@ -220,13 +220,13 @@ static inline void dp_vector2_append_scaled(DPVector2* basic_vector, const DPVec
|
|||
|
||||
// ================== Average2 ================== //
|
||||
|
||||
static inline void sp_vector2_get_mean2(const SPVector2* vector1, const SPVector2* vector2, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_get_mean2(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_get_mean2(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_get_mean2(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
|
@ -234,101 +234,101 @@ static inline void dp_vector2_get_mean2(const DPVector2* vector1, const DPVector
|
|||
|
||||
// ================== Average3 ================== //
|
||||
|
||||
static inline void sp_vector2_get_mean3(const SPVector2* vector1, const SPVector2* vector2, const SPVector2* vector3, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_get_mean3(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const BgFP32Vector2* vector3, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * SP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * SP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP32_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP32_ONE_THIRD;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_get_mean3(const DPVector2* vector1, const DPVector2* vector2, const DPVector2* vector3, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_get_mean3(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const BgFP64Vector2* vector3, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * DP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * DP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP64_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP64_ONE_THIRD;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
||||
static inline float sp_vector2_scalar(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_dot_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_scalar(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_dot_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
// =============== Cross Product ================ //
|
||||
|
||||
static inline float sp_vector2_cross(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_cross_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_cross(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
static inline int sp_vector2_normalize(SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = sp_vector2_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
|
||||
if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= SP_SQUARE_EPSYLON) {
|
||||
sp_vector2_reset(vector);
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp_vector2_divide(vector, sqrtf(square_module), vector);
|
||||
bg_fp32_vector2_divide(vector, sqrtf(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_normalize(DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = dp_vector2_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
|
||||
if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= DP_SQUARE_EPSYLON) {
|
||||
dp_vector2_reset(vector);
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dp_vector2_divide(vector, sqrt(square_module), vector);
|
||||
bg_fp64_vector2_divide(vector, sqrt(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Get Normalized =============== //
|
||||
|
||||
static inline int sp_vector2_get_normalized(const SPVector2* vector, SPVector2* result)
|
||||
static inline int bg_fp32_vector2_set_normalized(const BgFP32Vector2* vector, BgFP32Vector2* result)
|
||||
{
|
||||
sp_vector2_copy(vector, result);
|
||||
return sp_vector2_normalize(result);
|
||||
bg_fp32_vector2_copy(vector, result);
|
||||
return bg_fp32_vector2_normalize(result);
|
||||
}
|
||||
|
||||
static inline int dp_vector2_get_normalized(const DPVector2* vector, DPVector2* result)
|
||||
static inline int bg_fp64_vector2_set_normalized(const BgFP64Vector2* vector, BgFP64Vector2* result)
|
||||
{
|
||||
dp_vector2_copy(vector, result);
|
||||
return dp_vector2_normalize(result);
|
||||
bg_fp64_vector2_copy(vector, result);
|
||||
return bg_fp64_vector2_normalize(result);
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float sp_vector2_angle(const SPVector2* vector1, const SPVector2* vector2, const angle_unit_t unit);
|
||||
float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const angle_unit_t unit);
|
||||
|
||||
double dp_vector2_angle(const DPVector2* vector1, const DPVector2* vector2, const angle_unit_t unit);
|
||||
double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const angle_unit_t unit);
|
||||
|
||||
// =============== Square Distance ============== //
|
||||
|
||||
static inline float sp_vector2_get_square_distance(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_get_square_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
const float dx1 = (vector1->x1 - vector2->x1);
|
||||
const float dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -336,7 +336,7 @@ static inline float sp_vector2_get_square_distance(const SPVector2* vector1, con
|
|||
return dx1 * dx1 + dx2 * dx2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_square_distance(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_get_square_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
const double dx1 = (vector1->x1 - vector2->x1);
|
||||
const double dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -346,52 +346,52 @@ static inline double dp_vector2_get_square_distance(const DPVector2* vector1, co
|
|||
|
||||
// ================== Distance ================== //
|
||||
|
||||
static inline float sp_vector2_get_distance(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_get_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return sqrtf(sp_vector2_get_square_distance(vector1, vector2));
|
||||
return sqrtf(bg_fp32_vector2_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_distance(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
return sqrt(dp_vector2_get_square_distance(vector1, vector2));
|
||||
return sqrt(bg_fp64_vector2_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
// ================== Are Equal ================= //
|
||||
|
||||
static inline int sp_vector2_are_equal(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
const float square_module1 = sp_vector2_get_square_module(vector1);
|
||||
const float square_module2 = sp_vector2_get_square_module(vector2);
|
||||
const float square_module3 = sp_vector2_get_square_distance(vector1, vector2);
|
||||
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
|
||||
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
|
||||
const float square_module3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0f means dimension amount
|
||||
if (square_module1 < SP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < SP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0f * SP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0f * SP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0f * SP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_are_equal(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
const double square_module1 = dp_vector2_get_square_module(vector1);
|
||||
const double square_module2 = dp_vector2_get_square_module(vector2);
|
||||
const double square_module3 = dp_vector2_get_square_distance(vector1, vector2);
|
||||
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0 means dimension amount
|
||||
if (square_module1 < DP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < DP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0 * DP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0 * DP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0 * DP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,64 +2,64 @@
|
|||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float sp_vector3_angle(const SPVector3* vector1, const SPVector3* vector2, const angle_unit_t unit)
|
||||
float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const angle_unit_t unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module1 = sp_vector3_get_square_module(vector1);
|
||||
const float square_module1 = bg_fp32_vector3_get_square_module(vector1);
|
||||
|
||||
if (square_module1 <= SP_SQUARE_EPSYLON) {
|
||||
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_module2 = sp_vector3_get_square_module(vector2);
|
||||
const float square_module2 = bg_fp32_vector3_get_square_module(vector2);
|
||||
|
||||
if (square_module2 <= SP_SQUARE_EPSYLON) {
|
||||
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float cosine = sp_vector3_scalar(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2);
|
||||
|
||||
if (cosine >= 1.0f - SP_EPSYLON) {
|
||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (cosine <= -1.0f + SP_EPSYLON) {
|
||||
return sp_get_half_circle(unit);
|
||||
if (cosine <= -1.0f + BG_FP32_EPSYLON) {
|
||||
return bg_fp32_angle_get_half_circle(unit);
|
||||
}
|
||||
|
||||
return sp_convert_from_radians(acosf(cosine), unit);
|
||||
return bg_fp32_radians_to_units(acosf(cosine), unit);
|
||||
}
|
||||
|
||||
double dp_vector3_angle(const DPVector3* vector1, const DPVector3* vector2, const angle_unit_t unit)
|
||||
double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const angle_unit_t unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module1 = dp_vector3_get_square_module(vector1);
|
||||
const double square_module1 = bg_fp64_vector3_get_square_module(vector1);
|
||||
|
||||
if (square_module1 <= DP_SQUARE_EPSYLON) {
|
||||
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_module2 = dp_vector3_get_square_module(vector2);
|
||||
const double square_module2 = bg_fp64_vector3_get_square_module(vector2);
|
||||
|
||||
if (square_module2 <= DP_SQUARE_EPSYLON) {
|
||||
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double cosine = dp_vector3_scalar(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2);
|
||||
|
||||
if (cosine >= 1.0 - DP_EPSYLON) {
|
||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (cosine <= -1.0 + DP_EPSYLON) {
|
||||
return dp_get_half_circle(unit);
|
||||
if (cosine <= -1.0 + BG_FP64_EPSYLON) {
|
||||
return bg_fp64_angle_get_half_circle(unit);
|
||||
}
|
||||
|
||||
return dp_convert_from_radians(acos(cosine), unit);
|
||||
return bg_fp64_radians_to_units(acos(cosine), unit);
|
||||
}
|
||||
|
|
226
src/vector3.h
226
src/vector3.h
|
@ -7,27 +7,27 @@
|
|||
#include <math.h>
|
||||
|
||||
// ================== Vector3 =================== //
|
||||
|
||||
//
|
||||
typedef struct
|
||||
{
|
||||
float x1, x2, x3;
|
||||
} SPVector3;
|
||||
} BgFP32Vector3;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2, x3;
|
||||
} DPVector3;
|
||||
} BgFP64Vector3;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_vector3_reset(SPVector3* vector)
|
||||
static inline void bg_fp32_vector3_reset(BgFP32Vector3* vector)
|
||||
{
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
vector->x3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_reset(DPVector3* vector)
|
||||
static inline void bg_fp64_vector3_reset(BgFP64Vector3* vector)
|
||||
{
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
|
@ -36,14 +36,14 @@ static inline void dp_vector3_reset(DPVector3* vector)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_vector3_set_values(const float x1, const float x2, const float x3, SPVector3* to)
|
||||
static inline void bg_fp32_vector3_set_values(const float x1, const float x2, const float x3, BgFP32Vector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
to->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_set_values(const double x1, const double x2, const double x3, DPVector3* to)
|
||||
static inline void bg_fp64_vector3_set_values(const double x1, const double x2, const double x3, BgFP64Vector3* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
|
@ -52,14 +52,14 @@ static inline void dp_vector3_set_values(const double x1, const double x2, const
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_vector3_copy(const SPVector3* from, SPVector3* to)
|
||||
static inline void bg_fp32_vector3_copy(const BgFP32Vector3* from, BgFP32Vector3* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
to->x3 = from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_copy(const DPVector3* from, DPVector3* to)
|
||||
static inline void bg_fp64_vector3_copy(const BgFP64Vector3* from, BgFP64Vector3* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -68,14 +68,14 @@ static inline void dp_vector3_copy(const DPVector3* from, DPVector3* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector3_copy_from_double(const DPVector3* from, SPVector3* to)
|
||||
static inline void bg_fp32_vector3_set_from_fp64(const BgFP64Vector3* from, BgFP32Vector3* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
to->x3 = (float)from->x3;
|
||||
to->x1 = (float) from->x1;
|
||||
to->x2 = (float) from->x2;
|
||||
to->x3 = (float) from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_copy_from_single(const SPVector3* from, DPVector3* to)
|
||||
static inline void bg_fp64_vector3_set_from_fp32(const BgFP32Vector3* from, BgFP64Vector3* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -84,14 +84,14 @@ static inline void dp_vector3_copy_from_single(const SPVector3* from, DPVector3*
|
|||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
static inline void sp_vector3_reverse(const SPVector3* from, SPVector3* to)
|
||||
static inline void bg_fp32_vector3_set_reverse(const BgFP32Vector3* from, BgFP32Vector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
to->x3 = -from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_reverse(const DPVector3* from, DPVector3* to)
|
||||
static inline void bg_fp64_vector3_set_reverse(const BgFP64Vector3* from, BgFP64Vector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -100,14 +100,14 @@ static inline void dp_vector3_reverse(const DPVector3* from, DPVector3* to)
|
|||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
static inline void sp_vector3_reverse_double(const DPVector3* from, SPVector3* to)
|
||||
static inline void bg_fp32_vector3_set_reverse_fp64(const BgFP64Vector3* from, BgFP32Vector3* to)
|
||||
{
|
||||
to->x1 = -(float)from->x1;
|
||||
to->x2 = -(float)from->x2;
|
||||
to->x3 = -(float)from->x3;
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
to->x3 = (float) -from->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_reverse_single(const SPVector3* from, DPVector3* to)
|
||||
static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, BgFP64Vector3* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -116,62 +116,62 @@ static inline void dp_vector3_reverse_single(const SPVector3* from, DPVector3* t
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
static inline float sp_vector3_get_square_module(const SPVector3* vector)
|
||||
static inline float bg_fp32_vector3_get_square_module(const BgFP32Vector3* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
||||
}
|
||||
|
||||
static inline double dp_vector3_get_square_module(const DPVector3* vector)
|
||||
static inline double bg_fp64_vector3_get_square_module(const BgFP64Vector3* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
||||
}
|
||||
|
||||
static inline float sp_vector3_get_module(const SPVector3* vector)
|
||||
static inline float bg_fp32_vector3_get_module(const BgFP32Vector3* vector)
|
||||
{
|
||||
return sqrtf(sp_vector3_get_square_module(vector));
|
||||
return sqrtf(bg_fp32_vector3_get_square_module(vector));
|
||||
}
|
||||
|
||||
static inline double dp_vector3_get_module(const DPVector3* vector)
|
||||
static inline double bg_fp64_vector3_get_module(const BgFP64Vector3* vector)
|
||||
{
|
||||
return sqrt(dp_vector3_get_square_module(vector));
|
||||
return sqrt(bg_fp64_vector3_get_square_module(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int sp_vector3_is_zero(const SPVector3* vector)
|
||||
static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector)
|
||||
{
|
||||
return sp_vector3_get_square_module(vector) <= SP_SQUARE_EPSYLON;
|
||||
return bg_fp32_vector3_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector3_is_zero(const DPVector3* vector)
|
||||
static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector)
|
||||
{
|
||||
return dp_vector3_get_square_module(vector) <= DP_SQUARE_EPSYLON;
|
||||
return bg_fp64_vector3_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int sp_vector3_is_unit(const SPVector3* vector)
|
||||
static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector)
|
||||
{
|
||||
const float square_module = sp_vector3_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector3_get_square_module(vector);
|
||||
|
||||
return 1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector3_is_unit(const DPVector3* vector)
|
||||
static inline int bg_fp64_vector3_is_unit(const BgFP64Vector3* vector)
|
||||
{
|
||||
const double square_module = dp_vector3_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector3_get_square_module(vector);
|
||||
|
||||
return 1.0f - DP_TWO_EPSYLON <= square_module && square_module <= 1.0f + DP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_vector3_add(const SPVector3* vector1, const SPVector3* vector2, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_add(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
result->x3 = vector1->x3 + vector2->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_add(const DPVector3* vector1, const DPVector3* vector2, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_add(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
|
@ -180,14 +180,14 @@ static inline void dp_vector3_add(const DPVector3* vector1, const DPVector3* vec
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_vector3_subtract(const SPVector3* minuend, const SPVector3* subtrahend, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_subtract(const BgFP32Vector3* minuend, const BgFP32Vector3* subtrahend, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
result->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_subtract(const DPVector3* minuend, const DPVector3* subtrahend, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_subtract(const BgFP64Vector3* minuend, const BgFP64Vector3* subtrahend, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
|
@ -196,14 +196,14 @@ static inline void dp_vector3_subtract(const DPVector3* minuend, const DPVector3
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_vector3_multiply(const SPVector3* multiplicand, const float multiplier, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_multiply(const BgFP32Vector3* multiplicand, const float multiplier, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
result->x3 = multiplicand->x3 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_multiply(const DPVector3* multiplicand, const double multiplier, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_multiply(const BgFP64Vector3* multiplicand, const double multiplier, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
|
@ -212,14 +212,14 @@ static inline void dp_vector3_multiply(const DPVector3* multiplicand, const doub
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_vector3_divide(const SPVector3* dividend, const float divisor, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_divide(const BgFP32Vector3* dividend, const float divisor, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
result->x3 = dividend->x3 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_divide(const DPVector3* dividend, const double divisor, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_divide(const BgFP64Vector3* dividend, const double divisor, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
|
@ -228,14 +228,14 @@ static inline void dp_vector3_divide(const DPVector3* dividend, const double div
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_vector3_append_scaled(SPVector3* basic_vector, const SPVector3* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_vector3_append_scaled(BgFP32Vector3* basic_vector, const BgFP32Vector3* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
basic_vector->x3 += scalable_vector->x3 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_append_scaled(DPVector3* basic_vector, const DPVector3* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_vector3_append_scaled(BgFP64Vector3* basic_vector, const BgFP64Vector3* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
|
@ -244,14 +244,14 @@ static inline void dp_vector3_append_scaled(DPVector3* basic_vector, const DPVec
|
|||
|
||||
// ================== Average2 ================== //
|
||||
|
||||
static inline void sp_vector3_get_mean2(const SPVector3* vector1, const SPVector3* vector2, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_get_mean2(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
result->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_get_mean2(const DPVector3* vector1, const DPVector3* vector2, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_get_mean2(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
|
@ -260,42 +260,42 @@ static inline void dp_vector3_get_mean2(const DPVector3* vector1, const DPVector
|
|||
|
||||
// ================== Average3 ================== //
|
||||
|
||||
static inline void sp_vector3_get_mean3(const SPVector3* vector1, const SPVector3* vector2, const SPVector3* vector3, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_get_mean3(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3, BgFP32Vector3* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * SP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * SP_ONE_THIRD;
|
||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * SP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP32_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP32_ONE_THIRD;
|
||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BG_FP32_ONE_THIRD;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_get_mean3(const DPVector3* vector1, const DPVector3* vector2, const DPVector3* vector3, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_get_mean3(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3, BgFP64Vector3* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * DP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * DP_ONE_THIRD;
|
||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * DP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP64_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP64_ONE_THIRD;
|
||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BG_FP64_ONE_THIRD;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
||||
static inline float sp_vector3_scalar(const SPVector3* vector1, const SPVector3* vector2)
|
||||
static inline float bg_fp32_vector3_dot_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
||||
}
|
||||
|
||||
static inline double dp_vector3_scalar(const DPVector3* vector1, const DPVector3* vector2)
|
||||
static inline double bg_fp64_vector3_dot_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
||||
}
|
||||
|
||||
// =============== Triple Product =============== //
|
||||
|
||||
static inline float sp_vector3_triple(const SPVector3* vector1, const SPVector3* vector2, const SPVector3* vector3)
|
||||
static inline float bg_fp32_vector3_triple_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3)
|
||||
{
|
||||
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
||||
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
||||
+ vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1);
|
||||
}
|
||||
|
||||
static inline double dp_vector3_triple(const DPVector3* vector1, const DPVector3* vector2, const DPVector3* vector3)
|
||||
static inline double bg_fp64_vector3_triple_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3)
|
||||
{
|
||||
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
||||
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
||||
|
@ -304,9 +304,9 @@ static inline double dp_vector3_triple(const DPVector3* vector1, const DPVector3
|
|||
|
||||
// =============== Cross Product ================ //
|
||||
|
||||
static inline void sp_vector3_cross(const SPVector3* vector1, const SPVector3* vector2, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_cross_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* result)
|
||||
{
|
||||
sp_vector3_set_values(
|
||||
bg_fp32_vector3_set_values(
|
||||
vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2,
|
||||
vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3,
|
||||
vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1,
|
||||
|
@ -314,9 +314,9 @@ static inline void sp_vector3_cross(const SPVector3* vector1, const SPVector3* v
|
|||
);
|
||||
}
|
||||
|
||||
static inline void dp_vector3_cross(const DPVector3* vector1, const DPVector3* vector2, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_cross_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* result)
|
||||
{
|
||||
dp_vector3_set_values(
|
||||
bg_fp64_vector3_set_values(
|
||||
vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2,
|
||||
vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3,
|
||||
vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1,
|
||||
|
@ -326,20 +326,20 @@ static inline void dp_vector3_cross(const DPVector3* vector1, const DPVector3* v
|
|||
|
||||
// ============ Double Cross Product ============ //
|
||||
|
||||
static inline void sp_vector3_double_cross(const SPVector3* vector1, const SPVector3* vector2, const SPVector3* vector3, SPVector3* result)
|
||||
static inline void bg_fp32_vector3_double_cross_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3, BgFP32Vector3* result)
|
||||
{
|
||||
const float ac = sp_vector3_scalar(vector1, vector3);
|
||||
const float ab = sp_vector3_scalar(vector1, vector2);
|
||||
const float ac = bg_fp32_vector3_dot_product(vector1, vector3);
|
||||
const float ab = bg_fp32_vector3_dot_product(vector1, vector2);
|
||||
|
||||
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||
result->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
||||
}
|
||||
|
||||
static inline void dp_vector3_double_cross(const DPVector3* vector1, const DPVector3* vector2, const DPVector3* vector3, DPVector3* result)
|
||||
static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3, BgFP64Vector3* result)
|
||||
{
|
||||
const double ac = dp_vector3_scalar(vector1, vector3);
|
||||
const double ab = dp_vector3_scalar(vector1, vector2);
|
||||
const double ac = bg_fp64_vector3_dot_product(vector1, vector3);
|
||||
const double ab = bg_fp64_vector3_dot_product(vector1, vector2);
|
||||
|
||||
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||
|
@ -348,63 +348,63 @@ static inline void dp_vector3_double_cross(const DPVector3* vector1, const DPVec
|
|||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
static inline int sp_vector3_normalize(SPVector3* vector)
|
||||
static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
|
||||
{
|
||||
const float square_module = sp_vector3_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector3_get_square_module(vector);
|
||||
|
||||
if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= SP_SQUARE_EPSYLON) {
|
||||
sp_vector3_reset(vector);
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp_vector3_divide(vector, sqrtf(square_module), vector);
|
||||
bg_fp32_vector3_divide(vector, sqrtf(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_vector3_normalize(DPVector3* vector)
|
||||
static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
|
||||
{
|
||||
const double square_module = dp_vector3_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector3_get_square_module(vector);
|
||||
|
||||
if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= DP_SQUARE_EPSYLON) {
|
||||
dp_vector3_reset(vector);
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dp_vector3_divide(vector, sqrt(square_module), vector);
|
||||
bg_fp64_vector3_divide(vector, sqrt(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Get Normalized =============== //
|
||||
|
||||
static inline int sp_vector3_get_normalized(const SPVector3* vector, SPVector3* result)
|
||||
static inline int bg_fp32_vector3_set_normalized(const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
sp_vector3_copy(vector, result);
|
||||
return sp_vector3_normalize(result);
|
||||
bg_fp32_vector3_copy(vector, result);
|
||||
return bg_fp32_vector3_normalize(result);
|
||||
}
|
||||
|
||||
static inline int dp_vector3_get_normalized(const DPVector3* vector, DPVector3* result)
|
||||
static inline int bg_fp64_vector3_set_normalized(const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
dp_vector3_copy(vector, result);
|
||||
return dp_vector3_normalize(result);
|
||||
bg_fp64_vector3_copy(vector, result);
|
||||
return bg_fp64_vector3_normalize(result);
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float sp_vector3_angle(const SPVector3* vector1, const SPVector3* vector2, const angle_unit_t unit);
|
||||
float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const angle_unit_t unit);
|
||||
|
||||
double dp_vector3_angle(const DPVector3* vector1, const DPVector3* vector2, const angle_unit_t unit);
|
||||
double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const angle_unit_t unit);
|
||||
|
||||
// =============== Square Distance ============== //
|
||||
|
||||
static inline float sp_vector3_get_square_distance(const SPVector3* vector1, const SPVector3* vector2)
|
||||
static inline float bg_fp32_vector3_get_square_distance(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
||||
{
|
||||
const float dx1 = (vector1->x1 - vector2->x1);
|
||||
const float dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -413,7 +413,7 @@ static inline float sp_vector3_get_square_distance(const SPVector3* vector1, con
|
|||
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
||||
}
|
||||
|
||||
static inline double dp_vector3_get_square_distance(const DPVector3* vector1, const DPVector3* vector2)
|
||||
static inline double bg_fp64_vector3_get_square_distance(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
const double dx1 = (vector1->x1 - vector2->x1);
|
||||
const double dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -424,52 +424,52 @@ static inline double dp_vector3_get_square_distance(const DPVector3* vector1, co
|
|||
|
||||
// ================== Distance ================== //
|
||||
|
||||
static inline float sp_vector3_get_distance(const SPVector3* vector1, const SPVector3* vector2)
|
||||
static inline float bg_fp32_vector3_get_distance(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
||||
{
|
||||
return sqrtf(sp_vector3_get_square_distance(vector1, vector2));
|
||||
return sqrtf(bg_fp32_vector3_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
static inline double dp_vector3_get_distance(const DPVector3* vector1, const DPVector3* vector2)
|
||||
static inline double bg_fp64_vector3_get_distance(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
return sqrt(dp_vector3_get_square_distance(vector1, vector2));
|
||||
return sqrt(bg_fp64_vector3_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
// ================== Are Equal ================= //
|
||||
|
||||
static inline int sp_vector3_are_equal(const SPVector3* vector1, const SPVector3* vector2)
|
||||
static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
||||
{
|
||||
const float square_module1 = sp_vector3_get_square_module(vector1);
|
||||
const float square_module2 = sp_vector3_get_square_module(vector2);
|
||||
const float square_module3 = sp_vector3_get_square_distance(vector1, vector2);
|
||||
const float square_module1 = bg_fp32_vector3_get_square_module(vector1);
|
||||
const float square_module2 = bg_fp32_vector3_get_square_module(vector2);
|
||||
const float square_module3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0f means dimension amount
|
||||
if (square_module1 < SP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < SP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0f * SP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0f * SP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0f * SP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
static inline int dp_vector3_are_equal(const DPVector3* vector1, const DPVector3* vector2)
|
||||
static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
const double square_module1 = dp_vector3_get_square_module(vector1);
|
||||
const double square_module2 = dp_vector3_get_square_module(vector2);
|
||||
const double square_module3 = dp_vector3_get_square_distance(vector1, vector2);
|
||||
const double square_module1 = bg_fp64_vector3_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector3_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0 means dimension amount
|
||||
if (square_module1 < DP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < DP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0 * DP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0 * DP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0 * DP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
64
src/versor.c
64
src/versor.c
|
@ -3,19 +3,19 @@
|
|||
#include "angle.h"
|
||||
#include "versor.h"
|
||||
|
||||
const SPVersor SP_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
const BgFP32Versor BG_FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
const DPVersor DP_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
|
||||
const BgFP64Versor BG_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
|
||||
|
||||
void __sp_versor_normalize(const float square_module, SPVersor* versor)
|
||||
void __bg_fp32_versor_normalize(const float square_module, BgFP32Versor* versor)
|
||||
{
|
||||
if (square_module <= SP_SQUARE_EPSYLON) {
|
||||
sp_versor_reset(versor);
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3) <= SP_SQUARE_EPSYLON * square_module) {
|
||||
sp_versor_reset(versor);
|
||||
if ((versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3) <= BG_FP32_SQUARE_EPSYLON * square_module) {
|
||||
bg_fp32_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,17 +27,17 @@ void __sp_versor_normalize(const float square_module, SPVersor* versor)
|
|||
versor->_x3 /= module;
|
||||
}
|
||||
|
||||
void __dp_versor_normalize(const double square_module, DPVersor* versor)
|
||||
void __bg_fp64_versor_normalize(const double square_module, BgFP64Versor* versor)
|
||||
{
|
||||
if (square_module <= DP_SQUARE_EPSYLON) {
|
||||
dp_versor_reset(versor);
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
const double square_vector = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
|
||||
|
||||
if (square_vector <= DP_SQUARE_EPSYLON * square_module) {
|
||||
dp_versor_reset(versor);
|
||||
if (square_vector <= BG_FP64_SQUARE_EPSYLON * square_module) {
|
||||
bg_fp64_versor_reset(versor);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,27 +51,27 @@ void __dp_versor_normalize(const double square_module, DPVersor* versor)
|
|||
|
||||
// ==================== Make ==================== //
|
||||
|
||||
void sp_versor_make_from_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, SPVersor* result)
|
||||
void bg_fp32_versor_make_from_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Versor* result)
|
||||
{
|
||||
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= SP_SQUARE_EPSYLON) {
|
||||
sp_versor_reset(result);
|
||||
if (square_vector <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_versor_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const float half_angle = sp_convert_to_radians(0.5f * angle, unit);
|
||||
const float half_angle = bg_fp32_angle_to_radians(0.5f * angle, unit);
|
||||
|
||||
const float sine = sinf(half_angle);
|
||||
|
||||
if (-SP_EPSYLON <= sine && sine <= SP_EPSYLON) {
|
||||
sp_versor_reset(result);
|
||||
if (-BG_FP32_EPSYLON <= sine && sine <= BG_FP32_EPSYLON) {
|
||||
bg_fp32_versor_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sine / sqrtf(square_vector);
|
||||
|
||||
sp_versor_set(
|
||||
bg_fp32_versor_set_values(
|
||||
cosf(half_angle),
|
||||
x1 * multiplier,
|
||||
x2 * multiplier,
|
||||
|
@ -80,27 +80,27 @@ void sp_versor_make_from_crude_turn(const float x1, const float x2, const float
|
|||
);
|
||||
}
|
||||
|
||||
void dp_versor_make_from_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, DPVersor* result)
|
||||
void bg_fp64_versor_make_from_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Versor* result)
|
||||
{
|
||||
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||
|
||||
if (square_vector <= DP_SQUARE_EPSYLON) {
|
||||
dp_versor_reset(result);
|
||||
if (square_vector <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_versor_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const double half_angle = dp_convert_to_radians(0.5 * angle, unit);
|
||||
const double half_angle = bg_fp64_angle_to_radians(0.5 * angle, unit);
|
||||
|
||||
const double sine = sin(half_angle);
|
||||
|
||||
if (-DP_EPSYLON <= sine && sine <= DP_EPSYLON) {
|
||||
dp_versor_reset(result);
|
||||
if (-BG_FP64_EPSYLON <= sine && sine <= BG_FP64_EPSYLON) {
|
||||
bg_fp64_versor_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sine / sqrt(square_vector);
|
||||
|
||||
dp_versor_set(
|
||||
bg_fp64_versor_set_values(
|
||||
cos(half_angle),
|
||||
x1 * multiplier,
|
||||
x2 * multiplier,
|
||||
|
@ -111,14 +111,14 @@ void dp_versor_make_from_crude_turn(const double x1, const double x2, const doub
|
|||
|
||||
// ================= Rotation3 ================== //
|
||||
|
||||
void sp_versor_get_rotation(const SPVersor* versor, SPRotation3* result)
|
||||
void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* result)
|
||||
{
|
||||
if (versor == 0 || result == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (versor->_s0 <= -(1.0f - SP_EPSYLON) || 1.0f - SP_EPSYLON <= versor->_s0) {
|
||||
sp_rotation_reset(result);
|
||||
if (versor->_s0 <= -(1.0f - BG_FP32_EPSYLON) || 1.0f - BG_FP32_EPSYLON <= versor->_s0) {
|
||||
bg_fp32_rotation_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -133,14 +133,14 @@ void sp_versor_get_rotation(const SPVersor* versor, SPRotation3* result)
|
|||
result->axis.x3 = versor->_x3 / vector_module;
|
||||
}
|
||||
|
||||
void dp_versor_get_rotation(const DPVersor* versor, DPRotation3* result)
|
||||
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result)
|
||||
{
|
||||
if (versor == 0 || result == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (versor->_s0 <= -(1.0 - DP_EPSYLON) || 1.0 - DP_EPSYLON <= versor->_s0) {
|
||||
dp_rotation_reset(result);
|
||||
if (versor->_s0 <= -(1.0 - BG_FP64_EPSYLON) || 1.0 - BG_FP64_EPSYLON <= versor->_s0) {
|
||||
bg_fp64_rotation_reset(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
152
src/versor.h
152
src/versor.h
|
@ -10,18 +10,18 @@
|
|||
|
||||
typedef struct {
|
||||
float _s0, _x1, _x2, _x3;
|
||||
} SPVersor;
|
||||
} BgFP32Versor;
|
||||
|
||||
typedef struct {
|
||||
double _s0, _x1, _x2, _x3;
|
||||
} DPVersor;
|
||||
} BgFP64Versor;
|
||||
|
||||
extern const SPVersor SP_IDLE_VERSOR;
|
||||
extern const DPVersor DP_IDLE_VERSOR;
|
||||
extern const BgFP32Versor BG_FP32_IDLE_VERSOR;
|
||||
extern const BgFP64Versor BG_FP64_IDLE_VERSOR;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_versor_reset(SPVersor* versor)
|
||||
static inline void bg_fp32_versor_reset(BgFP32Versor* versor)
|
||||
{
|
||||
versor->_s0 = 1.0f;
|
||||
versor->_x1 = 0.0f;
|
||||
|
@ -29,7 +29,7 @@ static inline void sp_versor_reset(SPVersor* versor)
|
|||
versor->_x3 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_versor_reset(DPVersor* versor)
|
||||
static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
|
||||
{
|
||||
versor->_s0 = 1.0;
|
||||
versor->_x1 = 0.0;
|
||||
|
@ -39,26 +39,26 @@ static inline void dp_versor_reset(DPVersor* versor)
|
|||
|
||||
// ============== Get Scalar Part =============== //
|
||||
|
||||
static inline float sp_get_scalar_part(const SPVersor* versor)
|
||||
static inline float bg_fp32_versor_get_scalar(const BgFP32Versor* versor)
|
||||
{
|
||||
return versor->_s0;
|
||||
}
|
||||
|
||||
static inline double dp_get_scalar_part(const DPVersor* versor)
|
||||
static inline double bg_fp64_versor_get_scalar(const BgFP64Versor* versor)
|
||||
{
|
||||
return versor->_s0;
|
||||
}
|
||||
|
||||
// ============== Get Vector Part =============== //
|
||||
|
||||
static inline void sp_get_vector_part(const SPVersor* versor, SPVector3 * result)
|
||||
static inline void bg_fp32_versor_get_vector_part(const BgFP32Versor* versor, BgFP32Vector3 * result)
|
||||
{
|
||||
result->x1 = versor->_x1;
|
||||
result->x2 = versor->_x2;
|
||||
result->x3 = versor->_x3;
|
||||
}
|
||||
|
||||
static inline void dp_get_vector_part(const DPVersor* versor, DPVector3 * result)
|
||||
static inline void bg_fp64_versor_get_vector_part(const BgFP64Versor* versor, BgFP64Vector3 * result)
|
||||
{
|
||||
result->x1 = versor->_x1;
|
||||
result->x2 = versor->_x2;
|
||||
|
@ -67,24 +67,24 @@ static inline void dp_get_vector_part(const DPVersor* versor, DPVector3 * result
|
|||
|
||||
// =================== Get x1 =================== //
|
||||
|
||||
static inline float sp_get_x1(const SPVersor* versor)
|
||||
static inline float bg_fp32_versor_get_x1(const BgFP32Versor* versor)
|
||||
{
|
||||
return versor->_x1;
|
||||
}
|
||||
|
||||
static inline double dp_get_x1(const DPVersor* versor)
|
||||
static inline double bg_fp64_versor_get_x1(const BgFP64Versor* versor)
|
||||
{
|
||||
return versor->_x1;
|
||||
}
|
||||
|
||||
// =================== Get x2 =================== //
|
||||
|
||||
static inline float sp_get_x2(const SPVersor* versor)
|
||||
static inline float bg_fp32_versor_get_x2(const BgFP32Versor* versor)
|
||||
{
|
||||
return versor->_x2;
|
||||
}
|
||||
|
||||
static inline double dp_get_x2(const DPVersor* versor)
|
||||
static inline double bg_fp64_versor_get_x2(const BgFP64Versor* versor)
|
||||
{
|
||||
return versor->_x2;
|
||||
}
|
||||
|
@ -92,23 +92,23 @@ static inline double dp_get_x2(const DPVersor* versor)
|
|||
// =================== Get x3 =================== //
|
||||
|
||||
|
||||
static inline float sp_get_x3(const SPVersor* versor)
|
||||
static inline float bg_fp32_versor_get_x3(const BgFP32Versor* versor)
|
||||
{
|
||||
return versor->_x3;
|
||||
}
|
||||
|
||||
static inline double dp_get_x3(const DPVersor* versor)
|
||||
static inline double bg_fp64_versor_get_x3(const BgFP64Versor* versor)
|
||||
{
|
||||
return versor->_x3;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void __sp_versor_normalize(const float square_module, SPVersor* versor);
|
||||
void __bg_fp32_versor_normalize(const float square_module, BgFP32Versor* versor);
|
||||
|
||||
void __dp_versor_normalize(const double square_module, DPVersor* versor);
|
||||
void __bg_fp64_versor_normalize(const double square_module, BgFP64Versor* versor);
|
||||
|
||||
static inline void sp_versor_set(const float s0, const float x1, const float x2, const float x3, SPVersor* result)
|
||||
static inline void bg_fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Versor* result)
|
||||
{
|
||||
result->_s0 = s0;
|
||||
result->_x1 = x1;
|
||||
|
@ -117,12 +117,12 @@ static inline void sp_versor_set(const float s0, const float x1, const float x2,
|
|||
|
||||
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (square_module < 1.0f - SP_TWO_EPSYLON || 1.0f + SP_TWO_EPSYLON < square_module) {
|
||||
__sp_versor_normalize(square_module, result);
|
||||
if (square_module < 1.0f - BG_FP32_TWO_EPSYLON || 1.0f + BG_FP32_TWO_EPSYLON < square_module) {
|
||||
__bg_fp32_versor_normalize(square_module, result);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dp_versor_set(const double s0, const double x1, const double x2, const double x3, DPVersor* result)
|
||||
static inline void bg_fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Versor* result)
|
||||
{
|
||||
result->_s0 = s0;
|
||||
result->_x1 = x1;
|
||||
|
@ -131,14 +131,14 @@ static inline void dp_versor_set(const double s0, const double x1, const double
|
|||
|
||||
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||
|
||||
if (square_module < 1.0 - DP_TWO_EPSYLON || 1.0 + DP_TWO_EPSYLON < square_module) {
|
||||
__dp_versor_normalize(square_module, result);
|
||||
if (square_module < 1.0 - BG_FP64_TWO_EPSYLON || 1.0 + BG_FP64_TWO_EPSYLON < square_module) {
|
||||
__bg_fp64_versor_normalize(square_module, result);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_versor_copy(const SPVersor* from, SPVersor* to)
|
||||
static inline void bg_fp32_versor_copy(const BgFP32Versor* from, BgFP32Versor* to)
|
||||
{
|
||||
to->_s0 = from->_s0;
|
||||
to->_x1 = from->_x1;
|
||||
|
@ -146,7 +146,7 @@ static inline void sp_versor_copy(const SPVersor* from, SPVersor* to)
|
|||
to->_x3 = from->_x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_copy(const DPVersor* from, DPVersor* to)
|
||||
static inline void bg_fp64_versor_copy(const BgFP64Versor* from, BgFP64Versor* to)
|
||||
{
|
||||
to->_s0 = from->_s0;
|
||||
to->_x1 = from->_x1;
|
||||
|
@ -156,76 +156,76 @@ static inline void dp_versor_copy(const DPVersor* from, DPVersor* to)
|
|||
|
||||
// ==================== Make ==================== //
|
||||
|
||||
void sp_versor_make_from_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, SPVersor* result);
|
||||
void bg_fp32_versor_make_from_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Versor* result);
|
||||
|
||||
void dp_versor_make_from_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, DPVersor* result);
|
||||
void bg_fp64_versor_make_from_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Versor* result);
|
||||
|
||||
static inline void sp_versor_make_from_turn(const SPVector3* axis, const float angle, const angle_unit_t unit, SPVersor* result)
|
||||
static inline void bg_fp32_versor_make_from_turn(const BgFP32Vector3* axis, const float angle, const angle_unit_t unit, BgFP32Versor* result)
|
||||
{
|
||||
sp_versor_make_from_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||
bg_fp32_versor_make_from_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||
}
|
||||
|
||||
static inline void dp_versor_make_from_turn(const DPVector3* axis, const double angle, const angle_unit_t unit, DPVersor* result)
|
||||
static inline void bg_fp64_versor_make_from_turn(const BgFP64Vector3* axis, const double angle, const angle_unit_t unit, BgFP64Versor* result)
|
||||
{
|
||||
dp_versor_make_from_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||
bg_fp64_versor_make_from_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||
}
|
||||
|
||||
static inline void sp_versor_make_from_rotation(const SPRotation3* rotation, SPVersor* result)
|
||||
static inline void bg_fp32_versor_make_from_rotation(const BgFP32Rotation3* rotation, BgFP32Versor* result)
|
||||
{
|
||||
sp_versor_make_from_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, ANGLE_UNIT_RADIANS, result);
|
||||
bg_fp32_versor_make_from_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
||||
}
|
||||
|
||||
static inline void dp_versor_make_from_rotation(const DPRotation3* rotation, DPVersor* result)
|
||||
static inline void bg_fp64_versor_make_from_rotation(const BgFP64Rotation3* rotation, BgFP64Versor* result)
|
||||
{
|
||||
dp_versor_make_from_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, ANGLE_UNIT_RADIANS, result);
|
||||
bg_fp64_versor_make_from_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int sp_versor_is_idle(const SPVersor* versor)
|
||||
static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor)
|
||||
{
|
||||
return 1.0f - SP_EPSYLON <= versor->_s0 || versor->_s0 <= -(1.0 - SP_EPSYLON);
|
||||
return 1.0f - BG_FP32_EPSYLON <= versor->_s0 || versor->_s0 <= -(1.0 - BG_FP32_EPSYLON);
|
||||
}
|
||||
|
||||
static inline int dp_versor_is_idle(const DPVersor* versor)
|
||||
static inline int bg_fp64_versor_is_idle(const BgFP64Versor* versor)
|
||||
{
|
||||
return 1.0 - DP_EPSYLON <= versor->_s0 || versor->_s0 <= -(1.0 - DP_EPSYLON);
|
||||
return 1.0 - BG_FP64_EPSYLON <= versor->_s0 || versor->_s0 <= -(1.0 - BG_FP64_EPSYLON);
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_versor_from_double(const DPVersor* versor, SPVersor* result)
|
||||
static inline void bg_fp32_versor_set_from_fp64(const BgFP64Versor* versor, BgFP32Versor* result)
|
||||
{
|
||||
sp_versor_set(
|
||||
(float)versor->_s0,
|
||||
(float)versor->_x1,
|
||||
(float)versor->_x2,
|
||||
(float)versor->_x3,
|
||||
bg_fp32_versor_set_values(
|
||||
(float) versor->_s0,
|
||||
(float) versor->_x1,
|
||||
(float) versor->_x2,
|
||||
(float) versor->_x3,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
static inline void dp_versor_from_single(const SPVersor* versor, DPVersor* result)
|
||||
static inline void bg_fp64_versor_set_from_fp32(const BgFP32Versor* versor, BgFP64Versor* result)
|
||||
{
|
||||
dp_versor_set(
|
||||
(double)versor->_s0,
|
||||
(double)versor->_x1,
|
||||
(double)versor->_x2,
|
||||
(double)versor->_x3,
|
||||
bg_fp64_versor_set_values(
|
||||
versor->_s0,
|
||||
versor->_x1,
|
||||
versor->_x2,
|
||||
versor->_x3,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline void sp_versor_invert(SPVersor* versor)
|
||||
static inline void bg_fp32_versor_invert(BgFP32Versor* versor)
|
||||
{
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
versor->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_invert(DPVersor* versor)
|
||||
static inline void bg_fp64_versor_invert(BgFP64Versor* versor)
|
||||
{
|
||||
versor->_x1 = -versor->_x1;
|
||||
versor->_x2 = -versor->_x2;
|
||||
|
@ -234,7 +234,7 @@ static inline void dp_versor_invert(DPVersor* versor)
|
|||
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
static inline void sp_versor_make_inverted(const SPVersor* versor, SPVersor* result)
|
||||
static inline void bg_fp32_versor_set_inverted(const BgFP32Versor* versor, BgFP32Versor* result)
|
||||
{
|
||||
result->_s0 = versor->_s0;
|
||||
result->_x1 = -versor->_x1;
|
||||
|
@ -242,7 +242,7 @@ static inline void sp_versor_make_inverted(const SPVersor* versor, SPVersor* res
|
|||
result->_x3 = -versor->_x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_make_inverted(const DPVersor* versor, DPVersor* result)
|
||||
static inline void bg_fp64_versor_set_inverted(const BgFP64Versor* versor, BgFP64Versor* result)
|
||||
{
|
||||
result->_s0 = versor->_s0;
|
||||
result->_x1 = -versor->_x1;
|
||||
|
@ -252,7 +252,7 @@ static inline void dp_versor_make_inverted(const DPVersor* versor, DPVersor* res
|
|||
|
||||
// ================ Combination ================= //
|
||||
|
||||
static inline void sp_versor_combine(const SPVersor* second, const SPVersor* first, SPVersor* result)
|
||||
static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP32Versor* first, BgFP32Versor* result)
|
||||
{
|
||||
const float s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
|
||||
const float x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
|
||||
|
@ -266,12 +266,12 @@ static inline void sp_versor_combine(const SPVersor* second, const SPVersor* fir
|
|||
result->_x2 = x2;
|
||||
result->_x3 = x3;
|
||||
|
||||
if (square_module < 1.0f - SP_TWO_EPSYLON || 1.0f + SP_TWO_EPSYLON < square_module) {
|
||||
__sp_versor_normalize(square_module, result);
|
||||
if (square_module < 1.0f - BG_FP32_TWO_EPSYLON || 1.0f + BG_FP32_TWO_EPSYLON < square_module) {
|
||||
__bg_fp32_versor_normalize(square_module, result);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dp_versor_combine(const DPVersor* second, const DPVersor* first, DPVersor* result)
|
||||
static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
|
||||
{
|
||||
const double s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
|
||||
const double x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
|
||||
|
@ -285,20 +285,20 @@ static inline void dp_versor_combine(const DPVersor* second, const DPVersor* fir
|
|||
result->_x2 = x2;
|
||||
result->_x3 = x3;
|
||||
|
||||
if (square_module < 1.0 - DP_TWO_EPSYLON || 1.0 + DP_TWO_EPSYLON < square_module) {
|
||||
__dp_versor_normalize(square_module, result);
|
||||
if (square_module < 1.0 - BG_FP64_TWO_EPSYLON || 1.0 + BG_FP64_TWO_EPSYLON < square_module) {
|
||||
__bg_fp64_versor_normalize(square_module, result);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= Rotation3 ================== //
|
||||
|
||||
void sp_versor_get_rotation(const SPVersor* versor, SPRotation3* result);
|
||||
void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* result);
|
||||
|
||||
void dp_versor_get_rotation(const DPVersor* versor, DPRotation3* result);
|
||||
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result);
|
||||
|
||||
// =========== Make Rotation Matrix3x3 ========== //
|
||||
|
||||
static inline void sp_versor_make_matrix(const SPVersor* versor, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_versor_make_rotation_matrix(const BgFP32Versor* versor, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -326,7 +326,7 @@ static inline void sp_versor_make_matrix(const SPVersor* versor, SPMatrix3x3* ma
|
|||
matrix->r1c3 = x1x3 + s0x2;
|
||||
}
|
||||
|
||||
static inline void dp_versor_make_matrix(const DPVersor* versor, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_versor_make_rotation_matrix(const BgFP64Versor* versor, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -356,7 +356,7 @@ static inline void dp_versor_make_matrix(const DPVersor* versor, DPMatrix3x3* ma
|
|||
|
||||
// =========== Make Reverse Matrix3x3 =========== //
|
||||
|
||||
static inline void sp_versor_make_reverse_matrix(const SPVersor* versor, SPMatrix3x3* matrix)
|
||||
static inline void bg_fp32_versor_make_reverse_matrix(const BgFP32Versor* versor, BgFP32Matrix3x3* matrix)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -384,7 +384,7 @@ static inline void sp_versor_make_reverse_matrix(const SPVersor* versor, SPMatri
|
|||
matrix->r1c3 = x1x3 - s0x2;
|
||||
}
|
||||
|
||||
static inline void dp_versor_make_reverse_matrix(const DPVersor* versor, DPMatrix3x3* matrix)
|
||||
static inline void bg_fp64_versor_make_reverse_matrix(const BgFP64Versor* versor, BgFP64Matrix3x3* matrix)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -414,7 +414,7 @@ static inline void dp_versor_make_reverse_matrix(const DPVersor* versor, DPMatri
|
|||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
static inline void sp_versor_turn(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
|
||||
static inline void bg_fp32_versor_turn(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
|
@ -429,7 +429,7 @@ static inline void sp_versor_turn(const SPVersor* versor, const SPVector3* vecto
|
|||
result->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_turn(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
|
||||
static inline void bg_fp64_versor_turn(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
|
@ -446,7 +446,7 @@ static inline void dp_versor_turn(const DPVersor* versor, const DPVector3* vecto
|
|||
|
||||
// ================ Turn2 Vector ================ //
|
||||
|
||||
static inline void sp_versor_turn2(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
|
||||
static inline void bg_fp32_versor_turn2(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -482,7 +482,7 @@ static inline void sp_versor_turn2(const SPVersor* versor, const SPVector3* vect
|
|||
result->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_turn2(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
|
||||
static inline void bg_fp64_versor_turn2(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -520,7 +520,7 @@ static inline void dp_versor_turn2(const DPVersor* versor, const DPVector3* vect
|
|||
|
||||
// ============== Turn Vector Back ============== //
|
||||
|
||||
static inline void sp_versor_turn_back(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
|
||||
static inline void bg_fp32_versor_turn_back(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
const float tx1 = 2.0f * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const float tx2 = 2.0f * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
|
@ -535,7 +535,7 @@ static inline void sp_versor_turn_back(const SPVersor* versor, const SPVector3*
|
|||
result->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_turn_back(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
|
||||
static inline void bg_fp64_versor_turn_back(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
const double tx1 = 2.0 * (versor->_x2 * vector->x3 - versor->_x3 * vector->x2);
|
||||
const double tx2 = 2.0 * (versor->_x3 * vector->x1 - versor->_x1 * vector->x3);
|
||||
|
@ -552,7 +552,7 @@ static inline void dp_versor_turn_back(const DPVersor* versor, const DPVector3*
|
|||
|
||||
// ============== Turn Vector Back2 ============= //
|
||||
|
||||
static inline void sp_versor_turn_back2(const SPVersor* versor, const SPVector3* vector, SPVector3* result)
|
||||
static inline void bg_fp32_versor_turn_back2(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
||||
{
|
||||
const float s0s0 = versor->_s0 * versor->_s0;
|
||||
const float x1x1 = versor->_x1 * versor->_x1;
|
||||
|
@ -588,7 +588,7 @@ static inline void sp_versor_turn_back2(const SPVersor* versor, const SPVector3*
|
|||
result->x3 = x3;
|
||||
}
|
||||
|
||||
static inline void dp_versor_turn_back2(const DPVersor* versor, const DPVector3* vector, DPVector3* result)
|
||||
static inline void bg_fp64_versor_turn_back2(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
||||
{
|
||||
const double s0s0 = versor->_s0 * versor->_s0;
|
||||
const double x1x1 = versor->_x1 * versor->_x1;
|
||||
|
|
150
test/fp32_vector2_test.c
Normal file
150
test/fp32_vector2_test.c
Normal file
|
@ -0,0 +1,150 @@
|
|||
#include "sp_vector2_test.h"
|
||||
|
||||
const int TEST_BG_FP32_VECTOR2_AMOUNT_1 = 5;
|
||||
|
||||
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1[] = {
|
||||
{ 3.0f, 4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 10000.0f, -20000.0f },
|
||||
{ 0.1f, -10.0f },
|
||||
{ -123.5f, 3.7283f }
|
||||
};
|
||||
|
||||
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = {
|
||||
{ -3.0f, -4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 0.002f, -0.05f },
|
||||
{ -0.2f, 12.0f },
|
||||
{ 1.5f, -23.35f }
|
||||
};
|
||||
|
||||
// =============== Square module ================ //
|
||||
|
||||
const float BG_FP32_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
|
||||
|
||||
int test_sp_vector2_square_module()
|
||||
{
|
||||
print_test_name("BgFP32Vector2 square module");
|
||||
|
||||
float square_module;
|
||||
|
||||
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
square_module = bg_fp32_vector2_get_square_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_sp_are_equal(square_module, BG_FP32_VECTOR2_SQUARE_MODULE_1[i], TEST_BG_FP32_TWO_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
|
||||
const float BG_FP32_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
|
||||
|
||||
int test_sp_vector2_module()
|
||||
{
|
||||
print_test_name("BgFP32Vector2 module");
|
||||
|
||||
float square_module;
|
||||
|
||||
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
square_module = sp_vector2_get_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_sp_are_equal(square_module, BG_FP32_VECTOR2_MODULE_1[i], TEST_BG_FP32_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ===================== Add ==================== //
|
||||
|
||||
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[] = {
|
||||
{ 0.0f, 0.0f },
|
||||
{ -6.0f, -8.0f },
|
||||
{ 10000.002f, -20000.05f },
|
||||
{ -0.1f, 2.0f },
|
||||
{ -122.0f, -19.6217f }
|
||||
};
|
||||
|
||||
int test_sp_vector2_add()
|
||||
{
|
||||
print_test_name("BgFP32Vector2 add");
|
||||
|
||||
BgFP32Vector2 vector;
|
||||
|
||||
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
sp_vector2_add(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_sp_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_BG_FP32_EPSYLON) ||
|
||||
!test_sp_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_BG_FP32_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[] = {
|
||||
{ 6.0f, 8.0f },
|
||||
{ 0.0f, 0.0f },
|
||||
{ 9999.998f, -19999.95f },
|
||||
{ 0.3f, -22.0f },
|
||||
{ -125.0f, 27.0783f }
|
||||
};
|
||||
|
||||
int test_sp_vector2_subtract()
|
||||
{
|
||||
print_test_name("BgFP32Vector2 subtract");
|
||||
|
||||
BgFP32Vector2 vector;
|
||||
|
||||
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
sp_vector2_subtract(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_sp_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_BG_FP32_EPSYLON) ||
|
||||
!test_sp_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_BG_FP32_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== 1234 ==================== //
|
||||
|
||||
int test_sp_vector2()
|
||||
{
|
||||
print_test_section("BgFP32Vector2");
|
||||
|
||||
if (test_sp_vector2_square_module() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_module() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_add() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_subtract() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
16
test/fp32_vector2_test.h
Normal file
16
test/fp32_vector2_test.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__
|
||||
#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__
|
||||
|
||||
#include "geometry_test.h"
|
||||
|
||||
int test_bg_fp32_vector2();
|
||||
|
||||
int test_bg_fp32_vector2_square_module();
|
||||
|
||||
int test_bg_fp32_vector2_module();
|
||||
|
||||
int test_bg_fp32_vector2_add();
|
||||
|
||||
int test_bg_fp32_vector2_subtract();
|
||||
|
||||
#endif
|
|
@ -42,6 +42,10 @@
|
|||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="fp32_vector2_test.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="fp32_vector2_test.h" />
|
||||
<Unit filename="geometry_test.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
@ -49,10 +53,6 @@
|
|||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="sp_vector2_test.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="sp_vector2_test.h" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<ActiveTarget name="Release" />
|
||||
<File name="main.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="178" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="geometry_test.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="407" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="sp_vector2_test.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="177" topLine="4" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="geometry_test.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="407" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
#define TEST_RESULT_SUCCES 0
|
||||
#define TEST_RESULT_FAILED 100
|
||||
|
||||
#define TEST_SP_EPSYLON 1E-6f
|
||||
#define TEST_SP_TWO_EPSYLON 2E-6f
|
||||
#define TEST_SP_SQUARE_EPSYLON 1E-12f
|
||||
#define TEST_BG_FP32_EPSYLON 1E-6f
|
||||
#define TEST_BG_FP32_TWO_EPSYLON 2E-6f
|
||||
#define TEST_BG_FP32_SQUARE_EPSYLON 1E-12f
|
||||
|
||||
#define TEST_DP_EPSYLON 1E-13f
|
||||
#define TEST_DP_TWO_EPSYLON 2E-13f
|
||||
#define TEST_DP_SQUARE_EPSYLON 1E-26f
|
||||
#define TEST_BG_FP64_EPSYLON 1E-13f
|
||||
#define TEST_BG_FP64_TWO_EPSYLON 2E-13f
|
||||
#define TEST_BG_FP64_SQUARE_EPSYLON 1E-26f
|
||||
|
||||
void print_test_section(const char * name);
|
||||
|
||||
|
@ -22,7 +22,7 @@ void print_test_success();
|
|||
|
||||
void print_test_failed();
|
||||
|
||||
inline int test_sp_are_equal(const float value1, const float value2, const float epsylon)
|
||||
inline int test_bg_fp32_are_equal(const float value1, const float value2, const float epsylon)
|
||||
{
|
||||
if (-1.0f <= value1 && value1 <= 1.0f) {
|
||||
const float difference = value1 - value2;
|
||||
|
@ -36,7 +36,7 @@ inline int test_sp_are_equal(const float value1, const float value2, const float
|
|||
return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1;
|
||||
}
|
||||
|
||||
inline int test_dp_are_equal(const double value1, const double value2, const double epsylon)
|
||||
inline int test_bg_fp64_are_equal(const double value1, const double value2, const double epsylon)
|
||||
{
|
||||
if (-1.0 <= value1 && value1 <= 1.0) {
|
||||
const double difference = value1 - value2;
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "geometry_test.h"
|
||||
#include "sp_vector2_test.h"
|
||||
#include "fp32_vector2_test.h"
|
||||
|
||||
#define PROGRAM_RESULT_SUCCESS 0
|
||||
#define PROGRAM_RESULT_FAILED 1
|
||||
|
||||
int main()
|
||||
{
|
||||
if (test_sp_vector2() == TEST_RESULT_FAILED) {
|
||||
if (test_bg_fp32_vector2() == TEST_RESULT_FAILED) {
|
||||
return PROGRAM_RESULT_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
#include "sp_vector2_test.h"
|
||||
|
||||
const int TEST_SP_VECTOR2_AMOUNT_1 = 5;
|
||||
|
||||
const SPVector2 TEST_SP_VECTOR2_COMMON_1[] = {
|
||||
{ 3.0f, 4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 10000.0f, -20000.0f },
|
||||
{ 0.1f, -10.0f },
|
||||
{ -123.5f, 3.7283f }
|
||||
};
|
||||
|
||||
const SPVector2 TEST_SP_VECTOR2_COMMON_2[] = {
|
||||
{ -3.0f, -4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 0.002f, -0.05f },
|
||||
{ -0.2f, 12.0f },
|
||||
{ 1.5f, -23.35f }
|
||||
};
|
||||
|
||||
// =============== Square module ================ //
|
||||
|
||||
const float SP_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
|
||||
|
||||
int test_sp_vector2_square_module()
|
||||
{
|
||||
print_test_name("SPVector2 square module");
|
||||
|
||||
float square_module;
|
||||
|
||||
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
|
||||
square_module = sp_vector2_get_square_module(&TEST_SP_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_sp_are_equal(square_module, SP_VECTOR2_SQUARE_MODULE_1[i], TEST_SP_TWO_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
|
||||
const float SP_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
|
||||
|
||||
int test_sp_vector2_module()
|
||||
{
|
||||
print_test_name("SPVector2 module");
|
||||
|
||||
float square_module;
|
||||
|
||||
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
|
||||
square_module = sp_vector2_get_module(&TEST_SP_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_sp_are_equal(square_module, SP_VECTOR2_MODULE_1[i], TEST_SP_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ===================== Add ==================== //
|
||||
|
||||
const SPVector2 TEST_SP_VECTOR2_COMMON_1_2_SUM[] = {
|
||||
{ 0.0f, 0.0f },
|
||||
{ -6.0f, -8.0f },
|
||||
{ 10000.002f, -20000.05f },
|
||||
{ -0.1f, 2.0f },
|
||||
{ -122.0f, -19.6217f }
|
||||
};
|
||||
|
||||
int test_sp_vector2_add()
|
||||
{
|
||||
print_test_name("SPVector2 add");
|
||||
|
||||
SPVector2 vector;
|
||||
|
||||
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
|
||||
sp_vector2_add(&TEST_SP_VECTOR2_COMMON_1[i], &TEST_SP_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_sp_are_equal(vector.x1, TEST_SP_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_SP_EPSYLON) ||
|
||||
!test_sp_are_equal(vector.x2, TEST_SP_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_SP_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
const SPVector2 TEST_SP_VECTOR2_COMMON_1_2_DIFF[] = {
|
||||
{ 6.0f, 8.0f },
|
||||
{ 0.0f, 0.0f },
|
||||
{ 9999.998f, -19999.95f },
|
||||
{ 0.3f, -22.0f },
|
||||
{ -125.0f, 27.0783f }
|
||||
};
|
||||
|
||||
int test_sp_vector2_subtract()
|
||||
{
|
||||
print_test_name("SPVector2 subtract");
|
||||
|
||||
SPVector2 vector;
|
||||
|
||||
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
|
||||
sp_vector2_subtract(&TEST_SP_VECTOR2_COMMON_1[i], &TEST_SP_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_sp_are_equal(vector.x1, TEST_SP_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_SP_EPSYLON) ||
|
||||
!test_sp_are_equal(vector.x2, TEST_SP_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_SP_EPSYLON)) {
|
||||
print_test_failed();
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_test_success();
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== 1234 ==================== //
|
||||
|
||||
int test_sp_vector2()
|
||||
{
|
||||
print_test_section("SPVector2");
|
||||
|
||||
if (test_sp_vector2_square_module() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_module() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_add() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
if (test_sp_vector2_subtract() != TEST_RESULT_SUCCES) {
|
||||
return TEST_RESULT_FAILED;
|
||||
}
|
||||
|
||||
return TEST_RESULT_SUCCES;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__
|
||||
#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__
|
||||
|
||||
#include "geometry_test.h"
|
||||
|
||||
int test_sp_vector2();
|
||||
|
||||
int test_sp_vector2_square_module();
|
||||
|
||||
int test_sp_vector2_module();
|
||||
|
||||
int test_sp_vector2_add();
|
||||
|
||||
int test_sp_vector2_subtract();
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue