diff --git a/basic-geometry-test/basic-geometry-test.vcxproj b/basic-geometry-test/basic-geometry-test.vcxproj index b5bf337..be411b3 100644 --- a/basic-geometry-test/basic-geometry-test.vcxproj +++ b/basic-geometry-test/basic-geometry-test.vcxproj @@ -148,13 +148,33 @@ - - + + + + + + + + + + + + - - + + + + + + + + + + + + diff --git a/basic-geometry-test/basic-geometry-test.vcxproj.filters b/basic-geometry-test/basic-geometry-test.vcxproj.filters index df06490..39dd6e5 100644 --- a/basic-geometry-test/basic-geometry-test.vcxproj.filters +++ b/basic-geometry-test/basic-geometry-test.vcxproj.filters @@ -1,36 +1,93 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы + + + + tests - - Исходные файлы + + tests - - Исходные файлы + + tests + + + tests + + + tests\utilities + + + tests\utilities + + + tests\utilities + + + tests\versor + + + tests\versor + + + tests\versor + + + tests\versor - - Исходные файлы + + + tests - - Исходные файлы + + tests + + tests + + + tests + + + tests\utilities + + + tests\utilities + + + tests\utilities + + + tests\versor + + + tests\versor + + + tests\versor + + + tests\versor + + + + + {10db9024-67b8-4555-80a9-48b54ae0dec9} + + + {392bc542-f334-4132-a22b-b5b440c77897} + + + {d9f520e0-1b2d-4379-8887-1b5728763129} + + + {dbf2eefa-8f1f-4447-b3d4-d17dee049580} + + + {d6f82407-8310-4b32-b153-aa67e766c72a} + \ No newline at end of file diff --git a/basic-geometry-test/geometry_test.c b/basic-geometry-test/geometry_test.c deleted file mode 100644 index b6f5de5..0000000 --- a/basic-geometry-test/geometry_test.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "geometry_test.h" - -#include - -void print_test_section(const char * name) -{ - printf("================ %s ================\n", name); -} - -void print_test_name(const char * name) -{ - printf(" Testing of %s: ", name); -} - -void print_test_success() -{ - printf("[ \x1b[32mSuccess\x1b[0m ]\n"); -} - -void print_test_failed() -{ - printf("[ \x1b[31mFailed\x1b[0m ]\n"); -} diff --git a/basic-geometry-test/geometry_test.h b/basic-geometry-test/geometry_test.h deleted file mode 100644 index a806b6f..0000000 --- a/basic-geometry-test/geometry_test.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __GEOMETRY_TEST_H__ -#define __GEOMETRY_TEST_H__ - -#include - -#define TEST_RESULT_SUCCES 0 -#define TEST_RESULT_FAILED 100 - -#define TEST_BGC_EPSYLON_FP32 1E-6f -#define TEST_BGC_TWO_EPSYLON_FP32 2E-6f -#define TEST_BGC_SQUARE_EPSYLON_FP32 1E-12f - -#define TEST_BGC_EPSYLON_FP64 1E-13f -#define TEST_BGC_TWO_EPSYLON_FP64 2E-13f -#define TEST_BGC_SQUARE_EPSYLON_FP64 1E-26f - -void print_test_section(const char * name); - -void print_test_name(const char * name); - -void print_test_success(); - -void print_test_failed(); - -inline int test_are_equal_fp32(const float value1, const float value2, const float epsylon) -{ - if (-1.0f <= value1 && value1 <= 1.0f) { - const float difference = value1 - value2; - return -epsylon <= difference && difference <= epsylon; - } - - if (value1 > 0.0f) { - return value1 <= value2 * (1.0f + epsylon) && value2 <= value1 * (1.0f + epsylon); - } - - return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1; -} - -inline int test_are_equal_fp64(const double value1, const double value2, const double epsylon) -{ - if (-1.0 <= value1 && value1 <= 1.0) { - const double difference = value1 - value2; - return -epsylon <= difference && difference <= epsylon; - } - - if (value1 > 0.0) { - return value1 <= value2 * (1.0 + epsylon) && value2 <= value1 * (1.0 + epsylon); - } - - return value1 * (1.0 + epsylon) <= value2 && value2 * (1.0 + epsylon) <= value1; -} - -#endif diff --git a/basic-geometry-test/helpers.c b/basic-geometry-test/helpers.c new file mode 100644 index 0000000..81c08f5 --- /dev/null +++ b/basic-geometry-test/helpers.c @@ -0,0 +1,29 @@ +#include + +#include "helpers.h" + +void print_testing_section(const char * name) +{ + puts("\n======================================\n"); + puts(name); +} + +void print_testing_name(const char * name) +{ + printf(" Testing of %s: ", name); +} + +void print_testing_success() +{ + printf("[ \x1b[32mSuccess\x1b[0m ]\n"); +} + +void print_testing_failed() +{ + printf("[ \x1b[31mFailed\x1b[0m ]\n"); +} + +void print_testing_warning(const char * message) +{ + printf(" Warning: \x1b[30m%s\x1b[0m\n", message); +} diff --git a/basic-geometry-test/helpers.h b/basic-geometry-test/helpers.h new file mode 100644 index 0000000..68a04a0 --- /dev/null +++ b/basic-geometry-test/helpers.h @@ -0,0 +1,19 @@ +#ifndef __GEOMETRY_TEST_H__ +#define __GEOMETRY_TEST_H__ + +#include + +#define TEST_SUCCES 0 +#define TEST_FAILED -1 + +void print_testing_section(const char * name); + +void print_testing_name(const char * name); + +void print_testing_success(); + +void print_testing_failed(); + +void print_testing_warning(const char* message); + +#endif diff --git a/basic-geometry-test/main.c b/basic-geometry-test/main.c index 03b5b92..ea53cdd 100644 --- a/basic-geometry-test/main.c +++ b/basic-geometry-test/main.c @@ -1,17 +1,23 @@ #include #include -#include "geometry_test.h" -#include "fp32_vector2_test.h" +#include "helpers.h" -#define PROGRAM_RESULT_SUCCESS 0 -#define PROGRAM_RESULT_FAILED 1 +#include "tests/utilities.h" +#include "tests/versor.h" + +#define PROGRAM_SUCCESS 0 +#define PROGRAM_FAILED 1 int main() { - if (test_fp32_vector2() == TEST_RESULT_FAILED) { - return PROGRAM_RESULT_FAILED; + if (test_utilities() == TEST_FAILED) { + return PROGRAM_FAILED; } - return PROGRAM_RESULT_SUCCESS; + if (test_versor() == TEST_FAILED) { + return PROGRAM_FAILED; + } + + return PROGRAM_SUCCESS; } diff --git a/basic-geometry-test/tests/utilities.c b/basic-geometry-test/tests/utilities.c new file mode 100644 index 0000000..edffa1a --- /dev/null +++ b/basic-geometry-test/tests/utilities.c @@ -0,0 +1,69 @@ +#include "./utilities.h" + +#include "./../helpers.h" + +int test_bgc_is_zero() +{ + if (test_bgc_is_zero_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_is_zero_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_bgc_is_unit() +{ + if (test_bgc_is_unit_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_is_unit_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_is_sqare_value_unit_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_is_sqare_value_unit_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_bgc_are_close() +{ + if (test_bgc_are_close_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_are_close_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_utilities() +{ + print_testing_section("BGC Utilities"); + + if (test_bgc_is_zero() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_is_unit() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_are_close() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} \ No newline at end of file diff --git a/basic-geometry-test/tests/utilities.h b/basic-geometry-test/tests/utilities.h new file mode 100644 index 0000000..901216b --- /dev/null +++ b/basic-geometry-test/tests/utilities.h @@ -0,0 +1,16 @@ +#ifndef _TEST_UTILITIES_H_ +#define _TEST_UTILITIES_H_ + +#include "./utilities/is_zero.h" +#include "./utilities/is_unit.h" +#include "./utilities/are_close.h" + +int test_bgc_is_zero(); + +int test_bgc_is_unit(); + +int test_bgc_are_close(); + +int test_utilities(); + +#endif diff --git a/basic-geometry-test/tests/utilities/are_close.c b/basic-geometry-test/tests/utilities/are_close.c new file mode 100644 index 0000000..a6734a0 --- /dev/null +++ b/basic-geometry-test/tests/utilities/are_close.c @@ -0,0 +1,163 @@ +#include "./are_close.h" + +#include "./../../helpers.h" + +typedef struct { + float number1, number2; +} _TestNumberPairFP32; + +typedef struct { + double number1, number2; +} _TestNumberPairFP64; + +// ==================== FP32 ==================== // + +static const int _TEST_FP32_CLOSE_NUMBERS_AMOUNT = 16; +static const int _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT = 16; + +static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = { + {0.0f, 0.0f}, + {1.0f, 1.0f}, + {-1.0f, -1.0f}, + + {-0.5f * BGC_EPSYLON_FP32, 0.5f * BGC_EPSYLON_FP32}, + + {1.0f, 1.0f + BGC_EPSYLON_FP32}, + {1.0f, 1.0f - BGC_EPSYLON_FP32}, + {1.0f + BGC_EPSYLON_FP32, 1.0f}, + {1.0f - BGC_EPSYLON_FP32, 1.0f}, + + {-1.0f, -1.0f + BGC_EPSYLON_FP32}, + {-1.0f, -1.0f - BGC_EPSYLON_FP32}, + {-1.0f + BGC_EPSYLON_FP32, -1.0f}, + {-1.0f - BGC_EPSYLON_FP32, -1.0f}, + + {100.0f, 100.0f + 99.0f * BGC_EPSYLON_FP32}, + {100.0f, 100.0f - 99.0f * BGC_EPSYLON_FP32}, + {-100.0f, -100.0f + 99.0f * BGC_EPSYLON_FP32}, + {-100.0f, -100.0f - 99.0f * BGC_EPSYLON_FP32} +}; + +static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = { + {0.0f, 0.001f}, + {1.0f, 0.999f}, + {-1.0f, -0.999f}, + + {-0.6f * BGC_EPSYLON_FP32, 0.6f * BGC_EPSYLON_FP32}, + + {1.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32}, + {1.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32}, + {1.0f + 1.5f * BGC_EPSYLON_FP32, 1.0f}, + {1.0f - 1.5f * BGC_EPSYLON_FP32, 1.0f}, + + {-1.0f, -1.0f + 1.5f * BGC_EPSYLON_FP32}, + {-1.0f, -1.0f - 1.5f * BGC_EPSYLON_FP32}, + {-1.0f + 1.5f * BGC_EPSYLON_FP32, -1.0f}, + {-1.0f - 1.5f * BGC_EPSYLON_FP32, -1.0f}, + + {100.0f, 100.0f + 101.0f * BGC_EPSYLON_FP32}, + {100.0f, 100.0f - 101.0f * BGC_EPSYLON_FP32}, + {-100.0f, -100.0f + 101.0f * BGC_EPSYLON_FP32}, + {-100.0f, -100.0f - 101.0f * BGC_EPSYLON_FP32} +}; + +int test_bgc_are_close_fp32() +{ + print_testing_name("bgc_are_close_fp32"); + + // Testing close pairs of values: + for (int i = 0; i < _TEST_FP32_CLOSE_NUMBERS_AMOUNT; i++) { + if (!bgc_are_close_fp32(_TEST_FP32_DATA_CLOSE[i].number1, _TEST_FP32_DATA_CLOSE[i].number2)) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing different pairs of values: + for (int i = 0; i < _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT; i++) { + if (bgc_are_close_fp32(_TEST_FP32_DATA_DIFFERENT[i].number1, _TEST_FP32_DATA_DIFFERENT[i].number2)) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} + +// ==================== FP64 ==================== // + +static const int _TEST_FP64_CLOSE_NUMBERS_AMOUNT = 16; +static const int _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT = 16; + +static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = { + {0.0, 0.0}, + {1.0, 1.0}, + {-1.0, -1.0}, + + {-0.5 * BGC_EPSYLON_FP64, 0.5 * BGC_EPSYLON_FP64}, + + {1.0, 1.0 + BGC_EPSYLON_FP64}, + {1.0, 1.0 - BGC_EPSYLON_FP64}, + {1.0 + BGC_EPSYLON_FP64, 1.0}, + {1.0 - BGC_EPSYLON_FP64, 1.0}, + + {-1.0, -1.0 + BGC_EPSYLON_FP64}, + {-1.0, -1.0 - BGC_EPSYLON_FP64}, + {-1.0 + BGC_EPSYLON_FP64, -1.0}, + {-1.0 - BGC_EPSYLON_FP64, -1.0}, + + {100.0, 100.0 + 99.0 * BGC_EPSYLON_FP64}, + {100.0, 100.0 - 99.0 * BGC_EPSYLON_FP64}, + {-100.0, -100.0 + 99.0 * BGC_EPSYLON_FP64}, + {-100.0, -100.0 - 99.0 * BGC_EPSYLON_FP64} +}; + +static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = { + {0.0, 0.000001}, + {1.0, 0.999999}, + {-1.0, -0.999999}, + + {-0.6 * BGC_EPSYLON_FP64, 0.6 * BGC_EPSYLON_FP64}, + + {1.0, 1.0 + 1.5 * BGC_EPSYLON_FP64}, + {1.0, 1.0 - 1.5 * BGC_EPSYLON_FP64}, + {1.0 + 1.5 * BGC_EPSYLON_FP64, 1.0}, + {1.0 - 1.5 * BGC_EPSYLON_FP64, 1.0}, + + {-1.0, -1.0 + 1.5 * BGC_EPSYLON_FP64}, + {-1.0, -1.0 - 1.5 * BGC_EPSYLON_FP64}, + {-1.0 + 1.5 * BGC_EPSYLON_FP64, -1.0}, + {-1.0 - 1.5 * BGC_EPSYLON_FP64, -1.0}, + + {100.0, 100.0 + 101.0 * BGC_EPSYLON_FP64}, + {100.0, 100.0 - 101.0 * BGC_EPSYLON_FP64}, + {-100.0, -100.0 + 101.0 * BGC_EPSYLON_FP64}, + {-100.0, -100.0 - 101.0 * BGC_EPSYLON_FP64} +}; + +int test_bgc_are_close_fp64() +{ + print_testing_name("bgc_are_close_fp64"); + + // Testing close pairs of values: + for (int i = 0; i < _TEST_FP64_CLOSE_NUMBERS_AMOUNT; i++) { + if (!bgc_are_close_fp64(_TEST_FP64_DATA_CLOSE[i].number1, _TEST_FP64_DATA_CLOSE[i].number2)) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing different pairs of values: + for (int i = 0; i < _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT; i++) { + if (bgc_are_close_fp64(_TEST_FP64_DATA_DIFFERENT[i].number1, _TEST_FP64_DATA_DIFFERENT[i].number2)) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} diff --git a/basic-geometry-test/tests/utilities/are_close.h b/basic-geometry-test/tests/utilities/are_close.h new file mode 100644 index 0000000..4fdea3f --- /dev/null +++ b/basic-geometry-test/tests/utilities/are_close.h @@ -0,0 +1,8 @@ +#ifndef _TEST_UTILITIES_ARE_CLOSE_H_ +#define _TEST_UTILITIES_ARE_CLOSE_H_ + +int test_bgc_are_close_fp32(); + +int test_bgc_are_close_fp64(); + +#endif diff --git a/basic-geometry-test/tests/utilities/is_unit.c b/basic-geometry-test/tests/utilities/is_unit.c new file mode 100644 index 0000000..4d19432 --- /dev/null +++ b/basic-geometry-test/tests/utilities/is_unit.c @@ -0,0 +1,179 @@ +#include "./is_unit.h" + +#include "./../../helpers.h" + +// ==================== FP32 ==================== // + +static const int _TEST_FP32_UNIT_NUMBERS_AMOUNT = 3; +static const int _TEST_FP32_NONUNIT_NUMBERS_AMOUNT = 4; + +static const float _TEST_FP32_UNIT_NUMBERS[] = { + 1.0f, + 1.0f + BGC_EPSYLON_FP32, + 1.0f - BGC_EPSYLON_FP32 +}; + +static const float _TEST_FP32_NONUNIT_NUMBERS[] = { + 0.0f, + -1.0f, + 1.0f + 2.0f * BGC_EPSYLON_FP32, + 1.0f - 2.0f * BGC_EPSYLON_FP32 +}; + +int test_bgc_is_unit_fp32() +{ + print_testing_name("bgc_is_unit_fp32"); + + // Testing unit values: + for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) { + if (!bgc_is_unit_fp32(_TEST_FP32_UNIT_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-unit values: + for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) { + if (bgc_is_unit_fp32(_TEST_FP32_NONUNIT_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} + +// ==================== FP64 ==================== // + +static const int _TEST_FP64_UNIT_NUMBERS_AMOUNT = 3; +static const int _TEST_FP64_NONUNIT_NUMBERS_AMOUNT = 4; + +static const double _TEST_FP64_UNIT_NUMBERS[] = { + 1.0, + 1.0 + BGC_EPSYLON_FP64, + 1.0 - BGC_EPSYLON_FP64 +}; + +static const double _TEST_FP64_NONUNIT_NUMBERS[] = { + 0.0, + -1.0, + 1.0 + 2.0 * BGC_EPSYLON_FP64, + 1.0 - 2.0 * BGC_EPSYLON_FP64 +}; + +int test_bgc_is_unit_fp64() +{ + print_testing_name("bgc_is_unit_fp64"); + + // Testing unit values: + for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) { + if (!bgc_is_unit_fp64(_TEST_FP64_UNIT_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-unit values: + for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) { + if (bgc_is_unit_fp64(_TEST_FP64_NONUNIT_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} + +// ================ Square FP32 ================= // + +static const int _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT = 5; +static const int _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT = 4; + +static const float _TEST_FP32_DATA_SQUARE_UNIT[] = { + 1.0f, + 1.0f + BGC_EPSYLON_FP32, + 1.0f - BGC_EPSYLON_FP32, + 1.0f + 2.0f * BGC_EPSYLON_FP32, + 1.0f - 2.0f * BGC_EPSYLON_FP32 +}; + +static const float _TEST_FP32_DATA_SQUARE_NONUNIT[] = { + 0.0f, + -1.0f, + 1.0f + 2.5f * BGC_EPSYLON_FP32, + 1.0f - 2.5f * BGC_EPSYLON_FP32 +}; + +int test_bgc_is_sqare_value_unit_fp32() +{ + print_testing_name("bgc_is_sqare_value_unit_fp32"); + + // Testing unit values: + for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) { + if (!bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-unit values: + for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) { + if (bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} + +// ================ Square FP64 ================= // + +static const int _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT = 5; +static const int _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT = 4; + +static const double _TEST_FP64_DATA_SQUARE_UNIT[] = { + 1.0, + 1.0 + BGC_EPSYLON_FP64, + 1.0 - BGC_EPSYLON_FP64, + 1.0 + 2.0 * BGC_EPSYLON_FP64, + 1.0 - 2.0 * BGC_EPSYLON_FP64 +}; + +static const double _TEST_FP64_DATA_SQUARE_NONUNIT[] = { + 0.0, + -1.0, + 1.0 + 2.5 * BGC_EPSYLON_FP64, + 1.0 - 2.5 * BGC_EPSYLON_FP64 +}; + +int test_bgc_is_sqare_value_unit_fp64() +{ + print_testing_name("bgc_is_sqare_value_unit_fp64"); + + // Testing unit values: + for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) { + if (!bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-unit values: + for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) { + if (bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} diff --git a/basic-geometry-test/tests/utilities/is_unit.h b/basic-geometry-test/tests/utilities/is_unit.h new file mode 100644 index 0000000..7f35c0c --- /dev/null +++ b/basic-geometry-test/tests/utilities/is_unit.h @@ -0,0 +1,12 @@ +#ifndef _TEST_UTILITIES_IS_UNIT_H_ +#define _TEST_UTILITIES_IS_UNIT_H_ + +int test_bgc_is_unit_fp32(); + +int test_bgc_is_unit_fp64(); + +int test_bgc_is_sqare_value_unit_fp32(); + +int test_bgc_is_sqare_value_unit_fp64(); + +#endif diff --git a/basic-geometry-test/tests/utilities/is_zero.c b/basic-geometry-test/tests/utilities/is_zero.c new file mode 100644 index 0000000..473a877 --- /dev/null +++ b/basic-geometry-test/tests/utilities/is_zero.c @@ -0,0 +1,93 @@ +#include "./is_zero.h" + +#include "./../../helpers.h" + +// ==================== FP32 ==================== // + +static const int _TEST_FP32_ZERO_NUMBERS_AMOUNT = 5; +static const int _TEST_FP32_NONZERO_NUMBERS_AMOUNT = 4; + +static const float _TEST_FP32_ZERO_NUMBERS[] = { + 0.0f, + BGC_EPSYLON_FP32, + -BGC_EPSYLON_FP32, + BGC_SQUARE_EPSYLON_FP32, + -BGC_SQUARE_EPSYLON_FP32 +}; + +static const float _TEST_FP32_NONZERO_NUMBERS[] = { + 1.0f, + -1.0f, + (1.5f * BGC_EPSYLON_FP32), + -(1.5f * BGC_EPSYLON_FP32) +}; + +int test_bgc_is_zero_fp32() +{ + print_testing_name("bgc_is_zero_fp32"); + + // Testing zero values: + for (int i = 0; i < _TEST_FP32_ZERO_NUMBERS_AMOUNT; i++) { + if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-zero values: + for (int i = 0; i < _TEST_FP32_NONZERO_NUMBERS_AMOUNT; i++) { + if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} + +// ==================== FP64 ==================== // + +static const int _TEST_FP64_ZERO_NUMBERS_AMOUNT = 5; +static const int _TEST_FP64_NONZERO_NUMBERS_AMOUNT = 4; + +static const double _TEST_FP64_ZERO_NUMBERS[] = { + 0.0, + BGC_EPSYLON_FP64, + -BGC_EPSYLON_FP64, + BGC_SQUARE_EPSYLON_FP64, + -BGC_SQUARE_EPSYLON_FP64 +}; + +static const double _TEST_FP64_NONZERO_NUMBERS[] = { + 1.0, + -1.0, + (1.5 * BGC_EPSYLON_FP64), + -(1.5 * BGC_EPSYLON_FP64) +}; + +int test_bgc_is_zero_fp64() +{ + print_testing_name("bgc_is_zero_fp64"); + + // Testing zero values: + for (int i = 0; i < _TEST_FP64_ZERO_NUMBERS_AMOUNT; i++) { + if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + // Testing non-zero values: + for (int i = 0; i < _TEST_FP64_NONZERO_NUMBERS_AMOUNT; i++) { + if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBERS[i])) { + print_testing_failed(); + return TEST_FAILED; + } + } + + print_testing_success(); + + return TEST_SUCCES; +} diff --git a/basic-geometry-test/tests/utilities/is_zero.h b/basic-geometry-test/tests/utilities/is_zero.h new file mode 100644 index 0000000..47db0ec --- /dev/null +++ b/basic-geometry-test/tests/utilities/is_zero.h @@ -0,0 +1,8 @@ +#ifndef _TEST_UTILITIES_IS_ZERO_H_ +#define _TEST_UTILITIES_IS_ZERO_H_ + +int test_bgc_is_zero_fp32(); + +int test_bgc_is_zero_fp64(); + +#endif diff --git a/basic-geometry-test/fp32_vector2_test.c b/basic-geometry-test/tests/vector2.c similarity index 64% rename from basic-geometry-test/fp32_vector2_test.c rename to basic-geometry-test/tests/vector2.c index ee79cfd..c942cae 100644 --- a/basic-geometry-test/fp32_vector2_test.c +++ b/basic-geometry-test/tests/vector2.c @@ -1,4 +1,4 @@ -#include "fp32_vector2_test.h" +#include "vector2.h" const int TEST_FP32_VECTOR2_AMOUNT_1 = 5; @@ -19,26 +19,26 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_2[] = { }; // =============== Square modulus =============== // - +/* const float FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f }; int test_vector2_fp32_square_modulus() { - print_test_name("vector2_fp32_t square modulus"); + print_testing_name("vector2_fp32_t square modulus"); float square_modulus; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { square_modulus = bgc_vector2_get_square_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]); - if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_BGC_TWO_EPSYLON_FP32)) { - print_test_failed(); - return TEST_RESULT_FAILED; + if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i])) { + print_testing_failed(); + return TEST_FAILED; } } - print_test_success(); - return TEST_RESULT_SUCCES; + print_testing_success(); + return TEST_SUCCES; } // =================== Module =================== // @@ -47,21 +47,21 @@ const float FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55 int test_vector2_fp32_modulus() { - print_test_name("vector2_fp32_t modulus"); + print_testing_name("vector2_fp32_t modulus"); float square_modulus; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { square_modulus = bgc_vector2_get_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]); - if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i], TEST_BGC_EPSYLON_FP32)) { - print_test_failed(); - return TEST_RESULT_FAILED; + if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i])) { + print_testing_failed(); + return TEST_FAILED; } } - print_test_success(); - return TEST_RESULT_SUCCES; + print_testing_success(); + return TEST_SUCCES; } // ===================== Add ==================== // @@ -76,22 +76,22 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1_2_SUM[] = { int test_vector2_add_fp32() { - print_test_name("vector2_fp32_t add"); + print_testing_name("vector2_fp32_t add"); BgcVector2FP32 vector; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { bgc_vector2_add_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector); - if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_BGC_EPSYLON_FP32) || - !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_BGC_EPSYLON_FP32)) { - print_test_failed(); - return TEST_RESULT_FAILED; + if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1) || + !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2)) { + print_testing_failed(); + return TEST_FAILED; } } - print_test_success(); - return TEST_RESULT_SUCCES; + print_testing_success(); + return TEST_SUCCES; } // ================== Subtract ================== // @@ -106,45 +106,46 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1_2_DIFF[] = { int test_vector2_subtract_fp32() { - print_test_name("vector2_fp32_t subtract"); + print_testing_name("vector2_fp32_t subtract"); BgcVector2FP32 vector; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { bgc_vector2_subtract_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector); - if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_BGC_EPSYLON_FP32) || - !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_BGC_EPSYLON_FP32)) { - print_test_failed(); - return TEST_RESULT_FAILED; + if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1) || + !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2)) { + print_testing_failed(); + return TEST_FAILED; } } - print_test_success(); - return TEST_RESULT_SUCCES; + print_testing_success(); + return TEST_SUCCES; } // ==================== 1234 ==================== // int test_fp32_vector2() { - print_test_section("vector2_fp32_t"); + print_testing_section("vector2_fp32_t"); - if (test_vector2_fp32_square_modulus() != TEST_RESULT_SUCCES) { - return TEST_RESULT_FAILED; + if (test_vector2_fp32_square_modulus() != TEST_SUCCES) { + return TEST_FAILED; } - if (test_vector2_fp32_modulus() != TEST_RESULT_SUCCES) { - return TEST_RESULT_FAILED; + if (test_vector2_fp32_modulus() != TEST_SUCCES) { + return TEST_FAILED; } - if (test_vector2_add_fp32() != TEST_RESULT_SUCCES) { - return TEST_RESULT_FAILED; + if (test_vector2_add_fp32() != TEST_SUCCES) { + return TEST_FAILED; } - if (test_vector2_subtract_fp32() != TEST_RESULT_SUCCES) { - return TEST_RESULT_FAILED; + if (test_vector2_subtract_fp32() != TEST_SUCCES) { + return TEST_FAILED; } - return TEST_RESULT_SUCCES; + return TEST_SUCCES; } +*/ \ No newline at end of file diff --git a/basic-geometry-test/fp32_vector2_test.h b/basic-geometry-test/tests/vector2.h similarity index 60% rename from basic-geometry-test/fp32_vector2_test.h rename to basic-geometry-test/tests/vector2.h index ad687a3..9980b6b 100644 --- a/basic-geometry-test/fp32_vector2_test.h +++ b/basic-geometry-test/tests/vector2.h @@ -1,8 +1,8 @@ -#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__ -#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__ - -#include "geometry_test.h" +#ifndef _TEST_VECTOR2_H_ +#define _TEST_VECTOR2_H_ +#include "./../helpers.h" +/* int test_fp32_vector2(); int test_vector2_fp32_square_modulus(); @@ -12,5 +12,5 @@ int test_vector2_fp32_modulus(); int test_vector2_add_fp32(); int test_vector2_subtract_fp32(); - +*/ #endif diff --git a/basic-geometry-test/tests/vector3.c b/basic-geometry-test/tests/vector3.c new file mode 100644 index 0000000..e69de29 diff --git a/basic-geometry-test/tests/vector3.h b/basic-geometry-test/tests/vector3.h new file mode 100644 index 0000000..21760e6 --- /dev/null +++ b/basic-geometry-test/tests/vector3.h @@ -0,0 +1 @@ +#include "../helpers.h" diff --git a/basic-geometry-test/tests/versor.c b/basic-geometry-test/tests/versor.c new file mode 100644 index 0000000..a545694 --- /dev/null +++ b/basic-geometry-test/tests/versor.c @@ -0,0 +1,78 @@ +#include "./versor.h" + +#include "./../helpers.h" + +int test_bgc_versor_reset() +{ + if (test_bgc_versor_reset_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_reset_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_bgc_versor_set_values() +{ + if (test_bgc_versor_set_values_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_set_values_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_bgc_versor_are_close() +{ + if (test_bgc_versor_are_close_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_are_close_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_bgc_versor_combine() +{ + if (test_bgc_versor_combine_fp32() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_combine_fp64() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} + +int test_versor() +{ + print_testing_section("BGC Versor"); + + if (test_bgc_versor_reset() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_set_values() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_are_close() != TEST_SUCCES) { + return TEST_FAILED; + } + + if (test_bgc_versor_combine() != TEST_SUCCES) { + return TEST_FAILED; + } + + return TEST_SUCCES; +} diff --git a/basic-geometry-test/tests/versor.h b/basic-geometry-test/tests/versor.h new file mode 100644 index 0000000..d3e0cfd --- /dev/null +++ b/basic-geometry-test/tests/versor.h @@ -0,0 +1,18 @@ +#ifndef _TEST_VERSOR_H_ +#define _TEST_VERSOR_H_ + +#include "./versor/versor_reset.h" +#include "./versor/versor_set_values.h" +#include "./versor/versor_are_close.h" + +int test_bgc_versor_reset(); + +int test_bgc_versor_set_values(); + +int test_bgc_versor_are_close(); + +int test_bgc_versor_combine(); + +int test_versor(); + +#endif diff --git a/basic-geometry-test/tests/versor/versor_are_close.c b/basic-geometry-test/tests/versor/versor_are_close.c new file mode 100644 index 0000000..5328d9c --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_are_close.c @@ -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; +} diff --git a/basic-geometry-test/tests/versor/versor_are_close.h b/basic-geometry-test/tests/versor/versor_are_close.h new file mode 100644 index 0000000..e61f107 --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_are_close.h @@ -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 diff --git a/basic-geometry-test/tests/versor/versor_combine.c b/basic-geometry-test/tests/versor/versor_combine.c new file mode 100644 index 0000000..9aa9f0f --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_combine.c @@ -0,0 +1,117 @@ +#include "./versor_combine.h" + +#include + +#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; +} diff --git a/basic-geometry-test/tests/versor/versor_combine.h b/basic-geometry-test/tests/versor/versor_combine.h new file mode 100644 index 0000000..a2fb779 --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_combine.h @@ -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 diff --git a/basic-geometry-test/tests/versor/versor_reset.c b/basic-geometry-test/tests/versor/versor_reset.c new file mode 100644 index 0000000..9019585 --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_reset.c @@ -0,0 +1,41 @@ +#include "./versor_reset.h" + +#include + +#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; +} diff --git a/basic-geometry-test/tests/versor/versor_reset.h b/basic-geometry-test/tests/versor/versor_reset.h new file mode 100644 index 0000000..7fca1fa --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_reset.h @@ -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 diff --git a/basic-geometry-test/tests/versor/versor_set_values.c b/basic-geometry-test/tests/versor/versor_set_values.c new file mode 100644 index 0000000..8eab851 --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_set_values.c @@ -0,0 +1,141 @@ +#include "./versor_set_values.h" + +#include + +#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; +} diff --git a/basic-geometry-test/tests/versor/versor_set_values.h b/basic-geometry-test/tests/versor/versor_set_values.h new file mode 100644 index 0000000..d0e8525 --- /dev/null +++ b/basic-geometry-test/tests/versor/versor_set_values.h @@ -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 diff --git a/basic-geometry/versor.h b/basic-geometry/versor.h index 99505f7..f0404fc 100644 --- a/basic-geometry/versor.h +++ b/basic-geometry/versor.h @@ -619,7 +619,7 @@ inline int bgc_versor_are_close_fp64(const BgcVersorFP64* versor1, const BgcVers const double dx2 = versor1->x2 - versor2->x2; const double dx3 = versor1->x3 - versor2->x3; - return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_SQUARE_EPSYLON_FP32; + return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_SQUARE_EPSYLON_FP64; } #endif