Добавлено несколько модульных тестов (покрыто примерно 3,2%), небольшое исправление, переименование tantent в tangent pair (тангенсная пара)

This commit is contained in:
Andrey Pokidov 2025-02-08 19:25:10 +07:00
parent 9864653787
commit ab4a589e21
30 changed files with 1433 additions and 155 deletions

View file

@ -0,0 +1,246 @@
#include "versor_are_close.h"
#include "../../helpers.h"
typedef struct {
BgcVersorFP32 versor1, versor2;
} _TestVersorPairFP32;
typedef struct {
BgcVersorFP64 versor1, versor2;
} _TestVersorPairFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = {
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32 }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32 }
},
{
{ 0.70710678f, 0.0f, 0.70710675f, 0.0f },
{ 0.70710675f, 0.0f, 0.70710678f, 0.0f }
},
{
{ 0.0f, -0.70710678f, 0.0f, -0.70710675f },
{ 0.0f, -0.70710675f, 0.0f, -0.70710678f }
}
};
static const int _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = {
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32 }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32 }
},
{
{ 0.707106f, 0.0f, 0.707107f, 0.0f },
{ 0.707107f, 0.0f, 0.707106f, 0.0f }
},
{
{ 0.0f, -0.707107f, 0.0f, -0.707106f },
{ 0.0f, -0.707106f, 0.0f, -0.707107f }
}
};
int test_bgc_versor_are_close_fp32()
{
print_testing_name("bgc_versor_are_close_fp32");
// Testing close pairs of versors:
for (int i = 0; i < _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
if (!bgc_versor_are_close_fp32(&_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor2)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of versors:
for (int i = 0; i < _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
if (bgc_versor_are_close_fp32(&_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = {
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64 }
},
{
{ 0.7071067811865475244, 0.0, 0.7071067811865465244, 0.0 },
{ 0.7071067811865465244, 0.0, 0.7071067811865475244, 0.0 }
},
{
{ 0.0, -0.7071067811865475244, 0.0, -0.7071067811865465244 },
{ 0.0, -0.7071067811865465244, 0.0, -0.7071067811865475244 }
}
};
static const int _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = {
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64 }
},
{
{ 0.7071067811866, 0.0, 0.7071067811865, 0.0 },
{ 0.7071067811865, 0.0, 0.7071067811866, 0.0 }
},
{
{ 0.0, -0.7071067811866, 0.0, -0.7071067811865 },
{ 0.0, -0.7071067811865, 0.0, -0.7071067811866 }
}
};
int test_bgc_versor_are_close_fp64()
{
print_testing_name("bgc_versor_are_close_fp64");
// Testing close pairs of versors:
for (int i = 0; i < _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
if (!bgc_versor_are_close_fp64(&_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor2)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of versors:
for (int i = 0; i < _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
if (bgc_versor_are_close_fp64(&_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_ARE_CLOSE_H_
#define _TEST_VERSOR_ARE_CLOSE_H_
int test_bgc_versor_are_close_fp32();
int test_bgc_versor_are_close_fp64();
#endif

View file

@ -0,0 +1,117 @@
#include "./versor_combine.h"
#include <math.h>
#include "./../../helpers.h"
typedef struct {
BgcVersorFP32 first, second, result;
} _TestVersorTripletFP32;
typedef struct {
BgcVersorFP64 first, second, result;
} _TestVersorTripletFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_TRIPLET_AMOUNT = 5;
static const _TestVersorTripletFP32 _TEST_FP32_VERSOR_TRIPLET_LIST[] = {
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 0.0f, 0.0f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f }
},
{
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
},
{
{ 0.7071067812f, 0.7071067812f, 0.0f, 0.0f },
{ 0.7071067812f, 0.0f, 0.0f, 0.7071067812f },
{ 0.5f, 0.5f, 0.5f, 0.5f }
}
};
int test_bgc_versor_combine_fp32()
{
BgcVersorFP32 versor;
print_testing_name("bgc_versor_combine_fp32");
for (int i = 0; i < _TEST_FP32_VERSOR_TRIPLET_AMOUNT; i++) {
bgc_versor_combine_fp32(&_TEST_FP32_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].first, &versor);
if (!bgc_versor_are_close_fp32(&versor, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_TRIPLET_AMOUNT = 5;
static const _TestVersorTripletFP64 _TEST_FP64_VERSOR_TRIPLET_LIST[] = {
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 0.0, 0.0 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ -1.0, 0.0, 0.0, 0.0 },
{ -1.0, 0.0, 0.0, 0.0 }
},
{
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
},
{
{ 0.7071067811865475, 0.7071067811865475, 0.0, 0.0 },
{ 0.7071067811865475, 0.0, 0.0, 0.7071067811865475 },
{ 0.5, 0.5, 0.5, 0.5 }
}
};
int test_bgc_versor_combine_fp64()
{
BgcVersorFP64 versor;
print_testing_name("bgc_versor_combine_fp64");
for (int i = 0; i < _TEST_FP64_VERSOR_TRIPLET_AMOUNT; i++) {
bgc_versor_combine_fp64(&_TEST_FP64_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].first, &versor);
if (!bgc_versor_are_close_fp64(&versor, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_COMBINE_H_
#define _TEST_VERSOR_COMBINE_H_
int test_bgc_versor_combine_fp32();
int test_bgc_versor_combine_fp64();
#endif

View file

@ -0,0 +1,41 @@
#include "./versor_reset.h"
#include <math.h>
#include "./../../helpers.h"
int test_bgc_versor_reset_fp32()
{
BgcVersorFP32 versor;
print_testing_name("bgc_versor_reset_fp32");
bgc_versor_reset_fp32(&versor);
if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}
int test_bgc_versor_reset_fp64()
{
BgcVersorFP64 versor;
print_testing_name("bgc_versor_reset_fp64");
bgc_versor_reset_fp64(&versor);
if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_RESET_H_
#define _TEST_VERSOR_RESET_H_
int test_bgc_versor_reset_fp32();
int test_bgc_versor_reset_fp64();
#endif

View file

@ -0,0 +1,141 @@
#include "./versor_set_values.h"
#include <math.h>
#include "./../../helpers.h"
typedef struct {
float s0, x1, x2, x3;
} _TestVersorComponentsFP32;
typedef struct {
double s0, x1, x2, x3;
} _TestVersorComponentsFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP32 _TEST_FP32_VERSOR_DATA_LIST[] = {
{ 1.0f, 2.0f, 3.0f, 4.0f },
{ 4.0f, 3.0f, 2.0f, 1.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f, 0.0f }
};
int test_bgc_versor_set_values_fp32()
{
float versor_module, ratio;
BgcVersorFP32 versor;
print_testing_name("bgc_versor_set_values_fp32");
for (int i = 0; i < _TEST_FP32_VERSOR_DATA_AMOUNT; i++) {
bgc_versor_set_values_fp32(
_TEST_FP32_VERSOR_DATA_LIST[i].s0,
_TEST_FP32_VERSOR_DATA_LIST[i].x1,
_TEST_FP32_VERSOR_DATA_LIST[i].x2,
_TEST_FP32_VERSOR_DATA_LIST[i].x3,
&versor
);
versor_module = sqrtf(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
if (!bgc_is_unit_fp32(versor_module)) {
print_testing_failed();
print_testing_warning("Versor module is not equal to one.");
return TEST_FAILED;
}
if (bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].s0)) {
continue;
}
ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor.s0;
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x1).");
return TEST_FAILED;
}
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x2).");
return TEST_FAILED;
}
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x3).");
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP64 _TEST_FP64_VERSOR_DATA_LIST[] = {
{ 1.0, 2.0, 3.0, 4.0 },
{ 4.0, 3.0, 2.0, 1.0 },
{ -1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 1.0, 0.0 }
};
int test_bgc_versor_set_values_fp64()
{
double versor_module, ratio;
BgcVersorFP64 versor;
print_testing_name("bgc_versor_set_values_fp64");
for (int i = 0; i < _TEST_FP64_VERSOR_DATA_AMOUNT; i++) {
bgc_versor_set_values_fp64(
_TEST_FP64_VERSOR_DATA_LIST[i].s0,
_TEST_FP64_VERSOR_DATA_LIST[i].x1,
_TEST_FP64_VERSOR_DATA_LIST[i].x2,
_TEST_FP64_VERSOR_DATA_LIST[i].x3,
&versor
);
versor_module = sqrt(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
if (!bgc_is_unit_fp64(versor_module)) {
print_testing_failed();
print_testing_warning("Versor module is not equal to one.");
return TEST_SUCCES;
}
if (bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].s0)) {
continue;
}
ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor.s0;
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x1).");
return TEST_SUCCES;
}
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x2).");
return TEST_SUCCES;
}
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x3).");
return TEST_SUCCES;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_SET_VALUES_H_
#define _TEST_VERSOR_SET_VALUES_H_
int test_bgc_versor_set_values_fp32();
int test_bgc_versor_set_values_fp64();
#endif