From 3805354611b7f0b6cb9185ce689974852dbb6940 Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Wed, 15 Jan 2025 15:08:12 +0700 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Geometry.workspace | 2 +- basic-geometry-dev/main.c | 38 +- basic-geometry-test/fp32_vector2_test.c | 32 +- basic-geometry-test/geometry_test.h | 12 +- basic-geometry/angle.c | 2 +- basic-geometry/angle.h | 342 +++++++++--------- basic-geometry/basic-geometry.cbp | 2 +- basic-geometry/basic-geometry.h | 6 +- basic-geometry/basic-geometry.vcxproj | 2 +- basic-geometry/basic-geometry.vcxproj.filters | 2 +- basic-geometry/basis.c | 2 +- basic-geometry/basis.h | 56 --- basic-geometry/matrix2x2.h | 168 ++++----- basic-geometry/matrix2x3.h | 128 +++---- basic-geometry/matrix3x2.h | 124 +++---- basic-geometry/matrix3x3.c | 24 +- basic-geometry/matrix3x3.h | 180 ++++----- basic-geometry/matrixes.c | 28 +- basic-geometry/matrixes.h | 54 +-- basic-geometry/quaternion.h | 162 +++++---- basic-geometry/rotation3.c | 4 +- basic-geometry/rotation3.h | 46 +-- basic-geometry/tangent.c | 4 +- basic-geometry/tangent.h | 158 ++++---- basic-geometry/utilities.h | 56 +++ basic-geometry/vector2.c | 40 +- basic-geometry/vector2.h | 230 ++++++------ basic-geometry/vector3.c | 40 +- basic-geometry/vector3.h | 286 ++++++--------- basic-geometry/versor.c | 44 +-- basic-geometry/versor.h | 194 +++++----- 31 files changed, 1213 insertions(+), 1255 deletions(-) delete mode 100644 basic-geometry/basis.h create mode 100644 basic-geometry/utilities.h diff --git a/Geometry.workspace b/Geometry.workspace index cd8d7cc..23e6315 100644 --- a/Geometry.workspace +++ b/Geometry.workspace @@ -1,10 +1,10 @@ - + diff --git a/basic-geometry-dev/main.c b/basic-geometry-dev/main.c index 3e20b09..d18ded7 100644 --- a/basic-geometry-dev/main.c +++ b/basic-geometry-dev/main.c @@ -10,9 +10,9 @@ #endif // _WINDOWS_ typedef struct { - versor_fp32_t versor1, versor2, result; + bgc_versor_fp32_t versor1, versor2, result; //matrix3x3_fp32_t matrix; - vector3_fp32_t vector1, vector2; + bgc_vector3_fp32_t vector1, vector2; } structure_fp32_t; structure_fp32_t* allocate_structures(const unsigned int amount) @@ -31,7 +31,7 @@ structure_fp32_t* make_structures(const unsigned int amount) const float multiplier = 2.0f / RAND_MAX; for (unsigned int i = 0; i < amount; i++) { - versor_set_values_fp32( + bgc_versor_set_values_fp32( rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, @@ -39,7 +39,7 @@ structure_fp32_t* make_structures(const unsigned int amount) &list[i].versor1 ); - versor_set_values_fp32( + bgc_versor_set_values_fp32( rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, @@ -47,49 +47,49 @@ structure_fp32_t* make_structures(const unsigned int amount) &list[i].versor2 ); - versor_reset_fp32(&list[i].result); + bgc_versor_reset_fp32(&list[i].result); //matrix3x3_set_to_identity_fp32(&list[i].matrix); - vector3_set_values_fp32( + bgc_vector3_set_values_fp32( rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, rand() * multiplier - 1.0f, &list[i].vector1 ); - vector3_reset_fp32(&list[i].vector2); + bgc_vector3_reset_fp32(&list[i].vector2); } return list; } -void print_versor_fp32(const versor_fp32_t* versor) +void print_versor_fp32(const bgc_versor_fp32_t* versor) { printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3); } -void print_versor_fp64(const versor_fp64_t* versor) +void print_versor_fp64(const bgc_versor_fp64_t* versor) { printf("Versor (%lf, %lf, %lf, %lf)\n", versor->s0, versor->x1, versor->x2, versor->x3); } -void print_vector_fp32(const vector3_fp32_t* vector) +void print_vector_fp32(const bgc_vector3_fp32_t* vector) { - printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, vector3_get_modulus_fp32(vector)); + printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bgc_vector3_get_modulus_fp32(vector)); } -void print_vector_fp64(const vector3_fp64_t* vector) +void print_vector_fp64(const bgc_vector3_fp64_t* vector) { - printf("(%lf, %lf, %lf) / %lf\n", vector->x1, vector->x2, vector->x3, vector3_get_modulus_fp64(vector)); + printf("(%lf, %lf, %lf) / %lf\n", vector->x1, vector->x2, vector->x3, bgc_vector3_get_modulus_fp64(vector)); } void item_work(structure_fp32_t* item) { - for (int j = 0; j < 1000; j++) { - versor_combine_fp32(&item->versor1, &item->versor2, &item->result); - versor_turn_vector_fp32(&item->result, &item->vector1, &item->vector2); - } + //for (int j = 0; j < 1000; j++) { + bgc_versor_combine_fp32(&item->versor1, &item->versor2, &item->result); + bgc_versor_turn_vector_fp32(&item->result, &item->vector1, &item->vector2); + //} } int main() @@ -125,8 +125,8 @@ int main() //for (int j = 0; j < 1000; j++) { item_work(list + i); //structure_fp32_t* item = list + i; - //versor_combine_fp32(&item->versor1, &item->versor2, &item->result); - //versor_turn_vector_fp32(&item->result, &item->vector1, &item->vector2); + //bgc_versor_combine_fp32(&item->versor1, &item->versor2, &item->result); + //bgc_versor_turn_vector_fp32(&item->result, &item->vector1, &item->vector2); //} } diff --git a/basic-geometry-test/fp32_vector2_test.c b/basic-geometry-test/fp32_vector2_test.c index 86c2189..bfb559e 100644 --- a/basic-geometry-test/fp32_vector2_test.c +++ b/basic-geometry-test/fp32_vector2_test.c @@ -2,7 +2,7 @@ const int TEST_FP32_VECTOR2_AMOUNT_1 = 5; -const vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1[] = { +const bgc_vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1[] = { { 3.0f, 4.0f }, { -3.0f, -4.0f }, { 10000.0f, -20000.0f }, @@ -10,7 +10,7 @@ const vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1[] = { { -123.5f, 3.7283f } }; -const vector2_fp32_t TEST_FP32_VECTOR2_COMMON_2[] = { +const bgc_vector2_fp32_t TEST_FP32_VECTOR2_COMMON_2[] = { { -3.0f, -4.0f }, { -3.0f, -4.0f }, { 0.002f, -0.05f }, @@ -29,9 +29,9 @@ int test_vector2_fp32_square_modulus() float square_modulus; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { - square_modulus = vector2_get_square_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_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_FP32_TWO_EPSYLON)) { + 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; } @@ -52,9 +52,9 @@ int test_vector2_fp32_modulus() float square_modulus; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { - square_modulus = vector2_get_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_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_FP32_EPSYLON)) { + if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i], TEST_BGC_EPSYLON_FP32)) { print_test_failed(); return TEST_RESULT_FAILED; } @@ -66,7 +66,7 @@ int test_vector2_fp32_modulus() // ===================== Add ==================== // -const vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1_2_SUM[] = { +const bgc_vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1_2_SUM[] = { { 0.0f, 0.0f }, { -6.0f, -8.0f }, { 10000.002f, -20000.05f }, @@ -78,13 +78,13 @@ int test_vector2_add_fp32() { print_test_name("vector2_fp32_t add"); - vector2_fp32_t vector; + bgc_vector2_fp32_t vector; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { - vector2_add_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector); + 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_FP32_EPSYLON) || - !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_FP32_EPSYLON)) { + 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; } @@ -96,7 +96,7 @@ int test_vector2_add_fp32() // ================== Subtract ================== // -const vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1_2_DIFF[] = { +const bgc_vector2_fp32_t TEST_FP32_VECTOR2_COMMON_1_2_DIFF[] = { { 6.0f, 8.0f }, { 0.0f, 0.0f }, { 9999.998f, -19999.95f }, @@ -108,13 +108,13 @@ int test_vector2_subtract_fp32() { print_test_name("vector2_fp32_t subtract"); - vector2_fp32_t vector; + bgc_vector2_fp32_t vector; for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) { - vector2_subtract_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector); + 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_FP32_EPSYLON) || - !test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_FP32_EPSYLON)) { + 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; } diff --git a/basic-geometry-test/geometry_test.h b/basic-geometry-test/geometry_test.h index 689940b..a806b6f 100644 --- a/basic-geometry-test/geometry_test.h +++ b/basic-geometry-test/geometry_test.h @@ -6,13 +6,13 @@ #define TEST_RESULT_SUCCES 0 #define TEST_RESULT_FAILED 100 -#define TEST_FP32_EPSYLON 1E-6f -#define TEST_FP32_TWO_EPSYLON 2E-6f -#define TEST_FP32_SQUARE_EPSYLON 1E-12f +#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_FP64_EPSYLON 1E-13f -#define TEST_FP64_TWO_EPSYLON 2E-13f -#define TEST_FP64_SQUARE_EPSYLON 1E-26f +#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); diff --git a/basic-geometry/angle.c b/basic-geometry/angle.c index b7b0313..ca211e5 100644 --- a/basic-geometry/angle.c +++ b/basic-geometry/angle.c @@ -1,3 +1,3 @@ -#include "basis.h" +#include "utilities.h" #include "angle.h" diff --git a/basic-geometry/angle.h b/basic-geometry/angle.h index aa7f05c..b0fab1a 100644 --- a/basic-geometry/angle.h +++ b/basic-geometry/angle.h @@ -1,102 +1,102 @@ -#ifndef _BASIC_GEOMETRY_ANGLE_H_ -#define _BASIC_GEOMETRY_ANGLE_H_ +#ifndef _BGC_ANGLE_H_ +#define _BGC_ANGLE_H_ #include -#include "basis.h" +#include "utilities.h" -#define FP32_PI 3.1415926536f -#define FP32_TWO_PI 6.2831853072f -#define FP32_HALF_OF_PI 1.5707963268f -#define FP32_THIRD_OF_PI 1.0471975512f -#define FP32_FOURTH_OF_PI 0.7853981634f -#define FP32_SIXTH_OF_PI 0.5235987756f +#define BGC_PI_FP32 3.1415926536f +#define BGC_TWO_PI_FP32 6.2831853072f +#define BGC_HALF_OF_PI_FP32 1.5707963268f +#define BGC_THIRD_OF_PI_FP32 1.0471975512f +#define BGC_FOURTH_OF_PI_FP32 0.7853981634f +#define BGC_SIXTH_OF_PI_FP32 0.5235987756f -#define FP32_DEGREES_IN_RADIAN 57.295779513f -#define FP32_TURNS_IN_RADIAN 0.1591549431f -#define FP32_RADIANS_IN_DEGREE 1.745329252E-2f -#define FP32_TURNS_IN_DEGREE 2.7777777778E-3f +#define BGC_DEGREES_IN_RADIAN_FP32 57.295779513f +#define BGC_TURNS_IN_RADIAN_FP32 0.1591549431f +#define BGC_RADIANS_IN_DEGREE_FP32 1.745329252E-2f +#define BGC_TURNS_IN_DEGREE_FP32 2.7777777778E-3f -#define FP64_PI 3.14159265358979324 -#define FP64_TWO_PI 6.28318530717958648 -#define FP64_HALF_OF_PI 1.57079632679489662 -#define FP64_THIRD_OF_PI 1.04719755119659775 -#define FP64_FOURTH_OF_PI 0.78539816339744831 -#define FP64_SIXTH_OF_PI 0.523598775598298873 +#define BGC_PI_FP64 3.14159265358979324 +#define BGC_TWO_PI_FP64 6.28318530717958648 +#define BGC_HALF_OF_PI_FP64 1.57079632679489662 +#define BGC_THIRD_OF_PI_FP64 1.04719755119659775 +#define BGC_FOURTH_OF_PI_FP64 0.78539816339744831 +#define BGC_SIXTH_OF_PI_FP64 0.523598775598298873 -#define FP64_DEGREES_IN_RADIAN 57.2957795130823209 -#define FP64_TURNS_IN_RADIAN 0.159154943091895336 -#define FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2 -#define FP64_TURNS_IN_DEGREE 2.77777777777777778E-3 +#define BGC_DEGREES_IN_RADIAN_FP64 57.2957795130823209 +#define BGC_TURNS_IN_RADIAN_FP64 0.159154943091895336 +#define BGC_RADIANS_IN_DEGREE_FP64 1.74532925199432958E-2 +#define BGC_TURNS_IN_DEGREE_FP64 2.77777777777777778E-3 typedef enum { - BG_ANGLE_UNIT_RADIANS = 1, - BG_ANGLE_UNIT_DEGREES = 2, - BG_ANGLE_UNIT_TURNS = 3 -} angle_unit_t; + BGC_ANGLE_UNIT_RADIANS = 1, + BGC_ANGLE_UNIT_DEGREES = 2, + BGC_ANGLE_UNIT_TURNS = 3 +} bgc_angle_unit_t; typedef enum { /** * The measure of an angle with a range of: * [0, 360) degrees, [0, 2xPI) radians, [0, 1) turns, [0, 400) gradians */ - BG_ANGLE_RANGE_UNSIGNED = 1, + BGC_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 */ - BG_ANGLE_RANGE_SIGNED = 2 -} angle_range_t; + BGC_ANGLE_RANGE_SIGNED = 2 +} bgc_angle_range_t; // !================= Radians ==================! // // ========= Convert radians to degrees ========= // -inline float fp32_radians_to_degrees(const float radians) +inline float bgc_radians_to_degrees_fp32(const float radians) { - return radians * FP32_DEGREES_IN_RADIAN; + return radians * BGC_DEGREES_IN_RADIAN_FP32; } -inline double fp64_radians_to_degrees(const double radians) +inline double bgc_radians_to_degrees_fp64(const double radians) { - return radians * FP64_DEGREES_IN_RADIAN; + return radians * BGC_DEGREES_IN_RADIAN_FP64; } // ========== Convert radians to turns ========== // -inline float fp32_radians_to_turns(const float radians) +inline float bgc_radians_to_turns_fp32(const float radians) { - return radians * FP32_TURNS_IN_RADIAN; + return radians * BGC_TURNS_IN_RADIAN_FP32; } -inline double fp64_radians_to_turns(const double radians) +inline double bgc_radians_to_turns_fp64(const double radians) { - return radians * FP64_TURNS_IN_RADIAN; + return radians * BGC_TURNS_IN_RADIAN_FP64; } // ========= Convert radians to any unit ======== // -inline float fp32_radians_to_units(const float radians, const angle_unit_t to_unit) +inline float bgc_radians_to_units_fp32(const float radians, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_DEGREES) { - return radians * FP32_DEGREES_IN_RADIAN; + if (to_unit == BGC_ANGLE_UNIT_DEGREES) { + return radians * BGC_DEGREES_IN_RADIAN_FP32; } - if (to_unit == BG_ANGLE_UNIT_TURNS) { - return radians * FP32_TURNS_IN_RADIAN; + if (to_unit == BGC_ANGLE_UNIT_TURNS) { + return radians * BGC_TURNS_IN_RADIAN_FP32; } return radians; } -inline double fp64_radians_to_units(const double radians, const angle_unit_t to_unit) +inline double bgc_radians_to_units_fp64(const double radians, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_DEGREES) { - return radians * FP64_DEGREES_IN_RADIAN; + if (to_unit == BGC_ANGLE_UNIT_DEGREES) { + return radians * BGC_DEGREES_IN_RADIAN_FP64; } - if (to_unit == BG_ANGLE_UNIT_TURNS) { - return radians * FP64_TURNS_IN_RADIAN; + if (to_unit == BGC_ANGLE_UNIT_TURNS) { + return radians * BGC_TURNS_IN_RADIAN_FP64; } return radians; @@ -104,103 +104,103 @@ inline double fp64_radians_to_units(const double radians, const angle_unit_t to_ // ============ Normalize radians ============= // -inline float fp32_radians_normalize(const float radians, const angle_range_t range) +inline float bgc_radians_normalize_fp32(const float radians, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { - if (0.0f <= radians && radians < FP32_TWO_PI) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { + if (0.0f <= radians && radians < BGC_TWO_PI_FP32) { return radians; } } else { - if (-FP32_PI < radians && radians <= FP32_PI) { + if (-BGC_PI_FP32 < radians && radians <= BGC_PI_FP32) { return radians; } } - float turns = radians * FP32_TURNS_IN_RADIAN; + float turns = radians * BGC_TURNS_IN_RADIAN_FP32; turns -= floorf(turns); - if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) { + if (range == BGC_ANGLE_RANGE_SIGNED && turns > 0.5f) { turns -= 1.0f; } - return turns * FP32_TWO_PI; + return turns * BGC_TWO_PI_FP32; } -inline double fp64_radians_normalize(const double radians, const angle_range_t range) +inline double bgc_radians_normalize_fp64(const double radians, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { - if (0.0 <= radians && radians < FP64_TWO_PI) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { + if (0.0 <= radians && radians < BGC_TWO_PI_FP64) { return radians; } } else { - if (-FP64_PI < radians && radians <= FP64_PI) { + if (-BGC_PI_FP64 < radians && radians <= BGC_PI_FP64) { return radians; } } - double turns = radians * FP64_TURNS_IN_RADIAN; + double turns = radians * BGC_TURNS_IN_RADIAN_FP64; turns -= floor(turns); - if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) { + if (range == BGC_ANGLE_RANGE_SIGNED && turns > 0.5) { turns -= 1.0; } - return turns * FP64_TWO_PI; + return turns * BGC_TWO_PI_FP64; } // !================= Degrees ==================! // // ========= Convert degrees to radians ========= // -inline float fp32_degrees_to_radians(const float degrees) +inline float bgc_degrees_to_radians_fp32(const float degrees) { - return degrees * FP32_RADIANS_IN_DEGREE; + return degrees * BGC_RADIANS_IN_DEGREE_FP32; } -inline double fp64_degrees_to_radians(const double degrees) +inline double bgc_degrees_to_radians_fp64(const double degrees) { - return degrees * FP64_RADIANS_IN_DEGREE; + return degrees * BGC_RADIANS_IN_DEGREE_FP64; } // ========== Convert degrees to turns ========== // -inline float fp32_degrees_to_turns(const float radians) +inline float bgc_degrees_to_turns_fp32(const float radians) { - return radians * FP32_TURNS_IN_DEGREE; + return radians * BGC_TURNS_IN_DEGREE_FP32; } inline double fp64_degrees_to_turns(const double radians) { - return radians * FP64_TURNS_IN_DEGREE; + return radians * BGC_TURNS_IN_DEGREE_FP64; } // ========= Convert degreess to any unit ======== // -inline float fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit) +inline float bgc_degrees_to_units_fp32(const float degrees, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_RADIANS) { - return degrees * FP32_RADIANS_IN_DEGREE; + if (to_unit == BGC_ANGLE_UNIT_RADIANS) { + return degrees * BGC_RADIANS_IN_DEGREE_FP32; } - if (to_unit == BG_ANGLE_UNIT_TURNS) { - return degrees * FP32_TURNS_IN_DEGREE; + if (to_unit == BGC_ANGLE_UNIT_TURNS) { + return degrees * BGC_TURNS_IN_DEGREE_FP32; } return degrees; } -inline double fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit) +inline double bgc_degrees_to_units_fp64(const double degrees, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_RADIANS) { - return degrees * FP64_RADIANS_IN_DEGREE; + if (to_unit == BGC_ANGLE_UNIT_RADIANS) { + return degrees * BGC_RADIANS_IN_DEGREE_FP64; } - if (to_unit == BG_ANGLE_UNIT_TURNS) { - return degrees * FP64_TURNS_IN_DEGREE; + if (to_unit == BGC_ANGLE_UNIT_TURNS) { + return degrees * BGC_TURNS_IN_DEGREE_FP64; } return degrees; @@ -208,9 +208,9 @@ inline double fp64_degrees_to_units(const double degrees, const angle_unit_t to_ // ============ Normalize degrees ============= // -inline float fp32_degrees_normalize(const float degrees, const angle_range_t range) +inline float bgc_degrees_normalize_fp32(const float degrees, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { if (0.0f <= degrees && degrees < 360.0f) { return degrees; } @@ -221,20 +221,20 @@ inline float fp32_degrees_normalize(const float degrees, const angle_range_t ran } } - float turns = degrees * FP32_TURNS_IN_DEGREE; + float turns = degrees * BGC_TURNS_IN_DEGREE_FP32; turns -= floorf(turns); - if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) { + if (range == BGC_ANGLE_RANGE_SIGNED && turns > 0.5f) { turns -= 1.0f; } return turns * 360.0f; } -inline double fp64_degrees_normalize(const double degrees, const angle_range_t range) +inline double bgc_degrees_normalize_fp64(const double degrees, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { if (0.0 <= degrees && degrees < 360.0) { return degrees; } @@ -245,11 +245,11 @@ inline double fp64_degrees_normalize(const double degrees, const angle_range_t r } } - double turns = degrees * FP64_TURNS_IN_DEGREE; + double turns = degrees * BGC_TURNS_IN_DEGREE_FP64; turns -= floor(turns); - if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) { + if (range == BGC_ANGLE_RANGE_SIGNED && turns > 0.5) { turns -= 1.0; } @@ -260,50 +260,50 @@ inline double fp64_degrees_normalize(const double degrees, const angle_range_t r // ========== Convert turns to radians ========== // -inline float fp32_turns_to_radians(const float turns) +inline float bgc_turns_to_radians_fp32(const float turns) { - return turns * FP32_TWO_PI; + return turns * BGC_TWO_PI_FP32; } -inline double fp64_turns_to_radians(const double turns) +inline double bgc_turns_to_radians_fp64(const double turns) { - return turns * FP64_TWO_PI; + return turns * BGC_TWO_PI_FP64; } // ========== Convert turns to degrees ========== // -inline float fp32_turns_to_degrees(const float turns) +inline float bgc_turns_to_degrees_fp32(const float turns) { return turns * 360.0f; } -inline double fp64_turns_to_degrees(const double turns) +inline double bgc_turns_to_degrees_fp64(const double turns) { return turns * 360.0; } // ========= Convert turns to any unit ======== // -inline float fp32_turns_to_units(const float turns, const angle_unit_t to_unit) +inline float bgc_turns_to_units_fp32(const float turns, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_RADIANS) { - return turns * FP32_TWO_PI; + if (to_unit == BGC_ANGLE_UNIT_RADIANS) { + return turns * BGC_TWO_PI_FP32; } - if (to_unit == BG_ANGLE_UNIT_DEGREES) { + if (to_unit == BGC_ANGLE_UNIT_DEGREES) { return turns * 360.0f; } return turns; } -inline double fp64_turns_to_units(const double turns, const angle_unit_t to_unit) +inline double bgc_turns_to_units_fp64(const double turns, const bgc_angle_unit_t to_unit) { - if (to_unit == BG_ANGLE_UNIT_RADIANS) { - return turns * FP64_TWO_PI; + if (to_unit == BGC_ANGLE_UNIT_RADIANS) { + return turns * BGC_TWO_PI_FP64; } - if (to_unit == BG_ANGLE_UNIT_DEGREES) { + if (to_unit == BGC_ANGLE_UNIT_DEGREES) { return turns * 360.0; } @@ -312,9 +312,9 @@ inline double fp64_turns_to_units(const double turns, const angle_unit_t to_unit // ============= Normalize turns ============== // -inline float fp32_turns_normalize(const float turns, const angle_range_t range) +inline float bgc_turns_normalize_fp32(const float turns, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { if (0.0f <= turns && turns < 1.0f) { return turns; } @@ -327,16 +327,16 @@ inline float fp32_turns_normalize(const float turns, const angle_range_t range) float rest = turns - floorf(turns); - if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5f) { + if (range == BGC_ANGLE_RANGE_SIGNED && rest > 0.5f) { return rest - 1.0f; } return rest; } -inline double fp64_turns_normalize(const double turns, const angle_range_t range) +inline double bgc_turns_normalize_fp64(const double turns, const bgc_angle_range_t range) { - if (range == BG_ANGLE_RANGE_UNSIGNED) { + if (range == BGC_ANGLE_RANGE_UNSIGNED) { if (0.0 <= turns && turns < 1.0) { return turns; } @@ -349,7 +349,7 @@ inline double fp64_turns_normalize(const double turns, const angle_range_t range double rest = turns - floor(turns); - if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5) { + if (range == BGC_ANGLE_RANGE_SIGNED && rest > 0.5) { return rest - 1.0; } @@ -360,27 +360,27 @@ inline double fp64_turns_normalize(const double turns, const angle_range_t range // ========= Convert any unit to radians ======== // -inline float fp32_angle_to_radians(const float angle, const angle_unit_t unit) +inline float bgc_angle_to_radians_fp32(const float angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { - return angle * FP32_RADIANS_IN_DEGREE; + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return angle * BGC_RADIANS_IN_DEGREE_FP32; } - if (unit == BG_ANGLE_UNIT_TURNS) { - return angle * FP32_TWO_PI; + if (unit == BGC_ANGLE_UNIT_TURNS) { + return angle * BGC_TWO_PI_FP32; } return angle; } -inline double fp64_angle_to_radians(const double angle, const angle_unit_t unit) +inline double bgc_angle_to_radians_fp64(const double angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { - return angle * FP64_RADIANS_IN_DEGREE; + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return angle * BGC_RADIANS_IN_DEGREE_FP64; } - if (unit == BG_ANGLE_UNIT_TURNS) { - return angle * FP64_TWO_PI; + if (unit == BGC_ANGLE_UNIT_TURNS) { + return angle * BGC_TWO_PI_FP64; } return angle; @@ -388,26 +388,26 @@ inline double fp64_angle_to_radians(const double angle, const angle_unit_t unit) // ========= Convert any unit to degreess ======== // -inline float fp32_angle_to_degrees(const float angle, const angle_unit_t unit) +inline float bgc_angle_to_degrees_fp32(const float angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_RADIANS) { - return angle * FP32_DEGREES_IN_RADIAN; + if (unit == BGC_ANGLE_UNIT_RADIANS) { + return angle * BGC_DEGREES_IN_RADIAN_FP32; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return angle * 360.0f; } return angle; } -inline double fp64_angle_to_degrees(const double angle, const angle_unit_t unit) +inline double bgc_angle_to_degrees_fp64(const double angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_RADIANS) { - return angle * FP64_DEGREES_IN_RADIAN; + if (unit == BGC_ANGLE_UNIT_RADIANS) { + return angle * BGC_DEGREES_IN_RADIAN_FP64; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return angle * 360.0; } @@ -416,27 +416,27 @@ inline double fp64_angle_to_degrees(const double angle, const angle_unit_t unit) // ========= Convert any unit to turns ======== // -inline float fp32_angle_to_turns(const float angle, const angle_unit_t unit) +inline float bgc_angle_to_turns_fp32(const float angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_RADIANS) { - return angle * FP32_TURNS_IN_RADIAN; + if (unit == BGC_ANGLE_UNIT_RADIANS) { + return angle * BGC_TURNS_IN_RADIAN_FP32; } - if (unit == BG_ANGLE_UNIT_DEGREES) { - return angle * FP32_TURNS_IN_DEGREE; + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return angle * BGC_TURNS_IN_DEGREE_FP32; } return angle; } -inline double fp64_angle_to_turns(const double angle, const angle_unit_t unit) +inline double bgc_angle_to_turns_fp64(const double angle, const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_RADIANS) { - return angle * FP64_TURNS_IN_RADIAN; + if (unit == BGC_ANGLE_UNIT_RADIANS) { + return angle * BGC_TURNS_IN_RADIAN_FP64; } - if (unit == BG_ANGLE_UNIT_DEGREES) { - return angle * FP64_TURNS_IN_DEGREE; + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return angle * BGC_TURNS_IN_DEGREE_FP64; } return angle; @@ -444,114 +444,114 @@ inline double fp64_angle_to_turns(const double angle, const angle_unit_t unit) // ============= Get Full Circle ============== // -inline float fp32_angle_get_full_circle(const angle_unit_t unit) +inline float bgc_angle_get_full_circle_fp32(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 360.0f; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 1.0f; } - return FP32_TWO_PI; + return BGC_TWO_PI_FP32; } -inline double fp64_angle_get_full_circle(const angle_unit_t unit) +inline double bgc_angle_get_full_circle_fp64(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 360.0; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 1.0; } - return FP64_TWO_PI; + return BGC_TWO_PI_FP64; } // ============= Get Half Circle ============== // -inline float fp32_angle_get_half_circle(const angle_unit_t unit) +inline float bgc_angle_get_half_circle_fp32(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 180.0f; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 0.5f; } - return FP32_PI; + return BGC_PI_FP32; } -inline double fp64_angle_get_half_circle(const angle_unit_t unit) +inline double bgc_angle_get_half_circle_fp64(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 180.0; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 0.5; } - return FP64_PI; + return BGC_PI_FP64; } // ============= Get Half Circle ============== // -inline float fp32_angle_get_quater_circle(const angle_unit_t unit) +inline float bgc_angle_get_quater_circle_fp32(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 90.0f; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 0.25f; } - return FP32_HALF_OF_PI; + return BGC_HALF_OF_PI_FP32; } -inline double fp64_angle_get_quater_circle(const angle_unit_t unit) +inline double bgc_angle_get_quater_circle_fp64(const bgc_angle_unit_t unit) { - if (unit == BG_ANGLE_UNIT_DEGREES) { + if (unit == BGC_ANGLE_UNIT_DEGREES) { return 90.0; } - if (unit == BG_ANGLE_UNIT_TURNS) { + if (unit == BGC_ANGLE_UNIT_TURNS) { return 0.25; } - return FP64_HALF_OF_PI; + return BGC_HALF_OF_PI_FP64; } // ================ Normalize ================= // -inline float fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range) +inline float bgc_angle_normalize_fp32(const float angle, const bgc_angle_unit_t unit, const bgc_angle_range_t range) { - if (unit == BG_ANGLE_UNIT_DEGREES) { - return fp32_degrees_normalize(angle, range); + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return bgc_degrees_normalize_fp32(angle, range); } - if (unit == BG_ANGLE_UNIT_TURNS) { - return fp32_turns_normalize(angle, range); + if (unit == BGC_ANGLE_UNIT_TURNS) { + return bgc_turns_normalize_fp32(angle, range); } - return fp32_radians_normalize(angle, range); + return bgc_radians_normalize_fp32(angle, range); } -inline double fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range) +inline double bgc_angle_normalize_fp64(const double angle, const bgc_angle_unit_t unit, const bgc_angle_range_t range) { - if (unit == BG_ANGLE_UNIT_DEGREES) { - return fp64_degrees_normalize(angle, range); + if (unit == BGC_ANGLE_UNIT_DEGREES) { + return bgc_degrees_normalize_fp64(angle, range); } - if (unit == BG_ANGLE_UNIT_TURNS) { - return fp64_turns_normalize(angle, range); + if (unit == BGC_ANGLE_UNIT_TURNS) { + return bgc_turns_normalize_fp64(angle, range); } - return fp64_radians_normalize(angle, range); + return bgc_radians_normalize_fp64(angle, range); } #endif diff --git a/basic-geometry/basic-geometry.cbp b/basic-geometry/basic-geometry.cbp index d128ff0..1bd5c8a 100644 --- a/basic-geometry/basic-geometry.cbp +++ b/basic-geometry/basic-geometry.cbp @@ -51,7 +51,6 @@ - @@ -78,6 +77,7 @@ + diff --git a/basic-geometry/basic-geometry.h b/basic-geometry/basic-geometry.h index 17d93f7..7a608d8 100644 --- a/basic-geometry/basic-geometry.h +++ b/basic-geometry/basic-geometry.h @@ -1,7 +1,7 @@ -#ifndef __GEOMETRY_H__ -#define __GEOMETRY_H__ +#ifndef _BGC_H_ +#define _BGC_H_ -#include "basis.h" +#include "utilities.h" #include "angle.h" diff --git a/basic-geometry/basic-geometry.vcxproj b/basic-geometry/basic-geometry.vcxproj index 7506257..cbfdc92 100644 --- a/basic-geometry/basic-geometry.vcxproj +++ b/basic-geometry/basic-geometry.vcxproj @@ -20,7 +20,6 @@ - @@ -30,6 +29,7 @@ + diff --git a/basic-geometry/basic-geometry.vcxproj.filters b/basic-geometry/basic-geometry.vcxproj.filters index 8637611..04a1c12 100644 --- a/basic-geometry/basic-geometry.vcxproj.filters +++ b/basic-geometry/basic-geometry.vcxproj.filters @@ -18,7 +18,7 @@ Файлы заголовков - + Файлы заголовков diff --git a/basic-geometry/basis.c b/basic-geometry/basis.c index 03a9af7..901ca29 100644 --- a/basic-geometry/basis.c +++ b/basic-geometry/basis.c @@ -1,2 +1,2 @@ -#include "basis.h" +#include "utilities.h" diff --git a/basic-geometry/basis.h b/basic-geometry/basis.h deleted file mode 100644 index 67f50a3..0000000 --- a/basic-geometry/basis.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _GEOMETRY_BASIS_H_ -#define _GEOMETRY_BASIS_H_ - -#define FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f - -#define FP32_EPSYLON 5E-7f -#define FP32_TWO_EPSYLON 1E-6f -#define FP32_SQUARE_EPSYLON 2.5E-13f - -#define FP32_ONE_THIRD 0.333333333f -#define FP32_ONE_SIXTH 0.166666667f -#define FP32_ONE_NINETH 0.111111111f - -#define FP32_GOLDEN_RATIO_HIGH 1.618034f -#define FP32_GOLDEN_RATIO_LOW 0.618034f - -#define FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0 - -#define FP64_EPSYLON 5E-14 -#define FP64_TWO_EPSYLON 1E-13 -#define FP64_SQUARE_EPSYLON 2.5E-27 - -#define FP64_ONE_THIRD 0.333333333333333333 -#define FP64_ONE_SIXTH 0.166666666666666667 -#define FP64_ONE_NINETH 0.111111111111111111 - -#define FP64_GOLDEN_RATIO_HIGH 1.61803398874989485 -#define FP64_GOLDEN_RATIO_LOW 0.61803398874989485 - -inline int fp32_are_equal(const float value1, const float value2) -{ - if (-FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) { - return -FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP32_EPSYLON; - } - - if (value1 < 0.0f) { - return (1.0f + FP32_EPSYLON) * value2 <= value1 && (1.0f + FP32_EPSYLON) * value1 <= value2; - } - - return value2 <= value1 * (1.0f + FP32_EPSYLON) && value1 <= value2 * (1.0f + FP32_EPSYLON); -} - -inline int fp64_are_equal(const double value1, const double value2) -{ - if (-FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) { - return -FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP64_EPSYLON; - } - - if (value1 < 0.0) { - return (1.0 + FP64_EPSYLON) * value2 <= value1 && (1.0 + FP64_EPSYLON) * value1 <= value2; - } - - return value2 <= value1 * (1.0 + FP64_EPSYLON) && value1 <= value2 * (1.0 + FP64_EPSYLON); -} - -#endif diff --git a/basic-geometry/matrix2x2.h b/basic-geometry/matrix2x2.h index 80954ef..0fd9db4 100644 --- a/basic-geometry/matrix2x2.h +++ b/basic-geometry/matrix2x2.h @@ -1,5 +1,5 @@ -#ifndef _BASIC_GEOMETRY_MATRIX2X2_H_ -#define _BASIC_GEOMETRY_MATRIX2X2_H_ +#ifndef _BGC_MATRIX2X2_H_ +#define _BGC_MATRIX2X2_H_ #include "angle.h" #include "vector2.h" @@ -7,7 +7,7 @@ // =================== Reset ==================== // -inline void matrix2x2_reset_fp32(matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_reset_fp32(bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = 0.0f; matrix->r1c2 = 0.0f; @@ -15,7 +15,7 @@ inline void matrix2x2_reset_fp32(matrix2x2_fp32_t* matrix) matrix->r2c2 = 0.0f; } -inline void matrix2x2_reset_fp64(matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_reset_fp64(bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = 0.0; matrix->r1c2 = 0.0; @@ -25,7 +25,7 @@ inline void matrix2x2_reset_fp64(matrix2x2_fp64_t* matrix) // ================== Identity ================== // -inline void matrix2x2_set_to_identity_fp32(matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_to_identity_fp32(bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = 1.0f; matrix->r1c2 = 0.0f; @@ -33,7 +33,7 @@ inline void matrix2x2_set_to_identity_fp32(matrix2x2_fp32_t* matrix) matrix->r2c2 = 1.0f; } -inline void matrix2x2_set_to_identity_fp64(matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_to_identity_fp64(bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = 1.0; matrix->r1c2 = 0.0; @@ -43,7 +43,7 @@ inline void matrix2x2_set_to_identity_fp64(matrix2x2_fp64_t* matrix) // ================ Make Diagonal =============== // -inline void matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = d1; matrix->r1c2 = 0.0f; @@ -51,7 +51,7 @@ inline void matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, matri matrix->r2c2 = d2; } -inline void matrix2x2_set_to_diagonal_fp64(const double d1, const double d2, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_to_diagonal_fp64(const double d1, const double d2, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = d1; matrix->r1c2 = 0.0; @@ -61,9 +61,9 @@ inline void matrix2x2_set_to_diagonal_fp64(const double d1, const double d2, mat // ============== Rotation Matrix =============== // -inline void matrix2x2_make_rotation_fp32(const float angle, const angle_unit_t unit, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_make_rotation_fp32(const float angle, const bgc_angle_unit_t unit, bgc_matrix2x2_fp32_t* matrix) { - const float radians = fp32_angle_to_radians(angle, unit); + const float radians = bgc_angle_to_radians_fp32(angle, unit); const float cosine = cosf(radians); const float sine = sinf(radians); @@ -73,9 +73,9 @@ inline void matrix2x2_make_rotation_fp32(const float angle, const angle_unit_t u matrix->r2c2 = cosine; } -inline void matrix2x2_make_rotation_fp64(const double angle, const angle_unit_t unit, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_make_rotation_fp64(const double angle, const bgc_angle_unit_t unit, bgc_matrix2x2_fp64_t* matrix) { - const double radians = fp64_angle_to_radians(angle, unit); + const double radians = bgc_angle_to_radians_fp64(angle, unit); const double cosine = cos(radians); const double sine = sin(radians); @@ -87,7 +87,7 @@ inline void matrix2x2_make_rotation_fp64(const double angle, const angle_unit_t // ==================== Copy ==================== // -inline void matrix2x2_copy_fp32(const matrix2x2_fp32_t* from, matrix2x2_fp32_t* to) +inline void bgc_matrix2x2_copy_fp32(const bgc_matrix2x2_fp32_t* from, bgc_matrix2x2_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -96,7 +96,7 @@ inline void matrix2x2_copy_fp32(const matrix2x2_fp32_t* from, matrix2x2_fp32_t* to->r2c2 = from->r2c2; } -inline void matrix2x2_copy_fp64(const matrix2x2_fp64_t* from, matrix2x2_fp64_t* to) +inline void bgc_matrix2x2_copy_fp64(const bgc_matrix2x2_fp64_t* from, bgc_matrix2x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -107,7 +107,7 @@ inline void matrix2x2_copy_fp64(const matrix2x2_fp64_t* from, matrix2x2_fp64_t* // ==================== Swap ==================== // -inline void matrix2x2_swap_fp32(matrix2x2_fp32_t* matrix1, matrix2x2_fp32_t* matrix2) +inline void bgc_matrix2x2_swap_fp32(bgc_matrix2x2_fp32_t* matrix1, bgc_matrix2x2_fp32_t* matrix2) { const float r1c1 = matrix2->r1c1; const float r1c2 = matrix2->r1c2; @@ -128,7 +128,7 @@ inline void matrix2x2_swap_fp32(matrix2x2_fp32_t* matrix1, matrix2x2_fp32_t* mat matrix1->r2c2 = r2c2; } -inline void matrix2x2_swap_fp64(matrix2x2_fp64_t* matrix1, matrix2x2_fp64_t* matrix2) +inline void bgc_matrix2x2_swap_fp64(bgc_matrix2x2_fp64_t* matrix1, bgc_matrix2x2_fp64_t* matrix2) { const double r1c1 = matrix2->r1c1; const double r1c2 = matrix2->r1c2; @@ -151,7 +151,7 @@ inline void matrix2x2_swap_fp64(matrix2x2_fp64_t* matrix1, matrix2x2_fp64_t* mat // ============= Copy to twin type ============== // -inline void matrix2x2_convert_fp64_to_fp32(const matrix2x2_fp64_t* from, matrix2x2_fp32_t* to) +inline void bgc_matrix2x2_convert_fp64_to_fp32(const bgc_matrix2x2_fp64_t* from, bgc_matrix2x2_fp32_t* to) { to->r1c1 = (float)from->r1c1; to->r1c2 = (float)from->r1c2; @@ -160,7 +160,7 @@ inline void matrix2x2_convert_fp64_to_fp32(const matrix2x2_fp64_t* from, matrix2 to->r2c2 = (float)from->r2c2; } -inline void matrix2x2_convert_fp32_to_fp64(const matrix2x2_fp32_t* from, matrix2x2_fp64_t* to) +inline void bgc_matrix2x2_convert_fp32_to_fp64(const bgc_matrix2x2_fp32_t* from, bgc_matrix2x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -171,42 +171,42 @@ inline void matrix2x2_convert_fp32_to_fp64(const matrix2x2_fp32_t* from, matrix2 // ================ Determinant ================= // -inline float matrix2x2_get_determinant_fp32(const matrix2x2_fp32_t* matrix) +inline float bgc_matrix2x2_get_determinant_fp32(const bgc_matrix2x2_fp32_t* matrix) { return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1; } -inline double matrix2x2_get_determinant_fp64(const matrix2x2_fp64_t* matrix) +inline double bgc_matrix2x2_get_determinant_fp64(const bgc_matrix2x2_fp64_t* matrix) { return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1; } // ================== Singular ================== // -inline int matrix2x2_is_singular_fp32(const matrix2x2_fp32_t* matrix) +inline int bgc_matrix2x2_is_singular_fp32(const bgc_matrix2x2_fp32_t* matrix) { - const float determinant = matrix2x2_get_determinant_fp32(matrix); + const float determinant = bgc_matrix2x2_get_determinant_fp32(matrix); - return -FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON; + return -BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32; } -inline int matrix2x2_is_singular_fp64(const matrix2x2_fp64_t* matrix) +inline int bgc_matrix2x2_is_singular_fp64(const bgc_matrix2x2_fp64_t* matrix) { - const double determinant = matrix2x2_get_determinant_fp64(matrix); + const double determinant = bgc_matrix2x2_get_determinant_fp64(matrix); - return -FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON; + return -BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64; } // =============== Transposition ================ // -inline void matrix2x2_transpose_fp32(matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_transpose_fp32(bgc_matrix2x2_fp32_t* matrix) { const float tmp = matrix->r1c2; matrix->r1c2 = matrix->r2c1; matrix->r2c1 = tmp; } -inline void matrix2x2_transpose_fp64(matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_transpose_fp64(bgc_matrix2x2_fp64_t* matrix) { const double tmp = matrix->r1c2; matrix->r1c2 = matrix->r2c1; @@ -215,11 +215,11 @@ inline void matrix2x2_transpose_fp64(matrix2x2_fp64_t* matrix) // ================= Inversion ================== // -inline int matrix2x2_invert_fp32(matrix2x2_fp32_t* matrix) +inline int bgc_matrix2x2_invert_fp32(bgc_matrix2x2_fp32_t* matrix) { - const float determinant = matrix2x2_get_determinant_fp32(matrix); + const float determinant = bgc_matrix2x2_get_determinant_fp32(matrix); - if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) { + if (-BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32) { return 0; } @@ -240,11 +240,11 @@ inline int matrix2x2_invert_fp32(matrix2x2_fp32_t* matrix) return 1; } -inline int matrix2x2_invert_fp64(matrix2x2_fp64_t* matrix) +inline int bgc_matrix2x2_invert_fp64(bgc_matrix2x2_fp64_t* matrix) { - const double determinant = matrix2x2_get_determinant_fp64(matrix); + const double determinant = bgc_matrix2x2_get_determinant_fp64(matrix); - if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) { + if (-BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64) { return 0; } @@ -267,7 +267,7 @@ inline int matrix2x2_invert_fp64(matrix2x2_fp64_t* matrix) // =============== Set Transposed =============== // -inline void matrix2x2_set_transposed_fp32(const matrix2x2_fp32_t* from, matrix2x2_fp32_t* to) +inline void bgc_matrix2x2_set_transposed_fp32(const bgc_matrix2x2_fp32_t* from, bgc_matrix2x2_fp32_t* to) { float tmp = from->r1c2; @@ -278,7 +278,7 @@ inline void matrix2x2_set_transposed_fp32(const matrix2x2_fp32_t* from, matrix2x to->r2c2 = from->r2c2; } -inline void matrix2x2_set_transposed_fp64(const matrix2x2_fp64_t* from, matrix2x2_fp64_t* to) +inline void bgc_matrix2x2_set_transposed_fp64(const bgc_matrix2x2_fp64_t* from, bgc_matrix2x2_fp64_t* to) { double tmp = from->r1c2; @@ -291,11 +291,11 @@ inline void matrix2x2_set_transposed_fp64(const matrix2x2_fp64_t* from, matrix2x // ================ Set Inverted ================ // -inline int matrix2x2_set_inverted_fp32(const matrix2x2_fp32_t* from, matrix2x2_fp32_t* to) +inline int bgc_matrix2x2_set_inverted_fp32(const bgc_matrix2x2_fp32_t* from, bgc_matrix2x2_fp32_t* to) { - const float determinant = matrix2x2_get_determinant_fp32(from); + const float determinant = bgc_matrix2x2_get_determinant_fp32(from); - if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) { + if (-BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32) { return 0; } @@ -316,11 +316,11 @@ inline int matrix2x2_set_inverted_fp32(const matrix2x2_fp32_t* from, matrix2x2_f return 1; } -inline int matrix2x2_set_inverted_fp64(const matrix2x2_fp64_t* from, matrix2x2_fp64_t* to) +inline int bgc_matrix2x2_set_inverted_fp64(const bgc_matrix2x2_fp64_t* from, bgc_matrix2x2_fp64_t* to) { - const double determinant = matrix2x2_get_determinant_fp64(from); + const double determinant = bgc_matrix2x2_get_determinant_fp64(from); - if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) { + if (-BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64) { return 0; } @@ -343,13 +343,13 @@ inline int matrix2x2_set_inverted_fp64(const matrix2x2_fp64_t* from, matrix2x2_f // ================= Set Row 1 ================== // -inline void matrix2x2_set_row1_fp32(const float c1, const float c2, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_row1_fp32(const float c1, const float c2, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; } -inline void matrix2x2_set_row1_fp64(const double c1, const double c2, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_row1_fp64(const double c1, const double c2, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; @@ -357,13 +357,13 @@ inline void matrix2x2_set_row1_fp64(const double c1, const double c2, matrix2x2_ // ================= Set Row 2 ================== // -inline void matrix2x2_set_row2_fp32(const float c1, const float c2, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_row2_fp32(const float c1, const float c2, bgc_matrix2x2_fp32_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; } -inline void matrix2x2_set_row2_fp64(const double c1, const double c2, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_row2_fp64(const double c1, const double c2, bgc_matrix2x2_fp64_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; @@ -371,13 +371,13 @@ inline void matrix2x2_set_row2_fp64(const double c1, const double c2, matrix2x2_ // ================ Set Column 1 ================ // -inline void matrix2x2_set_column1_fp32(const float r1, const float r2, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_column1_fp32(const float r1, const float r2, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; } -inline void matrix2x2_set_column1_fp64(const double r1, const double r2, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_column1_fp64(const double r1, const double r2, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; @@ -385,41 +385,21 @@ inline void matrix2x2_set_column1_fp64(const double r1, const double r2, matrix2 // ================ Set Column 2 ================ // -inline void matrix2x2_set_column2_fp32(const float r1, const float r2, matrix2x2_fp32_t* matrix) +inline void bgc_matrix2x2_set_column2_fp32(const float r1, const float r2, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; } -inline void matrix2x2_set_column2_fp64(const double r1, const double r2, matrix2x2_fp64_t* matrix) +inline void bgc_matrix2x2_set_column2_fp64(const double r1, const double r2, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; } -// ================ Append scaled =============== // - -inline void matrix2x2_add_scaled_fp32(matrix2x2_fp32_t* basic_vector, const matrix2x2_fp32_t* scalable_vector, const float scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; -} - -inline void matrix2x2_add_scaled_fp64(matrix2x2_fp64_t* basic_vector, const matrix2x2_fp64_t* scalable_vector, const double scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; -} - // ================== Addition ================== // -inline void matrix2x2_add_fp32(const matrix2x2_fp32_t* matrix1, const matrix2x2_fp32_t* matrix2, matrix2x2_fp32_t* sum) +inline void bgc_matrix2x2_add_fp32(const bgc_matrix2x2_fp32_t* matrix1, const bgc_matrix2x2_fp32_t* matrix2, bgc_matrix2x2_fp32_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -428,7 +408,7 @@ inline void matrix2x2_add_fp32(const matrix2x2_fp32_t* matrix1, const matrix2x2_ sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; } -inline void matrix2x2_add_fp64(const matrix2x2_fp64_t* matrix1, const matrix2x2_fp64_t* matrix2, matrix2x2_fp64_t* sum) +inline void bgc_matrix2x2_add_fp64(const bgc_matrix2x2_fp64_t* matrix1, const bgc_matrix2x2_fp64_t* matrix2, bgc_matrix2x2_fp64_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -437,9 +417,29 @@ inline void matrix2x2_add_fp64(const matrix2x2_fp64_t* matrix1, const matrix2x2_ sum->r2c2 = matrix1->r2c2 + matrix2->r2c2; } +// ================= Add scaled ================= // + +inline void bgc_matrix2x2_add_scaled_fp32(const bgc_matrix2x2_fp32_t* basic_matrix, const bgc_matrix2x2_fp32_t* scalable_matrix, const float scale, bgc_matrix2x2_fp32_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; +} + +inline void bgc_matrix2x2_add_scaled_fp64(const bgc_matrix2x2_fp64_t* basic_matrix, const bgc_matrix2x2_fp64_t* scalable_matrix, const double scale, bgc_matrix2x2_fp64_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; +} + // ================ Subtraction ================= // -inline void matrix2x2_subtract_fp32(const matrix2x2_fp32_t* minuend, const matrix2x2_fp32_t* subtrahend, matrix2x2_fp32_t* difference) +inline void bgc_matrix2x2_subtract_fp32(const bgc_matrix2x2_fp32_t* minuend, const bgc_matrix2x2_fp32_t* subtrahend, bgc_matrix2x2_fp32_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -448,7 +448,7 @@ inline void matrix2x2_subtract_fp32(const matrix2x2_fp32_t* minuend, const matri difference->r2c2 = minuend->r2c2 - subtrahend->r2c2; } -inline void matrix2x2_subtract_fp64(const matrix2x2_fp64_t* minuend, const matrix2x2_fp64_t* subtrahend, matrix2x2_fp64_t* difference) +inline void bgc_matrix2x2_subtract_fp64(const bgc_matrix2x2_fp64_t* minuend, const bgc_matrix2x2_fp64_t* subtrahend, bgc_matrix2x2_fp64_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -459,7 +459,7 @@ inline void matrix2x2_subtract_fp64(const matrix2x2_fp64_t* minuend, const matri // =============== Multiplication =============== // -inline void matrix2x2_multiply_fp32(const matrix2x2_fp32_t* multiplicand, const float multiplier, matrix2x2_fp32_t* product) +inline void bgc_matrix2x2_multiply_fp32(const bgc_matrix2x2_fp32_t* multiplicand, const float multiplier, bgc_matrix2x2_fp32_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -468,7 +468,7 @@ inline void matrix2x2_multiply_fp32(const matrix2x2_fp32_t* multiplicand, const product->r2c2 = multiplicand->r2c2 * multiplier; } -inline void matrix2x2_multiply_fp64(const matrix2x2_fp64_t* multiplicand, const double multiplier, matrix2x2_fp64_t* product) +inline void bgc_matrix2x2_multiply_fp64(const bgc_matrix2x2_fp64_t* multiplicand, const double multiplier, bgc_matrix2x2_fp64_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -479,19 +479,19 @@ inline void matrix2x2_multiply_fp64(const matrix2x2_fp64_t* multiplicand, const // ================== Division ================== // -inline void matrix2x2_divide_fp32(const matrix2x2_fp32_t* dividend, const float divisor, matrix2x2_fp32_t* quotient) +inline void bgc_matrix2x2_divide_fp32(const bgc_matrix2x2_fp32_t* dividend, const float divisor, bgc_matrix2x2_fp32_t* quotient) { - matrix2x2_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_matrix2x2_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void matrix2x2_fp64_divide(const matrix2x2_fp64_t* dividend, const double divisor, matrix2x2_fp64_t* quotient) +inline void bgc_matrix2x2_divide_fp64(const bgc_matrix2x2_fp64_t* dividend, const double divisor, bgc_matrix2x2_fp64_t* quotient) { - matrix2x2_multiply_fp64(dividend, 1.0 / divisor, quotient); + bgc_matrix2x2_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ============ Left Vector Product ============= // -inline void matrix2x2_left_product_fp32(const vector2_fp32_t* vector, const matrix2x2_fp32_t* matrix, vector2_fp32_t* result) +inline void bgc_matrix2x2_left_product_fp32(const bgc_vector2_fp32_t* vector, const bgc_matrix2x2_fp32_t* matrix, bgc_vector2_fp32_t* result) { const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; @@ -500,7 +500,7 @@ inline void matrix2x2_left_product_fp32(const vector2_fp32_t* vector, const matr result->x2 = x2; } -inline void matrix2x2_left_product_fp64(const vector2_fp64_t* vector, const matrix2x2_fp64_t* matrix, vector2_fp64_t* result) +inline void bgc_matrix2x2_left_product_fp64(const bgc_vector2_fp64_t* vector, const bgc_matrix2x2_fp64_t* matrix, bgc_vector2_fp64_t* result) { const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; @@ -511,7 +511,7 @@ inline void matrix2x2_left_product_fp64(const vector2_fp64_t* vector, const matr // ============ Right Vector Product ============ // -inline void matrix2x2_right_product_fp32(const matrix2x2_fp32_t* matrix, const vector2_fp32_t* vector, vector2_fp32_t* result) +inline void bgc_matrix2x2_right_product_fp32(const bgc_matrix2x2_fp32_t* matrix, const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result) { const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; @@ -520,7 +520,7 @@ inline void matrix2x2_right_product_fp32(const matrix2x2_fp32_t* matrix, const v result->x2 = x2; } -inline void matrix2x2_right_product_fp64(const matrix2x2_fp64_t* matrix, const vector2_fp64_t* vector, vector2_fp64_t* result) +inline void bgc_matrix2x2_right_product_fp64(const bgc_matrix2x2_fp64_t* matrix, const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result) { const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; diff --git a/basic-geometry/matrix2x3.h b/basic-geometry/matrix2x3.h index 68a7a63..062fe78 100644 --- a/basic-geometry/matrix2x3.h +++ b/basic-geometry/matrix2x3.h @@ -1,5 +1,5 @@ -#ifndef _BASIC_GEOMETRY_MATRIX2X3_H_ -#define _BASIC_GEOMETRY_MATRIX2X3_H_ +#ifndef _BGC_MATRIX2X3_H_ +#define _BGC_MATRIX2X3_H_ #include "vector2.h" #include "vector3.h" @@ -7,7 +7,7 @@ // =================== Reset ==================== // -inline void matrix2x3_reset_fp32(matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_reset_fp32(bgc_matrix2x3_fp32_t* matrix) { matrix->r1c1 = 0.0f; matrix->r1c2 = 0.0f; @@ -19,7 +19,7 @@ inline void matrix2x3_reset_fp32(matrix2x3_fp32_t* matrix) matrix->r3c2 = 0.0f; } -inline void matrix2x3_reset_fp64(matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_reset_fp64(bgc_matrix2x3_fp64_t* matrix) { matrix->r1c1 = 0.0; matrix->r1c2 = 0.0; @@ -33,7 +33,7 @@ inline void matrix2x3_reset_fp64(matrix2x3_fp64_t* matrix) // ==================== Copy ==================== // -inline void matrix2x3_copy_fp32(const matrix2x3_fp32_t* from, matrix2x3_fp32_t* to) +inline void bgc_matrix2x3_copy_fp32(const bgc_matrix2x3_fp32_t* from, bgc_matrix2x3_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -45,7 +45,7 @@ inline void matrix2x3_copy_fp32(const matrix2x3_fp32_t* from, matrix2x3_fp32_t* to->r3c2 = from->r3c2; } -inline void matrix2x3_copy_fp64(const matrix2x3_fp64_t* from, matrix2x3_fp64_t* to) +inline void bgc_matrix2x3_copy_fp64(const bgc_matrix2x3_fp64_t* from, bgc_matrix2x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -59,7 +59,7 @@ inline void matrix2x3_copy_fp64(const matrix2x3_fp64_t* from, matrix2x3_fp64_t* // ==================== Swap ==================== // -inline void matrix2x3_swap_fp32(matrix2x3_fp32_t* matrix1, matrix2x3_fp32_t* matrix2) +inline void bgc_matrix2x3_swap_fp32(bgc_matrix2x3_fp32_t* matrix1, bgc_matrix2x3_fp32_t* matrix2) { const float r1c1 = matrix2->r1c1; const float r1c2 = matrix2->r1c2; @@ -89,7 +89,7 @@ inline void matrix2x3_swap_fp32(matrix2x3_fp32_t* matrix1, matrix2x3_fp32_t* mat matrix1->r3c2 = r3c2; } -inline void matrix2x3_swap_fp64(matrix2x3_fp64_t* matrix1, matrix2x3_fp64_t* matrix2) +inline void bgc_matrix2x3_swap_fp64(bgc_matrix2x3_fp64_t* matrix1, bgc_matrix2x3_fp64_t* matrix2) { const double r1c1 = matrix2->r1c1; const double r1c2 = matrix2->r1c2; @@ -121,7 +121,7 @@ inline void matrix2x3_swap_fp64(matrix2x3_fp64_t* matrix1, matrix2x3_fp64_t* mat // ============= Copy to twin type ============== // -inline void matrix2x3_convert_fp64_to_fp32(const matrix2x3_fp64_t* from, matrix2x3_fp32_t* to) +inline void bgc_matrix2x3_convert_fp64_to_fp32(const bgc_matrix2x3_fp64_t* from, bgc_matrix2x3_fp32_t* to) { to->r1c1 = (float) from->r1c1; to->r1c2 = (float) from->r1c2; @@ -133,7 +133,7 @@ inline void matrix2x3_convert_fp64_to_fp32(const matrix2x3_fp64_t* from, matrix2 to->r3c2 = (float) from->r3c2; } -inline void matrix2x3_convert_fp32_to_fp64(const matrix2x3_fp32_t* from, matrix2x3_fp64_t* to) +inline void bgc_matrix2x3_convert_fp32_to_fp64(const bgc_matrix2x3_fp32_t* from, bgc_matrix2x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -147,7 +147,7 @@ inline void matrix2x3_convert_fp32_to_fp64(const matrix2x3_fp32_t* from, matrix2 // =============== Set transposed =============== // -inline void matrix2x3_set_transposed_fp32(const matrix3x2_fp32_t* from, matrix2x3_fp32_t* to) +inline void bgc_matrix2x3_set_transposed_fp32(const bgc_matrix3x2_fp32_t* from, bgc_matrix2x3_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -159,7 +159,7 @@ inline void matrix2x3_set_transposed_fp32(const matrix3x2_fp32_t* from, matrix2x to->r3c2 = from->r2c3; } -inline void matrix2x3_set_transposed_fp64(const matrix3x2_fp64_t* from, matrix2x3_fp64_t* to) +inline void bgc_matrix2x3_set_transposed_fp64(const bgc_matrix3x2_fp64_t* from, bgc_matrix2x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -173,7 +173,7 @@ inline void matrix2x3_set_transposed_fp64(const matrix3x2_fp64_t* from, matrix2x // =============== Set transposed =============== // -inline void matrix2x3_set_transposed_fp32_fp64(const matrix3x2_fp64_t* from, matrix2x3_fp32_t* to) +inline void bgc_matrix2x3_set_transposed_fp32_fp64(const bgc_matrix3x2_fp64_t* from, bgc_matrix2x3_fp32_t* to) { to->r1c1 = (float) from->r1c1; to->r1c2 = (float) from->r2c1; @@ -185,7 +185,7 @@ inline void matrix2x3_set_transposed_fp32_fp64(const matrix3x2_fp64_t* from, mat to->r3c2 = (float) from->r2c3; } -inline void matrix2x3_set_transposed_fp64_fp32(const matrix3x2_fp32_t* from, matrix2x3_fp64_t* to) +inline void bgc_matrix2x3_set_transposed_fp64_fp32(const bgc_matrix3x2_fp32_t* from, bgc_matrix2x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -199,13 +199,13 @@ inline void matrix2x3_set_transposed_fp64_fp32(const matrix3x2_fp32_t* from, mat // ================= Set Row 1 ================== // -inline void matrix2x3_set_row1_fp32(const float c1, const float c2, matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_set_row1_fp32(const float c1, const float c2, bgc_matrix2x3_fp32_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; } -inline void matrix2x3_set_row1_fp64(const double c1, const double c2, matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_set_row1_fp64(const double c1, const double c2, bgc_matrix2x3_fp64_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; @@ -213,13 +213,13 @@ inline void matrix2x3_set_row1_fp64(const double c1, const double c2, matrix2x3_ // ================= Set Row 2 ================== // -inline void matrix2x3_set_row2_fp32(const float c1, const float c2, matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_set_row2_fp32(const float c1, const float c2, bgc_matrix2x3_fp32_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; } -inline void matrix2x3_set_row2_fp64(const double c1, const double c2, matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_set_row2_fp64(const double c1, const double c2, bgc_matrix2x3_fp64_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; @@ -227,13 +227,13 @@ inline void matrix2x3_set_row2_fp64(const double c1, const double c2, matrix2x3_ // ================= Set Row 3 ================== // -inline void matrix2x3_set_row3_fp32(const float c1, const float c2, matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_set_row3_fp32(const float c1, const float c2, bgc_matrix2x3_fp32_t* matrix) { matrix->r3c1 = c1; matrix->r3c2 = c2; } -inline void matrix2x3_set_row3_fp64(const double c1, const double c2, matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_set_row3_fp64(const double c1, const double c2, bgc_matrix2x3_fp64_t* matrix) { matrix->r3c1 = c1; matrix->r3c2 = c2; @@ -241,14 +241,14 @@ inline void matrix2x3_set_row3_fp64(const double c1, const double c2, matrix2x3_ // ================ Set Column 1 ================ // -inline void matrix2x3_set_column1_fp32(const float r1, const float r2, const float r3, matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_set_column1_fp32(const float r1, const float r2, const float r3, bgc_matrix2x3_fp32_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; matrix->r3c1 = r3; } -inline void matrix2x3_set_column1_fp64(const double r1, const double r2, const double r3, matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_set_column1_fp64(const double r1, const double r2, const double r3, bgc_matrix2x3_fp64_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; @@ -257,49 +257,23 @@ inline void matrix2x3_set_column1_fp64(const double r1, const double r2, const d // ================ Set Column 2 ================ // -inline void matrix2x3_set_column2_fp32(const float r1, const float r2, const float r3, matrix2x3_fp32_t* matrix) +inline void bgc_matrix2x3_set_column2_fp32(const float r1, const float r2, const float r3, bgc_matrix2x3_fp32_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; matrix->r3c2 = r3; } -inline void matrix2x3_set_column2_fp64(const double r1, const double r2, const double r3, matrix2x3_fp64_t* matrix) +inline void bgc_matrix2x3_set_column2_fp64(const double r1, const double r2, const double r3, bgc_matrix2x3_fp64_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; matrix->r3c2 = r3; } -// ================ Append scaled =============== // - -inline void matrix2x3_add_scaled_fp32(matrix2x3_fp32_t* basic_vector, const matrix2x3_fp32_t* scalable_vector, const float scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - - basic_vector->r3c1 += scalable_vector->r3c1 * scale; - basic_vector->r3c2 += scalable_vector->r3c2 * scale; -} - -inline void matrix2x3_add_scaled_fp64(matrix2x3_fp64_t* basic_vector, const matrix2x3_fp64_t* scalable_vector, const double scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - - basic_vector->r3c1 += scalable_vector->r3c1 * scale; - basic_vector->r3c2 += scalable_vector->r3c2 * scale; -} - // ================== Addition ================== // -inline void matrix2x3_add_fp32(const matrix2x3_fp32_t* matrix1, const matrix2x3_fp32_t* matrix2, matrix2x3_fp32_t* sum) +inline void bgc_matrix2x3_add_fp32(const bgc_matrix2x3_fp32_t* matrix1, const bgc_matrix2x3_fp32_t* matrix2, bgc_matrix2x3_fp32_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -311,7 +285,7 @@ inline void matrix2x3_add_fp32(const matrix2x3_fp32_t* matrix1, const matrix2x3_ sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; } -inline void matrix2x3_add_fp64(const matrix2x3_fp64_t* matrix1, const matrix2x3_fp64_t* matrix2, matrix2x3_fp64_t* sum) +inline void bgc_matrix2x3_add_fp64(const bgc_matrix2x3_fp64_t* matrix1, const bgc_matrix2x3_fp64_t* matrix2, bgc_matrix2x3_fp64_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -323,9 +297,35 @@ inline void matrix2x3_add_fp64(const matrix2x3_fp64_t* matrix1, const matrix2x3_ sum->r3c2 = matrix1->r3c2 + matrix2->r3c2; } +// ================= Add scaled ================= // + +inline void bgc_matrix2x3_add_scaled_fp32(const bgc_matrix2x3_fp32_t* basic_matrix, const bgc_matrix2x3_fp32_t* scalable_matrix, const float scale, bgc_matrix2x3_fp32_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + + sum->r3c1 = basic_matrix->r3c1 + scalable_matrix->r3c1 * scale; + sum->r3c2 = basic_matrix->r3c2 + scalable_matrix->r3c2 * scale; +} + +inline void bgc_matrix2x3_add_scaled_fp64(const bgc_matrix2x3_fp64_t* basic_matrix, const bgc_matrix2x3_fp64_t* scalable_matrix, const double scale, bgc_matrix2x3_fp64_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + + sum->r3c1 = basic_matrix->r3c1 + scalable_matrix->r3c1 * scale; + sum->r3c2 = basic_matrix->r3c2 + scalable_matrix->r3c2 * scale; +} + // ================ Subtraction ================= // -inline void matrix2x3_subtract_fp32(const matrix2x3_fp32_t* minuend, const matrix2x3_fp32_t* subtrahend, matrix2x3_fp32_t* difference) +inline void bgc_matrix2x3_subtract_fp32(const bgc_matrix2x3_fp32_t* minuend, const bgc_matrix2x3_fp32_t* subtrahend, bgc_matrix2x3_fp32_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -337,7 +337,7 @@ inline void matrix2x3_subtract_fp32(const matrix2x3_fp32_t* minuend, const matri difference->r3c2 = minuend->r3c2 - subtrahend->r3c2; } -inline void matrix2x3_subtract_fp64(const matrix2x3_fp64_t* minuend, const matrix2x3_fp64_t* subtrahend, matrix2x3_fp64_t* difference) +inline void bgc_matrix2x3_subtract_fp64(const bgc_matrix2x3_fp64_t* minuend, const bgc_matrix2x3_fp64_t* subtrahend, bgc_matrix2x3_fp64_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -351,7 +351,7 @@ inline void matrix2x3_subtract_fp64(const matrix2x3_fp64_t* minuend, const matri // =============== Multiplication =============== // -inline void matrix2x3_multiply_fp32(const matrix2x3_fp32_t* multiplicand, const float multiplier, matrix2x3_fp32_t* product) +inline void bgc_matrix2x3_multiply_fp32(const bgc_matrix2x3_fp32_t* multiplicand, const float multiplier, bgc_matrix2x3_fp32_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -363,7 +363,7 @@ inline void matrix2x3_multiply_fp32(const matrix2x3_fp32_t* multiplicand, const product->r3c2 = multiplicand->r3c2 * multiplier; } -inline void matrix2x3_multiply_fp64(const matrix2x3_fp64_t* multiplicand, const double multiplier, matrix2x3_fp64_t* product) +inline void bgc_matrix2x3_multiply_fp64(const bgc_matrix2x3_fp64_t* multiplicand, const double multiplier, bgc_matrix2x3_fp64_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -377,25 +377,25 @@ inline void matrix2x3_multiply_fp64(const matrix2x3_fp64_t* multiplicand, const // ================== Division ================== // -inline void matrix2x3_divide_fp32(const matrix2x3_fp32_t* dividend, const float divisor, matrix2x3_fp32_t* quotient) +inline void bgc_matrix2x3_divide_fp32(const bgc_matrix2x3_fp32_t* dividend, const float divisor, bgc_matrix2x3_fp32_t* quotient) { - matrix2x3_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_matrix2x3_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void matrix2x3_fp64_divide(const matrix2x3_fp64_t* dividend, const double divisor, matrix2x3_fp64_t* quotient) +inline void bgc_matrix2x3_divide_fp64(const bgc_matrix2x3_fp64_t* dividend, const double divisor, bgc_matrix2x3_fp64_t* quotient) { - matrix2x3_multiply_fp64(dividend, 1.0 / divisor, quotient); + bgc_matrix2x3_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ============ Left Vector Product ============= // -inline void matrix2x3_left_product_fp32(const vector3_fp32_t* vector, const matrix2x3_fp32_t* matrix, vector2_fp32_t* result) +inline void bgc_matrix2x3_left_product_fp32(const bgc_vector3_fp32_t* vector, const bgc_matrix2x3_fp32_t* matrix, bgc_vector2_fp32_t* 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; } -inline void matrix2x3_left_product_fp64(const vector3_fp64_t* vector, const matrix2x3_fp64_t* matrix, vector2_fp64_t* result) +inline void bgc_matrix2x3_left_product_fp64(const bgc_vector3_fp64_t* vector, const bgc_matrix2x3_fp64_t* matrix, bgc_vector2_fp64_t* 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; @@ -403,14 +403,14 @@ inline void matrix2x3_left_product_fp64(const vector3_fp64_t* vector, const matr // ============ Right Vector Product ============ // -inline void matrix2x3_right_product_fp32(const matrix2x3_fp32_t* matrix, const vector2_fp32_t* vector, vector3_fp32_t* result) +inline void bgc_matrix2x3_right_product_fp32(const bgc_matrix2x3_fp32_t* matrix, const bgc_vector2_fp32_t* vector, bgc_vector3_fp32_t* 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; } -inline void matrix2x3_right_product_fp64(const matrix2x3_fp64_t* matrix, const vector2_fp64_t* vector, vector3_fp64_t* result) +inline void bgc_matrix2x3_right_product_fp64(const bgc_matrix2x3_fp64_t* matrix, const bgc_vector2_fp64_t* vector, bgc_vector3_fp64_t* result) { result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; diff --git a/basic-geometry/matrix3x2.h b/basic-geometry/matrix3x2.h index dd1b697..334fd60 100644 --- a/basic-geometry/matrix3x2.h +++ b/basic-geometry/matrix3x2.h @@ -1,5 +1,5 @@ -#ifndef _BASIC_GEOMETRY_MATRIX3X2_H_ -#define _BASIC_GEOMETRY_MATRIX3X2_H_ +#ifndef _BGC_MATRIX3X2_H_ +#define _BGC_MATRIX3X2_H_ #include "vector2.h" #include "vector3.h" @@ -7,7 +7,7 @@ // =================== Reset ==================== // -inline void matrix3x2_reset_fp32(matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_reset_fp32(bgc_matrix3x2_fp32_t* matrix) { matrix->r1c1 = 0.0f; matrix->r1c2 = 0.0f; @@ -18,7 +18,7 @@ inline void matrix3x2_reset_fp32(matrix3x2_fp32_t* matrix) matrix->r2c3 = 0.0f; } -inline void matrix3x2_reset_fp64(matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_reset_fp64(bgc_matrix3x2_fp64_t* matrix) { matrix->r1c1 = 0.0; matrix->r1c2 = 0.0; @@ -31,7 +31,7 @@ inline void matrix3x2_reset_fp64(matrix3x2_fp64_t* matrix) // ==================== Copy ==================== // -inline void matrix3x2_copy_fp32(const matrix3x2_fp32_t* from, matrix3x2_fp32_t* to) +inline void bgc_matrix3x2_copy_fp32(const bgc_matrix3x2_fp32_t* from, bgc_matrix3x2_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -42,7 +42,7 @@ inline void matrix3x2_copy_fp32(const matrix3x2_fp32_t* from, matrix3x2_fp32_t* to->r2c3 = from->r2c3; } -inline void matrix3x2_copy_fp64(const matrix3x2_fp64_t* from, matrix3x2_fp64_t* to) +inline void bgc_matrix3x2_copy_fp64(const bgc_matrix3x2_fp64_t* from, bgc_matrix3x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -55,7 +55,7 @@ inline void matrix3x2_copy_fp64(const matrix3x2_fp64_t* from, matrix3x2_fp64_t* // ==================== Swap ==================== // -inline void matrix3x2_swap_fp32(matrix3x2_fp32_t* matrix1, matrix3x2_fp32_t* matrix2) +inline void bgc_matrix3x2_swap_fp32(bgc_matrix3x2_fp32_t* matrix1, bgc_matrix3x2_fp32_t* matrix2) { const float r1c1 = matrix2->r1c1; const float r1c2 = matrix2->r1c2; @@ -82,7 +82,7 @@ inline void matrix3x2_swap_fp32(matrix3x2_fp32_t* matrix1, matrix3x2_fp32_t* mat matrix1->r2c3 = r2c3; } -inline void matrix3x2_swap_fp64(matrix3x2_fp64_t* matrix1, matrix3x2_fp64_t* matrix2) +inline void bgc_matrix3x2_swap_fp64(bgc_matrix3x2_fp64_t* matrix1, bgc_matrix3x2_fp64_t* matrix2) { const double r1c1 = matrix2->r1c1; const double r1c2 = matrix2->r1c2; @@ -111,7 +111,7 @@ inline void matrix3x2_swap_fp64(matrix3x2_fp64_t* matrix1, matrix3x2_fp64_t* mat // ============= Set from twin type ============= // -inline void matrix3x2_convert_fp64_to_fp32(const matrix3x2_fp64_t* from, matrix3x2_fp32_t* to) +inline void bgc_matrix3x2_convert_fp64_to_fp32(const bgc_matrix3x2_fp64_t* from, bgc_matrix3x2_fp32_t* to) { to->r1c1 = (float) from->r1c1; to->r1c2 = (float) from->r1c2; @@ -122,7 +122,7 @@ inline void matrix3x2_convert_fp64_to_fp32(const matrix3x2_fp64_t* from, matrix3 to->r2c3 = (float) from->r2c3; } -inline void matrix3x2_convert_fp32_to_fp64(const matrix3x2_fp32_t* from, matrix3x2_fp64_t* to) +inline void bgc_matrix3x2_convert_fp32_to_fp64(const bgc_matrix3x2_fp32_t* from, bgc_matrix3x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -135,7 +135,7 @@ inline void matrix3x2_convert_fp32_to_fp64(const matrix3x2_fp32_t* from, matrix3 // =============== Set transposed =============== // -inline void matrix3x2_set_transposed_fp32(const matrix2x3_fp32_t* from, matrix3x2_fp32_t* to) +inline void bgc_matrix3x2_set_transposed_fp32(const bgc_matrix2x3_fp32_t* from, bgc_matrix3x2_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -146,7 +146,7 @@ inline void matrix3x2_set_transposed_fp32(const matrix2x3_fp32_t* from, matrix3x to->r2c3 = from->r3c2; } -inline void matrix3x2_set_transposed_fp64(const matrix2x3_fp64_t* from, matrix3x2_fp64_t* to) +inline void bgc_matrix3x2_set_transposed_fp64(const bgc_matrix2x3_fp64_t* from, bgc_matrix3x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -159,7 +159,7 @@ inline void matrix3x2_set_transposed_fp64(const matrix2x3_fp64_t* from, matrix3x // =============== Set transposed =============== // -inline void matrix3x2_set_transposed_fp32_fp64(const matrix2x3_fp64_t* from, matrix3x2_fp32_t* to) +inline void bgc_matrix3x2_set_transposed_fp32_fp64(const bgc_matrix2x3_fp64_t* from, bgc_matrix3x2_fp32_t* to) { to->r1c1 = (float) from->r1c1; to->r1c2 = (float) from->r2c1; @@ -170,7 +170,7 @@ inline void matrix3x2_set_transposed_fp32_fp64(const matrix2x3_fp64_t* from, mat to->r2c3 = (float) from->r3c2; } -inline void matrix3x2_set_transposed_fp64_fp32(const matrix2x3_fp32_t* from, matrix3x2_fp64_t* to) +inline void bgc_matrix3x2_set_transposed_fp64_fp32(const bgc_matrix2x3_fp32_t* from, bgc_matrix3x2_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r2c1; @@ -183,14 +183,14 @@ inline void matrix3x2_set_transposed_fp64_fp32(const matrix2x3_fp32_t* from, mat // ================= Set Row 1 ================== // -inline void matrix3x2_set_row1_fp32(const float c1, const float c2, const float c3, matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_set_row1_fp32(const float c1, const float c2, const float c3, bgc_matrix3x2_fp32_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; matrix->r1c3 = c3; } -inline void matrix3x2_set_row1_fp64(const double c1, const double c2, const double c3, matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_set_row1_fp64(const double c1, const double c2, const double c3, bgc_matrix3x2_fp64_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; @@ -199,14 +199,14 @@ inline void matrix3x2_set_row1_fp64(const double c1, const double c2, const doub // ================= Set Row 2 ================== // -inline void matrix3x2_set_row2_fp32(const float c1, const float c2, const float c3, matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_set_row2_fp32(const float c1, const float c2, const float c3, bgc_matrix3x2_fp32_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; matrix->r2c3 = c3; } -inline void matrix3x2_set_row2_fp64(const double c1, const double c2, const double c3, matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_set_row2_fp64(const double c1, const double c2, const double c3, bgc_matrix3x2_fp64_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; @@ -215,13 +215,13 @@ inline void matrix3x2_set_row2_fp64(const double c1, const double c2, const doub // ================ Set Column 1 ================ // -inline void matrix3x2_set_column1_fp32(const float r1, const float r2, matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_set_column1_fp32(const float r1, const float r2, bgc_matrix3x2_fp32_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; } -inline void matrix3x2_set_column1_fp64(const double r1, const double r2, matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_set_column1_fp64(const double r1, const double r2, bgc_matrix3x2_fp64_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; @@ -229,13 +229,13 @@ inline void matrix3x2_set_column1_fp64(const double r1, const double r2, matrix3 // ================ Set Column 2 ================ // -inline void matrix3x2_set_column2_fp32(const float r1, const float r2, matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_set_column2_fp32(const float r1, const float r2, bgc_matrix3x2_fp32_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; } -inline void matrix3x2_set_column2_fp64(const double r1, const double r2, matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_set_column2_fp64(const double r1, const double r2, bgc_matrix3x2_fp64_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; @@ -243,45 +243,21 @@ inline void matrix3x2_set_column2_fp64(const double r1, const double r2, matrix3 // ================ Set Column 3 ================ // -inline void matrix3x2_set_column3_fp32(const float r1, const float r2, matrix3x2_fp32_t* matrix) +inline void bgc_matrix3x2_set_column3_fp32(const float r1, const float r2, bgc_matrix3x2_fp32_t* matrix) { matrix->r1c3 = r1; matrix->r2c3 = r2; } -inline void matrix3x2_set_column3_fp64(const double r1, const double r2, matrix3x2_fp64_t* matrix) +inline void bgc_matrix3x2_set_column3_fp64(const double r1, const double r2, bgc_matrix3x2_fp64_t* matrix) { matrix->r1c3 = r1; matrix->r2c3 = r2; } -// ================ Append scaled =============== // - -inline void matrix3x2_add_scaled_fp32(matrix3x2_fp32_t* basic_vector, const matrix3x2_fp32_t* scalable_vector, const float scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - basic_vector->r1c3 += scalable_vector->r1c3 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - basic_vector->r2c3 += scalable_vector->r2c3 * scale; -} - -inline void matrix3x2_add_scaled_fp64(matrix3x2_fp64_t* basic_vector, const matrix3x2_fp64_t* scalable_vector, const double scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - basic_vector->r1c3 += scalable_vector->r1c3 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - basic_vector->r2c3 += scalable_vector->r2c3 * scale; -} - // ================== Addition ================== // -inline void matrix3x2_add_fp32(const matrix3x2_fp32_t* matrix1, const matrix3x2_fp32_t* matrix2, matrix3x2_fp32_t* sum) +inline void bgc_matrix3x2_add_fp32(const bgc_matrix3x2_fp32_t* matrix1, const bgc_matrix3x2_fp32_t* matrix2, bgc_matrix3x2_fp32_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -292,7 +268,7 @@ inline void matrix3x2_add_fp32(const matrix3x2_fp32_t* matrix1, const matrix3x2_ sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; } -inline void matrix3x2_add_fp64(const matrix3x2_fp64_t* matrix1, const matrix3x2_fp64_t* matrix2, matrix3x2_fp64_t* sum) +inline void bgc_matrix3x2_add_fp64(const bgc_matrix3x2_fp64_t* matrix1, const bgc_matrix3x2_fp64_t* matrix2, bgc_matrix3x2_fp64_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -303,9 +279,33 @@ inline void matrix3x2_add_fp64(const matrix3x2_fp64_t* matrix1, const matrix3x2_ sum->r2c3 = matrix1->r2c3 + matrix2->r2c3; } +// ================= Add scaled ================= // + +inline void bgc_matrix3x2_add_scaled_fp32(const bgc_matrix3x2_fp32_t* basic_matrix, const bgc_matrix3x2_fp32_t* scalable_matrix, const float scale, bgc_matrix3x2_fp32_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + sum->r1c3 = basic_matrix->r1c3 + scalable_matrix->r1c3 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + sum->r2c3 = basic_matrix->r2c3 + scalable_matrix->r2c3 * scale; +} + +inline void bgc_matrix3x2_add_scaled_fp64(const bgc_matrix3x2_fp64_t* basic_matrix, const bgc_matrix3x2_fp64_t* scalable_matrix, const double scale, bgc_matrix3x2_fp64_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + sum->r1c3 = basic_matrix->r1c3 + scalable_matrix->r1c3 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + sum->r2c3 = basic_matrix->r2c3 + scalable_matrix->r2c3 * scale; +} + // ================ Subtraction ================= // -inline void matrix3x2_subtract_fp32(const matrix3x2_fp32_t* minuend, const matrix3x2_fp32_t* subtrahend, matrix3x2_fp32_t* difference) +inline void bgc_matrix3x2_subtract_fp32(const bgc_matrix3x2_fp32_t* minuend, const bgc_matrix3x2_fp32_t* subtrahend, bgc_matrix3x2_fp32_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -316,7 +316,7 @@ inline void matrix3x2_subtract_fp32(const matrix3x2_fp32_t* minuend, const matri difference->r2c3 = minuend->r2c3 - subtrahend->r2c3; } -inline void matrix3x2_subtract_fp64(const matrix3x2_fp64_t* minuend, const matrix3x2_fp64_t* subtrahend, matrix3x2_fp64_t* difference) +inline void bgc_matrix3x2_subtract_fp64(const bgc_matrix3x2_fp64_t* minuend, const bgc_matrix3x2_fp64_t* subtrahend, bgc_matrix3x2_fp64_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -329,7 +329,7 @@ inline void matrix3x2_subtract_fp64(const matrix3x2_fp64_t* minuend, const matri // =============== Multiplication =============== // -inline void matrix3x2_multiply_fp32(const matrix3x2_fp32_t* multiplicand, const float multiplier, matrix3x2_fp32_t* product) +inline void bgc_matrix3x2_multiply_fp32(const bgc_matrix3x2_fp32_t* multiplicand, const float multiplier, bgc_matrix3x2_fp32_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -340,7 +340,7 @@ inline void matrix3x2_multiply_fp32(const matrix3x2_fp32_t* multiplicand, const product->r2c3 = multiplicand->r2c3 * multiplier; } -inline void matrix3x2_multiply_fp64(const matrix3x2_fp64_t* multiplicand, const double multiplier, matrix3x2_fp64_t* product) +inline void bgc_matrix3x2_multiply_fp64(const bgc_matrix3x2_fp64_t* multiplicand, const double multiplier, bgc_matrix3x2_fp64_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -353,26 +353,26 @@ inline void matrix3x2_multiply_fp64(const matrix3x2_fp64_t* multiplicand, const // ================== Division ================== // -inline void matrix3x2_divide_fp32(const matrix3x2_fp32_t* dividend, const float divisor, matrix3x2_fp32_t* quotient) +inline void bgc_matrix3x2_divide_fp32(const bgc_matrix3x2_fp32_t* dividend, const float divisor, bgc_matrix3x2_fp32_t* quotient) { - matrix3x2_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_matrix3x2_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void matrix3x2_fp64_divide(const matrix3x2_fp64_t* dividend, const double divisor, matrix3x2_fp64_t* quotient) +inline void bgc_matrix3x2_divide_fp64(const bgc_matrix3x2_fp64_t* dividend, const double divisor, bgc_matrix3x2_fp64_t* quotient) { - matrix3x2_multiply_fp64(dividend, 1.0 / divisor, quotient); + bgc_matrix3x2_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ============ Left Vector Product ============= // -inline void matrix3x2_left_product_fp32(const vector2_fp32_t* vector, const matrix3x2_fp32_t* matrix, vector3_fp32_t* result) +inline void bgc_matrix3x2_left_product_fp32(const bgc_vector2_fp32_t* vector, const bgc_matrix3x2_fp32_t* matrix, bgc_vector3_fp32_t* 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; } -inline void matrix3x2_left_product_fp64(const vector2_fp64_t* vector, const matrix3x2_fp64_t* matrix, vector3_fp64_t* result) +inline void bgc_matrix3x2_left_product_fp64(const bgc_vector2_fp64_t* vector, const bgc_matrix3x2_fp64_t* matrix, bgc_vector3_fp64_t* result) { result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; @@ -381,13 +381,13 @@ inline void matrix3x2_left_product_fp64(const vector2_fp64_t* vector, const matr // ============ Right Vector Product ============ // -inline void matrix3x2_right_product_fp32(const matrix3x2_fp32_t* matrix, const vector3_fp32_t* vector, vector2_fp32_t* result) +inline void bgc_matrix3x2_right_product_fp32(const bgc_matrix3x2_fp32_t* matrix, const bgc_vector3_fp32_t* vector, bgc_vector2_fp32_t* 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; } -inline void matrix3x2_right_product_fp64(const matrix3x2_fp64_t* matrix, const vector3_fp64_t* vector, vector2_fp64_t* result) +inline void bgc_matrix3x2_right_product_fp64(const bgc_matrix3x2_fp64_t* matrix, const bgc_vector3_fp64_t* vector, bgc_vector2_fp64_t* 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; diff --git a/basic-geometry/matrix3x3.c b/basic-geometry/matrix3x3.c index 5c95d17..ade1e9f 100644 --- a/basic-geometry/matrix3x3.c +++ b/basic-geometry/matrix3x3.c @@ -2,11 +2,11 @@ // ================= Inversion ================== // -int matrix3x3_invert_fp32(matrix3x3_fp32_t* matrix) +int bgc_matrix3x3_invert_fp32(bgc_matrix3x3_fp32_t* matrix) { - const float determinant = matrix3x3_get_determinant_fp32(matrix); + const float determinant = bgc_matrix3x3_get_determinant_fp32(matrix); - if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) { + if (-BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32) { return 0; } @@ -39,11 +39,11 @@ int matrix3x3_invert_fp32(matrix3x3_fp32_t* matrix) return 1; } -int matrix3x3_invert_fp64(matrix3x3_fp64_t* matrix) +int bgc_matrix3x3_invert_fp64(bgc_matrix3x3_fp64_t* matrix) { - const double determinant = matrix3x3_get_determinant_fp64(matrix); + const double determinant = bgc_matrix3x3_get_determinant_fp64(matrix); - if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) { + if (-BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64) { return 0; } @@ -78,11 +78,11 @@ int matrix3x3_invert_fp64(matrix3x3_fp64_t* matrix) // ================ Make Inverted =============== // -int matrix3x3_set_inverted_fp32(const matrix3x3_fp32_t* matrix, matrix3x3_fp32_t* result) +int bgc_matrix3x3_set_inverted_fp32(const bgc_matrix3x3_fp32_t* matrix, bgc_matrix3x3_fp32_t* result) { - const float determinant = matrix3x3_get_determinant_fp32(matrix); + const float determinant = bgc_matrix3x3_get_determinant_fp32(matrix); - if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) { + if (-BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32) { return 0; } @@ -115,11 +115,11 @@ int matrix3x3_set_inverted_fp32(const matrix3x3_fp32_t* matrix, matrix3x3_fp32_t return 1; } -int matrix3x3_set_inverted_fp64(const matrix3x3_fp64_t* matrix, matrix3x3_fp64_t* result) +int bgc_matrix3x3_set_inverted_fp64(const bgc_matrix3x3_fp64_t* matrix, bgc_matrix3x3_fp64_t* result) { - const double determinant = matrix3x3_get_determinant_fp64(matrix); + const double determinant = bgc_matrix3x3_get_determinant_fp64(matrix); - if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) { + if (-BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64) { return 0; } diff --git a/basic-geometry/matrix3x3.h b/basic-geometry/matrix3x3.h index 7468f77..cc4528e 100644 --- a/basic-geometry/matrix3x3.h +++ b/basic-geometry/matrix3x3.h @@ -1,12 +1,12 @@ -#ifndef _BASIC_GEOMETRY_MATRIX3X3_H_ -#define _BASIC_GEOMETRY_MATRIX3X3_H_ +#ifndef _BGC_MATRIX3X3_H_ +#define _BGC_MATRIX3X3_H_ #include "vector3.h" #include "matrixes.h" // =================== Reset ==================== // -inline void matrix3x3_reset_fp32(matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_reset_fp32(bgc_matrix3x3_fp32_t* matrix) { matrix->r1c1 = 0.0f; matrix->r1c2 = 0.0f; @@ -21,7 +21,7 @@ inline void matrix3x3_reset_fp32(matrix3x3_fp32_t* matrix) matrix->r3c3 = 0.0f; } -inline void matrix3x3_reset_fp64(matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_reset_fp64(bgc_matrix3x3_fp64_t* matrix) { matrix->r1c1 = 0.0; matrix->r1c2 = 0.0; @@ -38,7 +38,7 @@ inline void matrix3x3_reset_fp64(matrix3x3_fp64_t* matrix) // ================== Identity ================== // -inline void matrix3x3_set_to_identity_fp32(matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_to_identity_fp32(bgc_matrix3x3_fp32_t* matrix) { matrix->r1c1 = 1.0f; matrix->r1c2 = 0.0f; @@ -53,7 +53,7 @@ inline void matrix3x3_set_to_identity_fp32(matrix3x3_fp32_t* matrix) matrix->r3c3 = 1.0f; } -inline void matrix3x3_set_to_identity_fp64(matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_to_identity_fp64(bgc_matrix3x3_fp64_t* matrix) { matrix->r1c1 = 1.0; matrix->r1c2 = 0.0; @@ -70,7 +70,7 @@ inline void matrix3x3_set_to_identity_fp64(matrix3x3_fp64_t* matrix) // ================ Make Diagonal =============== // -inline void matrix3x3_set_to_diagonal_fp32(const float d1, const float d2, const float d3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_to_diagonal_fp32(const float d1, const float d2, const float d3, bgc_matrix3x3_fp32_t* matrix) { matrix->r1c1 = d1; matrix->r1c2 = 0.0f; @@ -85,7 +85,7 @@ inline void matrix3x3_set_to_diagonal_fp32(const float d1, const float d2, const matrix->r3c3 = d2; } -inline void matrix3x3_set_to_diagonal_fp64(const double d1, const double d2, const double d3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_to_diagonal_fp64(const double d1, const double d2, const double d3, bgc_matrix3x3_fp64_t* matrix) { matrix->r1c1 = d1; matrix->r1c2 = 0.0; @@ -102,7 +102,7 @@ inline void matrix3x3_set_to_diagonal_fp64(const double d1, const double d2, con // ==================== Copy ==================== // -inline void matrix3x3_copy_fp32(const matrix3x3_fp32_t* from, matrix3x3_fp32_t* to) +inline void bgc_matrix3x3_copy_fp32(const bgc_matrix3x3_fp32_t* from, bgc_matrix3x3_fp32_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -117,7 +117,7 @@ inline void matrix3x3_copy_fp32(const matrix3x3_fp32_t* from, matrix3x3_fp32_t* to->r3c3 = from->r3c3; } -inline void matrix3x3_copy_fp64(const matrix3x3_fp64_t* from, matrix3x3_fp64_t* to) +inline void bgc_matrix3x3_copy_fp64(const bgc_matrix3x3_fp64_t* from, bgc_matrix3x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -134,7 +134,7 @@ inline void matrix3x3_copy_fp64(const matrix3x3_fp64_t* from, matrix3x3_fp64_t* // ==================== Swap ==================== // -inline void matrix3x3_swap_fp32(matrix3x3_fp32_t* matrix1, matrix3x3_fp32_t* matrix2) +inline void bgc_matrix3x3_swap_fp32(bgc_matrix3x3_fp32_t* matrix1, bgc_matrix3x3_fp32_t* matrix2) { const float r1c1 = matrix2->r1c1; const float r1c2 = matrix2->r1c2; @@ -173,7 +173,7 @@ inline void matrix3x3_swap_fp32(matrix3x3_fp32_t* matrix1, matrix3x3_fp32_t* mat matrix1->r3c3 = r3c3; } -inline void matrix3x3_swap_fp64(matrix3x3_fp64_t* matrix1, matrix3x3_fp64_t* matrix2) +inline void bgc_matrix3x3_swap_fp64(bgc_matrix3x3_fp64_t* matrix1, bgc_matrix3x3_fp64_t* matrix2) { const double r1c1 = matrix2->r1c1; const double r1c2 = matrix2->r1c2; @@ -214,7 +214,7 @@ inline void matrix3x3_swap_fp64(matrix3x3_fp64_t* matrix1, matrix3x3_fp64_t* mat // ============= Set from twin type ============= // -inline void matrix3x3_convert_fp64_to_fp32(const matrix3x3_fp64_t* from, matrix3x3_fp32_t* to) +inline void bgc_matrix3x3_convert_fp64_to_fp32(const bgc_matrix3x3_fp64_t* from, bgc_matrix3x3_fp32_t* to) { to->r1c1 = (float) from->r1c1; to->r1c2 = (float) from->r1c2; @@ -229,7 +229,7 @@ inline void matrix3x3_convert_fp64_to_fp32(const matrix3x3_fp64_t* from, matrix3 to->r3c3 = (float) from->r3c3; } -inline void matrix3x3_convert_fp32_to_fp64(const matrix3x3_fp32_t* from, matrix3x3_fp64_t* to) +inline void bgc_matrix3x3_convert_fp32_to_fp64(const bgc_matrix3x3_fp32_t* from, bgc_matrix3x3_fp64_t* to) { to->r1c1 = from->r1c1; to->r1c2 = from->r1c2; @@ -246,14 +246,14 @@ inline void matrix3x3_convert_fp32_to_fp64(const matrix3x3_fp32_t* from, matrix3 // ================ Determinant ================= // -inline float matrix3x3_get_determinant_fp32(const matrix3x3_fp32_t* matrix) +inline float bgc_matrix3x3_get_determinant_fp32(const bgc_matrix3x3_fp32_t* 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); } -inline double matrix3x3_get_determinant_fp64(const matrix3x3_fp64_t* matrix) +inline double bgc_matrix3x3_get_determinant_fp64(const bgc_matrix3x3_fp64_t* matrix) { return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2) + matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3) @@ -262,29 +262,29 @@ inline double matrix3x3_get_determinant_fp64(const matrix3x3_fp64_t* matrix) // ================== Singular ================== // -inline int matrix3x3_is_singular_fp32(const matrix3x3_fp32_t* matrix) +inline int bgc_matrix3x3_is_singular_fp32(const bgc_matrix3x3_fp32_t* matrix) { - const float determinant = matrix3x3_get_determinant_fp32(matrix); + const float determinant = bgc_matrix3x3_get_determinant_fp32(matrix); - return -FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON; + return -BGC_EPSYLON_FP32 <= determinant && determinant <= BGC_EPSYLON_FP32; } -inline int matrix3x3_is_singular_fp64(const matrix3x3_fp64_t* matrix) +inline int bgc_matrix3x3_is_singular_fp64(const bgc_matrix3x3_fp64_t* matrix) { - const double determinant = matrix3x3_get_determinant_fp64(matrix); + const double determinant = bgc_matrix3x3_get_determinant_fp64(matrix); - return -FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON; + return -BGC_EPSYLON_FP64 <= determinant && determinant <= BGC_EPSYLON_FP64; } // ================= Inversion ================== // -int matrix3x3_invert_fp32(matrix3x3_fp32_t* matrix); +int bgc_matrix3x3_invert_fp32(bgc_matrix3x3_fp32_t* matrix); -int matrix3x3_invert_fp64(matrix3x3_fp64_t* matrix); +int bgc_matrix3x3_invert_fp64(bgc_matrix3x3_fp64_t* matrix); // =============== Transposition ================ // -inline void matrix3x3_transpose_fp32(matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_transpose_fp32(bgc_matrix3x3_fp32_t* matrix) { float tmp = matrix->r1c2; matrix->r1c2 = matrix->r2c1; @@ -299,7 +299,7 @@ inline void matrix3x3_transpose_fp32(matrix3x3_fp32_t* matrix) matrix->r3c2 = tmp; } -inline void matrix3x3_transpose_fp64(matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_transpose_fp64(bgc_matrix3x3_fp64_t* matrix) { double tmp = matrix->r1c2; matrix->r1c2 = matrix->r2c1; @@ -316,16 +316,16 @@ inline void matrix3x3_transpose_fp64(matrix3x3_fp64_t* matrix) // ================ Make Inverted =============== // -int matrix3x3_set_inverted_fp32(const matrix3x3_fp32_t* matrix, matrix3x3_fp32_t* result); +int bgc_matrix3x3_set_inverted_fp32(const bgc_matrix3x3_fp32_t* matrix, bgc_matrix3x3_fp32_t* result); -int matrix3x3_set_inverted_fp64(const matrix3x3_fp64_t* matrix, matrix3x3_fp64_t* result); +int bgc_matrix3x3_set_inverted_fp64(const bgc_matrix3x3_fp64_t* matrix, bgc_matrix3x3_fp64_t* result); // =============== Make Transposed ============== // -inline void matrix3x3_set_transposed_fp32(const matrix3x3_fp32_t* matrix, matrix3x3_fp32_t* result) +inline void bgc_matrix3x3_set_transposed_fp32(const bgc_matrix3x3_fp32_t* matrix, bgc_matrix3x3_fp32_t* result) { if (matrix == result) { - matrix3x3_transpose_fp32(result); + bgc_matrix3x3_transpose_fp32(result); return; } @@ -342,10 +342,10 @@ inline void matrix3x3_set_transposed_fp32(const matrix3x3_fp32_t* matrix, matrix result->r3c3 = matrix->r3c3; } -inline void matrix3x3_set_transposed_fp64(const matrix3x3_fp64_t* matrix, matrix3x3_fp64_t* result) +inline void bgc_matrix3x3_set_transposed_fp64(const bgc_matrix3x3_fp64_t* matrix, bgc_matrix3x3_fp64_t* result) { if (matrix == result) { - matrix3x3_transpose_fp64(result); + bgc_matrix3x3_transpose_fp64(result); return; } @@ -364,14 +364,14 @@ inline void matrix3x3_set_transposed_fp64(const matrix3x3_fp64_t* matrix, matrix // ================= Set Row 1 ================== // -inline void matrix3x3_set_row1_fp32(const float c1, const float c2, const float c3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_row1_fp32(const float c1, const float c2, const float c3, bgc_matrix3x3_fp32_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; matrix->r1c3 = c3; } -inline void matrix3x3_set_row1_fp64(const double c1, const double c2, const double c3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_row1_fp64(const double c1, const double c2, const double c3, bgc_matrix3x3_fp64_t* matrix) { matrix->r1c1 = c1; matrix->r1c2 = c2; @@ -380,14 +380,14 @@ inline void matrix3x3_set_row1_fp64(const double c1, const double c2, const doub // ================= Set Row 2 ================== // -inline void matrix3x3_set_row2_fp32(const float c1, const float c2, const float c3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_row2_fp32(const float c1, const float c2, const float c3, bgc_matrix3x3_fp32_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; matrix->r2c3 = c3; } -inline void matrix3x3_set_row2_fp64(const double c1, const double c2, const double c3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_row2_fp64(const double c1, const double c2, const double c3, bgc_matrix3x3_fp64_t* matrix) { matrix->r2c1 = c1; matrix->r2c2 = c2; @@ -396,14 +396,14 @@ inline void matrix3x3_set_row2_fp64(const double c1, const double c2, const doub // ================= Set Row 3 ================== // -inline void matrix3x3_set_row3_fp32(const float c1, const float c2, const float c3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_row3_fp32(const float c1, const float c2, const float c3, bgc_matrix3x3_fp32_t* matrix) { matrix->r3c1 = c1; matrix->r3c2 = c2; matrix->r3c3 = c3; } -inline void matrix3x3_set_row3_fp64(const double c1, const double c2, const double c3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_row3_fp64(const double c1, const double c2, const double c3, bgc_matrix3x3_fp64_t* matrix) { matrix->r3c1 = c1; matrix->r3c2 = c2; @@ -412,14 +412,14 @@ inline void matrix3x3_set_row3_fp64(const double c1, const double c2, const doub // ================ Set Column 1 ================ // -inline void matrix3x3_set_column1_fp32(const float r1, const float r2, const float r3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_column1_fp32(const float r1, const float r2, const float r3, bgc_matrix3x3_fp32_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; matrix->r3c1 = r3; } -inline void matrix3x3_set_column1_fp64(const double r1, const double r2, const double r3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_column1_fp64(const double r1, const double r2, const double r3, bgc_matrix3x3_fp64_t* matrix) { matrix->r1c1 = r1; matrix->r2c1 = r2; @@ -428,14 +428,14 @@ inline void matrix3x3_set_column1_fp64(const double r1, const double r2, const d // ================ Set Column 2 ================ // -inline void matrix3x3_set_column2_fp32(const float r1, const float r2, const float r3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_column2_fp32(const float r1, const float r2, const float r3, bgc_matrix3x3_fp32_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; matrix->r3c2 = r3; } -inline void matrix3x3_set_column2_fp64(const double r1, const double r2, const double r3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_column2_fp64(const double r1, const double r2, const double r3, bgc_matrix3x3_fp64_t* matrix) { matrix->r1c2 = r1; matrix->r2c2 = r2; @@ -444,55 +444,23 @@ inline void matrix3x3_set_column2_fp64(const double r1, const double r2, const d // ================ Set Column 3 ================ // -inline void matrix3x3_set_column3_fp32(const float r1, const float r2, const float r3, matrix3x3_fp32_t* matrix) +inline void bgc_matrix3x3_set_column3_fp32(const float r1, const float r2, const float r3, bgc_matrix3x3_fp32_t* matrix) { matrix->r1c3 = r1; matrix->r2c3 = r2; matrix->r3c3 = r3; } -inline void matrix3x3_set_column3_fp64(const double r1, const double r2, const double r3, matrix3x3_fp64_t* matrix) +inline void bgc_matrix3x3_set_column3_fp64(const double r1, const double r2, const double r3, bgc_matrix3x3_fp64_t* matrix) { matrix->r1c3 = r1; matrix->r2c3 = r2; matrix->r3c3 = r3; } -// ================ Append scaled =============== // - -inline void matrix3x3_add_scaled_fp32(matrix3x3_fp32_t* basic_vector, const matrix3x3_fp32_t* scalable_vector, const float scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - basic_vector->r1c3 += scalable_vector->r1c3 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - basic_vector->r2c3 += scalable_vector->r2c3 * scale; - - basic_vector->r3c1 += scalable_vector->r3c1 * scale; - basic_vector->r3c2 += scalable_vector->r3c2 * scale; - basic_vector->r3c3 += scalable_vector->r3c3 * scale; -} - -inline void matrix3x3_add_scaled_fp64(matrix3x3_fp64_t* basic_vector, const matrix3x3_fp64_t* scalable_vector, const double scale) -{ - basic_vector->r1c1 += scalable_vector->r1c1 * scale; - basic_vector->r1c2 += scalable_vector->r1c2 * scale; - basic_vector->r1c3 += scalable_vector->r1c3 * scale; - - basic_vector->r2c1 += scalable_vector->r2c1 * scale; - basic_vector->r2c2 += scalable_vector->r2c2 * scale; - basic_vector->r2c3 += scalable_vector->r2c3 * scale; - - basic_vector->r3c1 += scalable_vector->r3c1 * scale; - basic_vector->r3c2 += scalable_vector->r3c2 * scale; - basic_vector->r3c3 += scalable_vector->r3c3 * scale; -} - // ================== Addition ================== // -inline void matrix3x3_add_fp32(const matrix3x3_fp32_t* matrix1, const matrix3x3_fp32_t* matrix2, matrix3x3_fp32_t* sum) +inline void bgc_matrix3x3_add_fp32(const bgc_matrix3x3_fp32_t* matrix1, const bgc_matrix3x3_fp32_t* matrix2, bgc_matrix3x3_fp32_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -507,7 +475,7 @@ inline void matrix3x3_add_fp32(const matrix3x3_fp32_t* matrix1, const matrix3x3_ sum->r3c3 = matrix1->r3c3 + matrix2->r3c3; } -inline void matrix3x3_add_fp64(const matrix3x3_fp64_t* matrix1, const matrix3x3_fp64_t* matrix2, matrix3x3_fp64_t* sum) +inline void bgc_matrix3x3_add_fp64(const bgc_matrix3x3_fp64_t* matrix1, const bgc_matrix3x3_fp64_t* matrix2, bgc_matrix3x3_fp64_t* sum) { sum->r1c1 = matrix1->r1c1 + matrix2->r1c1; sum->r1c2 = matrix1->r1c2 + matrix2->r1c2; @@ -522,9 +490,41 @@ inline void matrix3x3_add_fp64(const matrix3x3_fp64_t* matrix1, const matrix3x3_ sum->r3c3 = matrix1->r3c3 + matrix2->r3c3; } +// ================= Add scaled ================= // + +inline void bgc_matrix3x3_add_scaled_fp32(const bgc_matrix3x3_fp32_t* basic_matrix, const bgc_matrix3x3_fp32_t* scalable_matrix, const float scale, bgc_matrix3x3_fp32_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + sum->r1c3 = basic_matrix->r1c3 + scalable_matrix->r1c3 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + sum->r2c3 = basic_matrix->r2c3 + scalable_matrix->r2c3 * scale; + + sum->r3c1 = basic_matrix->r3c1 + scalable_matrix->r3c1 * scale; + sum->r3c2 = basic_matrix->r3c2 + scalable_matrix->r3c2 * scale; + sum->r3c3 = basic_matrix->r3c3 + scalable_matrix->r3c3 * scale; +} + +inline void bgc_matrix3x3_add_scaled_fp64(const bgc_matrix3x3_fp64_t* basic_matrix, const bgc_matrix3x3_fp64_t* scalable_matrix, const double scale, bgc_matrix3x3_fp64_t* sum) +{ + sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale; + sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale; + sum->r1c3 = basic_matrix->r1c3 + scalable_matrix->r1c3 * scale; + + sum->r2c1 = basic_matrix->r2c1 + scalable_matrix->r2c1 * scale; + sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale; + sum->r2c3 = basic_matrix->r2c3 + scalable_matrix->r2c3 * scale; + + sum->r3c1 = basic_matrix->r3c1 + scalable_matrix->r3c1 * scale; + sum->r3c2 = basic_matrix->r3c2 + scalable_matrix->r3c2 * scale; + sum->r3c3 = basic_matrix->r3c3 + scalable_matrix->r3c3 * scale; +} + // ================ Subtraction ================= // -inline void matrix3x3_subtract_fp32(const matrix3x3_fp32_t* minuend, const matrix3x3_fp32_t* subtrahend, matrix3x3_fp32_t* difference) +inline void bgc_matrix3x3_subtract_fp32(const bgc_matrix3x3_fp32_t* minuend, const bgc_matrix3x3_fp32_t* subtrahend, bgc_matrix3x3_fp32_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -539,7 +539,7 @@ inline void matrix3x3_subtract_fp32(const matrix3x3_fp32_t* minuend, const matri difference->r3c3 = minuend->r3c3 - subtrahend->r3c3; } -inline void matrix3x3_subtract_fp64(const matrix3x3_fp64_t* minuend, const matrix3x3_fp64_t* subtrahend, matrix3x3_fp64_t* difference) +inline void bgc_matrix3x3_subtract_fp64(const bgc_matrix3x3_fp64_t* minuend, const bgc_matrix3x3_fp64_t* subtrahend, bgc_matrix3x3_fp64_t* difference) { difference->r1c1 = minuend->r1c1 - subtrahend->r1c1; difference->r1c2 = minuend->r1c2 - subtrahend->r1c2; @@ -556,7 +556,7 @@ inline void matrix3x3_subtract_fp64(const matrix3x3_fp64_t* minuend, const matri // =============== Multiplication =============== // -inline void matrix3x3_multiply_fp32(const matrix3x3_fp32_t* multiplicand, const float multiplier, matrix3x3_fp32_t* product) +inline void bgc_matrix3x3_multiply_fp32(const bgc_matrix3x3_fp32_t* multiplicand, const float multiplier, bgc_matrix3x3_fp32_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -571,7 +571,7 @@ inline void matrix3x3_multiply_fp32(const matrix3x3_fp32_t* multiplicand, const product->r3c3 = multiplicand->r3c3 * multiplier; } -inline void matrix3x3_multiply_fp64(const matrix3x3_fp64_t* multiplicand, const double multiplier, matrix3x3_fp64_t* product) +inline void bgc_matrix3x3_multiply_fp64(const bgc_matrix3x3_fp64_t* multiplicand, const double multiplier, bgc_matrix3x3_fp64_t* product) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -588,19 +588,19 @@ inline void matrix3x3_multiply_fp64(const matrix3x3_fp64_t* multiplicand, const // ================== Division ================== // -inline void matrix3x3_divide_fp32(const matrix3x3_fp32_t* dividend, const float divisor, matrix3x3_fp32_t* quotient) +inline void bgc_matrix3x3_divide_fp32(const bgc_matrix3x3_fp32_t* dividend, const float divisor, bgc_matrix3x3_fp32_t* quotient) { - matrix3x3_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_matrix3x3_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void matrix3x3_fp64_divide(const matrix3x3_fp64_t* dividend, const double divisor, matrix3x3_fp64_t* quotient) +inline void bgc_matrix3x3_divide_fp64(const bgc_matrix3x3_fp64_t* dividend, const double divisor, bgc_matrix3x3_fp64_t* quotient) { - matrix3x3_multiply_fp64(dividend, 1.0 / divisor, quotient); + bgc_matrix3x3_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ============ Left Vector Product ============= // -inline void matrix3x3_left_product_fp32(const vector3_fp32_t* vector, const matrix3x3_fp32_t* matrix, vector3_fp32_t* result) +inline void bgc_matrix3x3_left_product_fp32(const bgc_vector3_fp32_t* vector, const bgc_matrix3x3_fp32_t* matrix, bgc_vector3_fp32_t* result) { const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; @@ -611,7 +611,7 @@ inline void matrix3x3_left_product_fp32(const vector3_fp32_t* vector, const matr result->x3 = x3; } -inline void matrix3x3_left_product_fp64(const vector3_fp64_t* vector, const matrix3x3_fp64_t* matrix, vector3_fp64_t* result) +inline void bgc_matrix3x3_left_product_fp64(const bgc_vector3_fp64_t* vector, const bgc_matrix3x3_fp64_t* matrix, bgc_vector3_fp64_t* result) { const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; @@ -624,7 +624,7 @@ inline void matrix3x3_left_product_fp64(const vector3_fp64_t* vector, const matr // ============ Right Vector Product ============ // -inline void matrix3x3_right_product_fp32(const matrix3x3_fp32_t* matrix, const vector3_fp32_t* vector, vector3_fp32_t* result) +inline void bgc_matrix3x3_right_product_fp32(const bgc_matrix3x3_fp32_t* matrix, const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* result) { const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; @@ -635,7 +635,7 @@ inline void matrix3x3_right_product_fp32(const matrix3x3_fp32_t* matrix, const v result->x3 = x3; } -inline void matrix3x3_right_product_fp64(const matrix3x3_fp64_t* matrix, const vector3_fp64_t* vector, vector3_fp64_t* result) +inline void bgc_matrix3x3_right_product_fp64(const bgc_matrix3x3_fp64_t* matrix, const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* result) { const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; diff --git a/basic-geometry/matrixes.c b/basic-geometry/matrixes.c index f3c496d..82bcbb5 100644 --- a/basic-geometry/matrixes.c +++ b/basic-geometry/matrixes.c @@ -2,7 +2,7 @@ // ========== Matrix Product 2x2 at 3x2 ========= // -void matrix_fp32_product_2x2_at_3x2(const matrix2x2_fp32_t* matrix1, const matrix3x2_fp32_t* matrix2, matrix3x2_fp32_t* result) +void bgc_matrix_product_2x2_at_3x2_fp32(const bgc_matrix2x2_fp32_t* matrix1, const bgc_matrix3x2_fp32_t* matrix2, bgc_matrix3x2_fp32_t* 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 matrix_fp32_product_2x2_at_3x2(const matrix2x2_fp32_t* matrix1, const matri result->r2c3 = r2c3; } -void matrix_fp64_product_2x2_at_3x2(const matrix2x2_fp64_t* matrix1, const matrix3x2_fp64_t* matrix2, matrix3x2_fp64_t* result) +void bgc_matrix_product_2x2_at_3x2_fp64(const bgc_matrix2x2_fp64_t* matrix1, const bgc_matrix3x2_fp64_t* matrix2, bgc_matrix3x2_fp64_t* 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 matrix_fp64_product_2x2_at_3x2(const matrix2x2_fp64_t* matrix1, const matri // ========== Matrix Product 2x3 at 2x2 ========= // -void matrix_fp32_product_2x3_at_2x2(const matrix2x3_fp32_t* matrix1, const matrix2x2_fp32_t* matrix2, matrix2x3_fp32_t* result) +void bgc_matrix_product_2x3_at_2x2_fp32(const bgc_matrix2x3_fp32_t* matrix1, const bgc_matrix2x2_fp32_t* matrix2, bgc_matrix2x3_fp32_t* 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 matrix_fp32_product_2x3_at_2x2(const matrix2x3_fp32_t* matrix1, const matri result->r3c2 = r3c2; } -void matrix_fp64_product_2x3_at_2x2(const matrix2x3_fp64_t* matrix1, const matrix2x2_fp64_t* matrix2, matrix2x3_fp64_t* result) +void bgc_matrix_product_2x3_at_2x2_fp64(const bgc_matrix2x3_fp64_t* matrix1, const bgc_matrix2x2_fp64_t* matrix2, bgc_matrix2x3_fp64_t* 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 matrix_fp64_product_2x3_at_2x2(const matrix2x3_fp64_t* matrix1, const matri // ========== Matrix Product 2x3 at 3x2 ========= // -void matrix_fp32_product_2x3_at_3x2(const matrix2x3_fp32_t* matrix1, const matrix3x2_fp32_t* matrix2, matrix3x3_fp32_t* result) +void bgc_matrix_product_2x3_at_3x2_fp32(const bgc_matrix2x3_fp32_t* matrix1, const bgc_matrix3x2_fp32_t* matrix2, bgc_matrix3x3_fp32_t* 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 matrix_fp32_product_2x3_at_3x2(const matrix2x3_fp32_t* matrix1, const matri result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; } -void matrix_fp64_product_2x3_at_3x2(const matrix2x3_fp64_t* matrix1, const matrix3x2_fp64_t* matrix2, matrix3x3_fp64_t* result) +void bgc_matrix_product_2x3_at_3x2_fp64(const bgc_matrix2x3_fp64_t* matrix1, const bgc_matrix3x2_fp64_t* matrix2, bgc_matrix3x3_fp64_t* 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 matrix_fp64_product_2x3_at_3x2(const matrix2x3_fp64_t* matrix1, const matri // ========== Matrix Product 3x2 at 2x3 ========= // -void matrix_fp32_product_3x2_at_2x3(const matrix3x2_fp32_t* matrix1, const matrix2x3_fp32_t* matrix2, matrix2x2_fp32_t* result) +void bgc_matrix_product_3x2_at_2x3_fp32(const bgc_matrix3x2_fp32_t* matrix1, const bgc_matrix2x3_fp32_t* matrix2, bgc_matrix2x2_fp32_t* 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 matrix_fp32_product_3x2_at_2x3(const matrix3x2_fp32_t* matrix1, const matri result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; } -void matrix_fp64_product_3x2_at_2x3(const matrix3x2_fp64_t* matrix1, const matrix2x3_fp64_t* matrix2, matrix2x2_fp64_t* result) +void bgc_matrix_product_3x2_at_2x3_fp64(const bgc_matrix3x2_fp64_t* matrix1, const bgc_matrix2x3_fp64_t* matrix2, bgc_matrix2x2_fp64_t* 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 matrix_fp64_product_3x2_at_2x3(const matrix3x2_fp64_t* matrix1, const matri // ========== Matrix Product 3x2 at 3x3 ========= // -void matrix_fp32_product_3x2_at_3x3(const matrix3x2_fp32_t* matrix1, const matrix3x3_fp32_t* matrix2, matrix3x2_fp32_t* result) +void bgc_matrix_product_3x2_at_3x3_fp32(const bgc_matrix3x2_fp32_t* matrix1, const bgc_matrix3x3_fp32_t* matrix2, bgc_matrix3x2_fp32_t* 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 matrix_fp32_product_3x2_at_3x3(const matrix3x2_fp32_t* matrix1, const matri result->r2c3 = r2c3; } -void matrix_fp64_product_3x2_at_3x3(const matrix3x2_fp64_t* matrix1, const matrix3x3_fp64_t* matrix2, matrix3x2_fp64_t* result) +void bgc_matrix_product_3x2_at_3x3_fp64(const bgc_matrix3x2_fp64_t* matrix1, const bgc_matrix3x3_fp64_t* matrix2, bgc_matrix3x2_fp64_t* 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 matrix_fp64_product_3x2_at_3x3(const matrix3x2_fp64_t* matrix1, const matri // ========== Matrix Product 3x3 at 2x3 ========= // -void matrix_fp32_product_3x3_at_2x3(const matrix3x3_fp32_t* matrix1, const matrix2x3_fp32_t* matrix2, matrix2x3_fp32_t* result) +void bgc_matrix_product_3x3_at_2x3_fp32(const bgc_matrix3x3_fp32_t* matrix1, const bgc_matrix2x3_fp32_t* matrix2, bgc_matrix2x3_fp32_t* 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 matrix_fp32_product_3x3_at_2x3(const matrix3x3_fp32_t* matrix1, const matri result->r3c2 = r3c2; } -void matrix_fp64_product_3x3_at_2x3(const matrix3x3_fp64_t* matrix1, const matrix2x3_fp64_t* matrix2, matrix2x3_fp64_t* result) +void bgc_matrix_product_3x3_at_2x3_fp64(const bgc_matrix3x3_fp64_t* matrix1, const bgc_matrix2x3_fp64_t* matrix2, bgc_matrix2x3_fp64_t* 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 matrix_fp64_product_3x3_at_2x3(const matrix3x3_fp64_t* matrix1, const matri // ========== Matrix Product 3x3 at 3x3 ========= // -void matrix_fp32_product_3x3_at_3x3(const matrix3x3_fp32_t* matrix1, const matrix3x3_fp32_t* matrix2, matrix3x3_fp32_t* result) +void bgc_matrix_product_3x3_at_3x3_fp32(const bgc_matrix3x3_fp32_t* matrix1, const bgc_matrix3x3_fp32_t* matrix2, bgc_matrix3x3_fp32_t* 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 matrix_fp32_product_3x3_at_3x3(const matrix3x3_fp32_t* matrix1, const matri result->r3c3 = r3c3; } -void matrix_fp64_product_3x3_at_3x3(const matrix3x3_fp64_t* matrix1, const matrix3x3_fp64_t* matrix2, matrix3x3_fp64_t* result) +void bgc_matrix_product_3x3_at_3x3_fp64(const bgc_matrix3x3_fp64_t* matrix1, const bgc_matrix3x3_fp64_t* matrix2, bgc_matrix3x3_fp64_t* 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; diff --git a/basic-geometry/matrixes.h b/basic-geometry/matrixes.h index c634ca5..9ced59a 100644 --- a/basic-geometry/matrixes.h +++ b/basic-geometry/matrixes.h @@ -1,17 +1,17 @@ -#ifndef _BASIC_GEOMETRY_MATRIX_TYPES_H_ -#define _BASIC_GEOMETRY_MATRIX_TYPES_H_ +#ifndef _BGC_MATRIX_TYPES_H_ +#define _BGC_MATRIX_TYPES_H_ // ================== Matrix2x2 ================= // typedef struct { float r1c1, r1c2; float r2c1, r2c2; -} matrix2x2_fp32_t; +} bgc_matrix2x2_fp32_t; typedef struct { double r1c1, r1c2; double r2c1, r2c2; -} matrix2x2_fp64_t; +} bgc_matrix2x2_fp64_t; // ================== Matrix2x3 ================= // @@ -19,25 +19,25 @@ typedef struct { float r1c1, r1c2; float r2c1, r2c2; float r3c1, r3c2; -} matrix2x3_fp32_t; +} bgc_matrix2x3_fp32_t; typedef struct { double r1c1, r1c2; double r2c1, r2c2; double r3c1, r3c2; -} matrix2x3_fp64_t; +} bgc_matrix2x3_fp64_t; // ================== Matrix3x2 ================= // typedef struct { float r1c1, r1c2, r1c3; float r2c1, r2c2, r2c3; -} matrix3x2_fp32_t; +} bgc_matrix3x2_fp32_t; typedef struct { double r1c1, r1c2, r1c3; double r2c1, r2c2, r2c3; -} matrix3x2_fp64_t; +} bgc_matrix3x2_fp64_t; // ================== Matrix3x3 ================= // @@ -45,17 +45,17 @@ typedef struct { float r1c1, r1c2, r1c3; float r2c1, r2c2, r2c3; float r3c1, r3c2, r3c3; -} matrix3x3_fp32_t; +} bgc_matrix3x3_fp32_t; typedef struct { double r1c1, r1c2, r1c3; double r2c1, r2c2, r2c3; double r3c1, r3c2, r3c3; -} matrix3x3_fp64_t; +} bgc_matrix3x3_fp64_t; // ========== Matrix Product 2x2 at 2x2 ========= // -inline void matrix_fp32_product_2x2_at_2x2(const matrix2x2_fp32_t* matrix1, const matrix2x2_fp32_t* matrix2, matrix2x2_fp32_t* result) +inline void bgc_matrix_product_2x2_at_2x2_fp32(const bgc_matrix2x2_fp32_t* matrix1, const bgc_matrix2x2_fp32_t* matrix2, bgc_matrix2x2_fp32_t* 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 @@ inline void matrix_fp32_product_2x2_at_2x2(const matrix2x2_fp32_t* matrix1, cons result->r2c2 = r2c2; } -inline void matrix_fp64_product_2x2_at_2x2(const matrix2x2_fp64_t* matrix1, const matrix2x2_fp64_t* matrix2, matrix2x2_fp64_t* result) +inline void bgc_matrix_product_2x2_at_2x2_fp64(const bgc_matrix2x2_fp64_t* matrix1, const bgc_matrix2x2_fp64_t* matrix2, bgc_matrix2x2_fp64_t* 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 @@ inline void matrix_fp64_product_2x2_at_2x2(const matrix2x2_fp64_t* matrix1, cons // ========== Matrix Product 2x2 at 3x2 ========= // -void matrix_fp32_product_2x2_at_3x2(const matrix2x2_fp32_t* matrix1, const matrix3x2_fp32_t* matrix2, matrix3x2_fp32_t* result); +void bgc_matrix_product_2x2_at_3x2_fp32(const bgc_matrix2x2_fp32_t* matrix1, const bgc_matrix3x2_fp32_t* matrix2, bgc_matrix3x2_fp32_t* result); -void matrix_fp64_product_2x2_at_3x2(const matrix2x2_fp64_t* matrix1, const matrix3x2_fp64_t* matrix2, matrix3x2_fp64_t* result); +void bgc_matrix_product_2x2_at_3x2_fp64(const bgc_matrix2x2_fp64_t* matrix1, const bgc_matrix3x2_fp64_t* matrix2, bgc_matrix3x2_fp64_t* result); // ========== Matrix Product 2x3 at 2x2 ========= // -void matrix_fp32_product_2x3_at_2x2(const matrix2x3_fp32_t* matrix1, const matrix2x2_fp32_t* matrix2, matrix2x3_fp32_t* result); +void bgc_matrix_product_2x3_at_2x2_fp32(const bgc_matrix2x3_fp32_t* matrix1, const bgc_matrix2x2_fp32_t* matrix2, bgc_matrix2x3_fp32_t* result); -void matrix_fp64_product_2x3_at_2x2(const matrix2x3_fp64_t* matrix1, const matrix2x2_fp64_t* matrix2, matrix2x3_fp64_t* result); +void bgc_matrix_product_2x3_at_2x2_fp64(const bgc_matrix2x3_fp64_t* matrix1, const bgc_matrix2x2_fp64_t* matrix2, bgc_matrix2x3_fp64_t* result); // ========== Matrix Product 2x3 at 3x2 ========= // -void matrix_fp32_product_2x3_at_3x2(const matrix2x3_fp32_t* matrix1, const matrix3x2_fp32_t* matrix2, matrix3x3_fp32_t* result); +void bgc_matrix_product_2x3_at_3x2_fp32(const bgc_matrix2x3_fp32_t* matrix1, const bgc_matrix3x2_fp32_t* matrix2, bgc_matrix3x3_fp32_t* result); -void matrix_fp64_product_2x3_at_3x2(const matrix2x3_fp64_t* matrix1, const matrix3x2_fp64_t* matrix2, matrix3x3_fp64_t* result); +void bgc_matrix_product_2x3_at_3x2_fp64(const bgc_matrix2x3_fp64_t* matrix1, const bgc_matrix3x2_fp64_t* matrix2, bgc_matrix3x3_fp64_t* result); // ========== Matrix Product 3x2 at 2x3 ========= // -void matrix_fp32_product_3x2_at_2x3(const matrix3x2_fp32_t* matrix1, const matrix2x3_fp32_t* matrix2, matrix2x2_fp32_t* result); +void bgc_matrix_product_3x2_at_2x3_fp32(const bgc_matrix3x2_fp32_t* matrix1, const bgc_matrix2x3_fp32_t* matrix2, bgc_matrix2x2_fp32_t* result); -void matrix_fp64_product_3x2_at_2x3(const matrix3x2_fp64_t* matrix1, const matrix2x3_fp64_t* matrix2, matrix2x2_fp64_t* result); +void bgc_matrix_product_3x2_at_2x3_fp64(const bgc_matrix3x2_fp64_t* matrix1, const bgc_matrix2x3_fp64_t* matrix2, bgc_matrix2x2_fp64_t* result); // ========== Matrix Product 3x2 at 3x3 ========= // -void matrix_fp32_product_3x2_at_3x3(const matrix3x2_fp32_t* matrix1, const matrix3x3_fp32_t* matrix2, matrix3x2_fp32_t* result); +void bgc_matrix_product_3x2_at_3x3_fp32(const bgc_matrix3x2_fp32_t* matrix1, const bgc_matrix3x3_fp32_t* matrix2, bgc_matrix3x2_fp32_t* result); -void matrix_fp64_product_3x2_at_3x3(const matrix3x2_fp64_t* matrix1, const matrix3x3_fp64_t* matrix2, matrix3x2_fp64_t* result); +void bgc_matrix_product_3x2_at_3x3_fp64(const bgc_matrix3x2_fp64_t* matrix1, const bgc_matrix3x3_fp64_t* matrix2, bgc_matrix3x2_fp64_t* result); // ========== Matrix Product 3x3 at 2x3 ========= // -void matrix_fp32_product_3x3_at_2x3(const matrix3x3_fp32_t* matrix1, const matrix2x3_fp32_t* matrix2, matrix2x3_fp32_t* result); +void bgc_matrix_product_3x3_at_2x3_fp32(const bgc_matrix3x3_fp32_t* matrix1, const bgc_matrix2x3_fp32_t* matrix2, bgc_matrix2x3_fp32_t* result); -void matrix_fp64_product_3x3_at_2x3(const matrix3x3_fp64_t* matrix1, const matrix2x3_fp64_t* matrix2, matrix2x3_fp64_t* result); +void bgc_matrix_product_3x3_at_2x3_fp64(const bgc_matrix3x3_fp64_t* matrix1, const bgc_matrix2x3_fp64_t* matrix2, bgc_matrix2x3_fp64_t* result); // ========== Matrix Product 3x3 at 3x3 ========= // -void matrix_fp32_product_3x3_at_3x3(const matrix3x3_fp32_t* matrix1, const matrix3x3_fp32_t* matrix2, matrix3x3_fp32_t* result); +void bgc_matrix_product_3x3_at_3x3_fp32(const bgc_matrix3x3_fp32_t* matrix1, const bgc_matrix3x3_fp32_t* matrix2, bgc_matrix3x3_fp32_t* result); -void matrix_fp64_product_3x3_at_3x3(const matrix3x3_fp64_t* matrix1, const matrix3x3_fp64_t* matrix2, matrix3x3_fp64_t* result); +void bgc_matrix_product_3x3_at_3x3_fp64(const bgc_matrix3x3_fp64_t* matrix1, const bgc_matrix3x3_fp64_t* matrix2, bgc_matrix3x3_fp64_t* result); -#endif // _GEOMETRY_MATRIX_TYPES_H_ +#endif // _BGC_MATRIX_TYPES_H_ diff --git a/basic-geometry/quaternion.h b/basic-geometry/quaternion.h index 816fa8d..795a9ea 100644 --- a/basic-geometry/quaternion.h +++ b/basic-geometry/quaternion.h @@ -1,23 +1,23 @@ -#ifndef _BASIC_GEOMETRY_QUATERNION_H_ -#define _BASIC_GEOMETRY_QUATERNION_H_ +#ifndef _BGC_QUATERNION_H_ +#define _BGC_QUATERNION_H_ #include -#include "basis.h" +#include "utilities.h" #include "angle.h" #include "matrix3x3.h" typedef struct { float s0, x1, x2, x3; -} quaternion_fp32_t; +} bgc_quaternion_fp32_t; typedef struct { double s0, x1, x2, x3; -} quaternion_fp64_t; +} bgc_quaternion_fp64_t; // ==================== Reset =================== // -inline void quaternion_reset_fp32(quaternion_fp32_t * quaternion) +inline void bgc_quaternion_reset_fp32(bgc_quaternion_fp32_t * quaternion) { quaternion->s0 = 0.0f; quaternion->x1 = 0.0f; @@ -25,7 +25,7 @@ inline void quaternion_reset_fp32(quaternion_fp32_t * quaternion) quaternion->x3 = 0.0f; } -inline void quaternion_reset_fp64(quaternion_fp64_t * quaternion) +inline void bgc_quaternion_reset_fp64(bgc_quaternion_fp64_t * quaternion) { quaternion->s0 = 0.0; quaternion->x1 = 0.0; @@ -35,7 +35,7 @@ inline void quaternion_reset_fp64(quaternion_fp64_t * quaternion) // ================== Set Unit ================== // -inline void quaternion_set_to_identity_fp32(quaternion_fp32_t * quaternion) +inline void bgc_quaternion_set_to_identity_fp32(bgc_quaternion_fp32_t * quaternion) { quaternion->s0 = 1.0f; quaternion->x1 = 0.0f; @@ -43,7 +43,7 @@ inline void quaternion_set_to_identity_fp32(quaternion_fp32_t * quaternion) quaternion->x3 = 0.0f; } -inline void quaternion_set_to_identity_fp64(quaternion_fp64_t * quaternion) +inline void bgc_quaternion_set_to_identity_fp64(bgc_quaternion_fp64_t * quaternion) { quaternion->s0 = 1.0; quaternion->x1 = 0.0; @@ -53,7 +53,7 @@ inline void quaternion_set_to_identity_fp64(quaternion_fp64_t * quaternion) // ==================== Set ===================== // -inline void quaternion_set_values_fp32(const float s0, const float x1, const float x2, const float x3, quaternion_fp32_t * quaternion) +inline void bgc_quaternion_set_values_fp32(const float s0, const float x1, const float x2, const float x3, bgc_quaternion_fp32_t * quaternion) { quaternion->s0 = s0; quaternion->x1 = x1; @@ -61,7 +61,7 @@ inline void quaternion_set_values_fp32(const float s0, const float x1, const flo quaternion->x3 = x3; } -inline void quaternion_set_values_fp64(const double s0, const double x1, const double x2, const double x3, quaternion_fp64_t * quaternion) +inline void bgc_quaternion_set_values_fp64(const double s0, const double x1, const double x2, const double x3, bgc_quaternion_fp64_t * quaternion) { quaternion->s0 = s0; quaternion->x1 = x1; @@ -71,7 +71,7 @@ inline void quaternion_set_values_fp64(const double s0, const double x1, const d // ==================== Copy ==================== // -inline void quaternion_copy_fp32(const quaternion_fp32_t* from, quaternion_fp32_t* to) +inline void bgc_quaternion_copy_fp32(const bgc_quaternion_fp32_t* from, bgc_quaternion_fp32_t* to) { to->s0 = from->s0; to->x1 = from->x1; @@ -79,7 +79,7 @@ inline void quaternion_copy_fp32(const quaternion_fp32_t* from, quaternion_fp32_ to->x3 = from->x3; } -inline void quaternion_copy_fp64(const quaternion_fp64_t* from, quaternion_fp64_t* to) +inline void bgc_quaternion_copy_fp64(const bgc_quaternion_fp64_t* from, bgc_quaternion_fp64_t* to) { to->s0 = from->s0; to->x1 = from->x1; @@ -89,7 +89,7 @@ inline void quaternion_copy_fp64(const quaternion_fp64_t* from, quaternion_fp64_ // ==================== Swap ==================== // -inline void quaternion_swap_fp32(quaternion_fp32_t* quarternion1, quaternion_fp32_t* quarternion2) +inline void bgc_quaternion_swap_fp32(bgc_quaternion_fp32_t* quarternion1, bgc_quaternion_fp32_t* quarternion2) { const float s0 = quarternion2->s0; const float x1 = quarternion2->x1; @@ -107,7 +107,7 @@ inline void quaternion_swap_fp32(quaternion_fp32_t* quarternion1, quaternion_fp3 quarternion1->x3 = x3; } -inline void quaternion_swap_fp64(quaternion_fp64_t* quarternion1, quaternion_fp64_t* quarternion2) +inline void bgc_quaternion_swap_fp64(bgc_quaternion_fp64_t* quarternion1, bgc_quaternion_fp64_t* quarternion2) { const double s0 = quarternion2->s0; const double x1 = quarternion2->x1; @@ -127,7 +127,7 @@ inline void quaternion_swap_fp64(quaternion_fp64_t* quarternion1, quaternion_fp6 // ============= Copy to twin type ============== // -inline void quaternion_convert_fp64_to_fp32(const quaternion_fp64_t* quaternion, quaternion_fp32_t* result) +inline void bgc_quaternion_convert_fp64_to_fp32(const bgc_quaternion_fp64_t* quaternion, bgc_quaternion_fp32_t* result) { result->s0 = (float) quaternion->s0; result->x1 = (float) quaternion->x1; @@ -135,7 +135,7 @@ inline void quaternion_convert_fp64_to_fp32(const quaternion_fp64_t* quaternion, result->x3 = (float) quaternion->x3; } -inline void quaternion_convert_fp32_to_fp64(const quaternion_fp32_t* quaternion, quaternion_fp64_t* result) +inline void bgc_quaternion_convert_fp32_to_fp64(const bgc_quaternion_fp32_t* quaternion, bgc_quaternion_fp64_t* result) { result->s0 = quaternion->s0; result->x1 = quaternion->x1; @@ -145,14 +145,14 @@ inline void quaternion_convert_fp32_to_fp64(const quaternion_fp32_t* quaternion, // ================= Inversion ================== // -inline void quaternion_conjugate_fp32(quaternion_fp32_t* quaternion) +inline void bgc_quaternion_conjugate_fp32(bgc_quaternion_fp32_t* quaternion) { quaternion->x1 = -quaternion->x1; quaternion->x2 = -quaternion->x2; quaternion->x3 = -quaternion->x3; } -inline void quaternion_conjugate_fp64(quaternion_fp64_t* quaternion) +inline void bgc_quaternion_conjugate_fp64(bgc_quaternion_fp64_t* quaternion) { quaternion->x1 = -quaternion->x1; quaternion->x2 = -quaternion->x2; @@ -161,7 +161,7 @@ inline void quaternion_conjugate_fp64(quaternion_fp64_t* quaternion) // ================ Set Conjugate =============== // -inline void quaternion_set_conjugate_fp32(const quaternion_fp32_t* quaternion, quaternion_fp32_t* result) +inline void bgc_quaternion_set_conjugate_fp32(const bgc_quaternion_fp32_t* quaternion, bgc_quaternion_fp32_t* result) { result->s0 = quaternion->s0; result->x1 = -quaternion->x1; @@ -169,7 +169,7 @@ inline void quaternion_set_conjugate_fp32(const quaternion_fp32_t* quaternion, q result->x3 = -quaternion->x3; } -inline void quaternion_set_conjugate_fp64(const quaternion_fp64_t* quaternion, quaternion_fp64_t* result) +inline void bgc_quaternion_set_conjugate_fp64(const bgc_quaternion_fp64_t* quaternion, bgc_quaternion_fp64_t* result) { result->s0 = quaternion->s0; result->x1 = -quaternion->x1; @@ -179,7 +179,7 @@ inline void quaternion_set_conjugate_fp64(const quaternion_fp64_t* quaternion, q // ================ Set Conjugate =============== // -inline void quaternion_set_conjugate_fp64_to_fp32(const quaternion_fp64_t* quaternion, quaternion_fp32_t* result) +inline void bgc_quaternion_set_conjugate_fp64_to_fp32(const bgc_quaternion_fp64_t* quaternion, bgc_quaternion_fp32_t* result) { result->s0 = (float) quaternion->s0; result->x1 = (float) -quaternion->x1; @@ -187,7 +187,7 @@ inline void quaternion_set_conjugate_fp64_to_fp32(const quaternion_fp64_t* quate result->x3 = (float) -quaternion->x3; } -inline void quaternion_set_conjugate_fp32_to_fp64(const quaternion_fp32_t* quaternion, quaternion_fp64_t* result) +inline void bgc_quaternion_set_conjugate_fp32_to_fp64(const bgc_quaternion_fp32_t* quaternion, bgc_quaternion_fp64_t* result) { result->s0 = quaternion->s0; result->x1 = -quaternion->x1; @@ -197,40 +197,40 @@ inline void quaternion_set_conjugate_fp32_to_fp64(const quaternion_fp32_t* quate // ============= Get Square Modulus ============= // -inline float quaternion_get_square_modulus_fp32(const quaternion_fp32_t* quaternion) +inline float bgc_quaternion_get_square_modulus_fp32(const bgc_quaternion_fp32_t* quaternion) { return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3); } -inline double quaternion_get_square_modulus_fp64(const quaternion_fp64_t* quaternion) +inline double bgc_quaternion_get_square_modulus_fp64(const bgc_quaternion_fp64_t* quaternion) { return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3); } // ================ Get Modulus ================= // -inline float quaternion_get_modulus_fp32(const quaternion_fp32_t* quaternion) +inline float bgc_quaternion_get_modulus_fp32(const bgc_quaternion_fp32_t* quaternion) { - return sqrtf(quaternion_get_square_modulus_fp32(quaternion)); + return sqrtf(bgc_quaternion_get_square_modulus_fp32(quaternion)); } -inline double quaternion_get_modulus_fp64(const quaternion_fp64_t* quaternion) +inline double bgc_quaternion_get_modulus_fp64(const bgc_quaternion_fp64_t* quaternion) { - return sqrt(quaternion_get_square_modulus_fp64(quaternion)); + return sqrt(bgc_quaternion_get_square_modulus_fp64(quaternion)); } // =============== Normalization ================ // -inline int quaternion_normalize_fp32(quaternion_fp32_t* quaternion) +inline int bgc_quaternion_normalize_fp32(bgc_quaternion_fp32_t* quaternion) { - const float square_modulus = quaternion_get_square_modulus_fp32(quaternion); + const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion); - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return 1; } - if (square_modulus <= FP32_SQUARE_EPSYLON) { - quaternion_reset_fp32(quaternion); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) { + bgc_quaternion_reset_fp32(quaternion); return 0; } @@ -244,16 +244,16 @@ inline int quaternion_normalize_fp32(quaternion_fp32_t* quaternion) return 1; } -inline int quaternion_normalize_fp64(quaternion_fp64_t* quaternion) +inline int bgc_quaternion_normalize_fp64(bgc_quaternion_fp64_t* quaternion) { - const double square_modulus = quaternion_get_square_modulus_fp64(quaternion); + const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion); - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return 1; } - if (square_modulus <= FP32_SQUARE_EPSYLON) { - quaternion_reset_fp64(quaternion); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) { + bgc_quaternion_reset_fp64(quaternion); return 0; } @@ -269,7 +269,7 @@ inline int quaternion_normalize_fp64(quaternion_fp64_t* quaternion) // ============ Make Rotation Matrix ============ // -inline void quaternion_get_rotation_matrix_fp32(const quaternion_fp32_t* quaternion, matrix3x3_fp32_t* matrix) +inline void bgc_quaternion_get_rotation_matrix_fp32(const bgc_quaternion_fp32_t* quaternion, bgc_matrix3x3_fp32_t* matrix) { const float s0s0 = quaternion->s0 * quaternion->s0; const float x1x1 = quaternion->x1 * quaternion->x1; @@ -278,9 +278,9 @@ inline void quaternion_get_rotation_matrix_fp32(const quaternion_fp32_t* quatern const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); - if (-FP32_EPSYLON <= square_modulus && square_modulus <= FP32_EPSYLON) + if (-BGC_EPSYLON_FP32 <= square_modulus && square_modulus <= BGC_EPSYLON_FP32) { - matrix3x3_set_to_identity_fp32(matrix); + bgc_matrix3x3_set_to_identity_fp32(matrix); return; } @@ -307,7 +307,7 @@ inline void quaternion_get_rotation_matrix_fp32(const quaternion_fp32_t* quatern matrix->r1c3 = corrector2 * (x1x3 + s0x2); } -inline void quaternion_get_rotation_matrix_fp64(const quaternion_fp64_t* quaternion, matrix3x3_fp64_t* matrix) +inline void bgc_quaternion_get_rotation_matrix_fp64(const bgc_quaternion_fp64_t* quaternion, bgc_matrix3x3_fp64_t* matrix) { const double s0s0 = quaternion->s0 * quaternion->s0; const double x1x1 = quaternion->x1 * quaternion->x1; @@ -316,9 +316,9 @@ inline void quaternion_get_rotation_matrix_fp64(const quaternion_fp64_t* quatern const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); - if (-FP64_EPSYLON <= square_modulus && square_modulus <= FP64_EPSYLON) + if (-BGC_EPSYLON_FP64 <= square_modulus && square_modulus <= BGC_EPSYLON_FP64) { - matrix3x3_set_to_identity_fp64(matrix); + bgc_matrix3x3_set_to_identity_fp64(matrix); return; } @@ -347,7 +347,7 @@ inline void quaternion_get_rotation_matrix_fp64(const quaternion_fp64_t* quatern // ============ Make Reverse Matrix ============= // -inline void quaternion_get_reverse_matrix_fp32(const quaternion_fp32_t* quaternion, matrix3x3_fp32_t* matrix) +inline void bgc_quaternion_get_reverse_matrix_fp32(const bgc_quaternion_fp32_t* quaternion, bgc_matrix3x3_fp32_t* matrix) { const float s0s0 = quaternion->s0 * quaternion->s0; const float x1x1 = quaternion->x1 * quaternion->x1; @@ -356,9 +356,9 @@ inline void quaternion_get_reverse_matrix_fp32(const quaternion_fp32_t* quaterni const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); - if (-FP32_EPSYLON <= square_modulus && square_modulus <= FP32_EPSYLON) + if (-BGC_EPSYLON_FP32 <= square_modulus && square_modulus <= BGC_EPSYLON_FP32) { - matrix3x3_set_to_identity_fp32(matrix); + bgc_matrix3x3_set_to_identity_fp32(matrix); return; } @@ -385,7 +385,7 @@ inline void quaternion_get_reverse_matrix_fp32(const quaternion_fp32_t* quaterni matrix->r1c3 = corrector2 * (x1x3 - s0x2); } -inline void quaternion_get_reverse_matrix_fp64(const quaternion_fp64_t* quaternion, matrix3x3_fp64_t* matrix) +inline void bgc_quaternion_get_reverse_matrix_fp64(const bgc_quaternion_fp64_t* quaternion, bgc_matrix3x3_fp64_t* matrix) { const double s0s0 = quaternion->s0 * quaternion->s0; const double x1x1 = quaternion->x1 * quaternion->x1; @@ -394,9 +394,9 @@ inline void quaternion_get_reverse_matrix_fp64(const quaternion_fp64_t* quaterni const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3); - if (-FP64_EPSYLON <= square_modulus && square_modulus <= FP64_EPSYLON) + if (-BGC_EPSYLON_FP64 <= square_modulus && square_modulus <= BGC_EPSYLON_FP64) { - matrix3x3_set_to_identity_fp64(matrix); + bgc_matrix3x3_set_to_identity_fp64(matrix); return; } @@ -425,25 +425,43 @@ inline void quaternion_get_reverse_matrix_fp64(const quaternion_fp64_t* quaterni // ==================== Add ===================== // -inline void quaternion_add_fp32(const quaternion_fp32_t * quaternion1, const quaternion_fp32_t * quaternion2, quaternion_fp32_t * result) +inline void bgc_quaternion_add_fp32(const bgc_quaternion_fp32_t * quaternion1, const bgc_quaternion_fp32_t * quaternion2, bgc_quaternion_fp32_t * sum) { - result->s0 = quaternion1->s0 + quaternion2->s0; - result->x1 = quaternion1->x1 + quaternion2->x1; - result->x2 = quaternion1->x2 + quaternion2->x2; - result->x3 = quaternion1->x3 + quaternion2->x3; + sum->s0 = quaternion1->s0 + quaternion2->s0; + sum->x1 = quaternion1->x1 + quaternion2->x1; + sum->x2 = quaternion1->x2 + quaternion2->x2; + sum->x3 = quaternion1->x3 + quaternion2->x3; } -inline void quaternion_add_fp64(const quaternion_fp64_t * quaternion1, const quaternion_fp64_t * quaternion2, quaternion_fp64_t * result) +inline void bgc_quaternion_add_fp64(const bgc_quaternion_fp64_t * quaternion1, const bgc_quaternion_fp64_t * quaternion2, bgc_quaternion_fp64_t * sum) { - result->s0 = quaternion1->s0 + quaternion2->s0; - result->x1 = quaternion1->x1 + quaternion2->x1; - result->x2 = quaternion1->x2 + quaternion2->x2; - result->x3 = quaternion1->x3 + quaternion2->x3; + sum->s0 = quaternion1->s0 + quaternion2->s0; + sum->x1 = quaternion1->x1 + quaternion2->x1; + sum->x2 = quaternion1->x2 + quaternion2->x2; + sum->x3 = quaternion1->x3 + quaternion2->x3; +} + +// ================= Add Scaled ================= // + +inline void bgc_quaternion_add_scaled_fp32(const bgc_quaternion_fp32_t * basic_quaternion, const bgc_quaternion_fp32_t * scalable_quaternion, const float scale, bgc_quaternion_fp32_t * sum) +{ + sum->s0 = basic_quaternion->s0 + scalable_quaternion->s0 * scale; + sum->x1 = basic_quaternion->x1 + scalable_quaternion->x1 * scale; + sum->x2 = basic_quaternion->x2 + scalable_quaternion->x2 * scale; + sum->x3 = basic_quaternion->x3 + scalable_quaternion->x3 * scale; +} + +inline void bgc_quaternion_add_scaled_fp64(const bgc_quaternion_fp64_t * basic_quaternion, const bgc_quaternion_fp64_t * scalable_quaternion, const double scale, bgc_quaternion_fp64_t * sum) +{ + sum->s0 = basic_quaternion->s0 + scalable_quaternion->s0 * scale; + sum->x1 = basic_quaternion->x1 + scalable_quaternion->x1 * scale; + sum->x2 = basic_quaternion->x2 + scalable_quaternion->x2 * scale; + sum->x3 = basic_quaternion->x3 + scalable_quaternion->x3 * scale; } // ================== Subtract ================== // -inline void quaternion_subtract_fp32(const quaternion_fp32_t * minuend, const quaternion_fp32_t * subtrahend, quaternion_fp32_t * difference) +inline void bgc_quaternion_subtract_fp32(const bgc_quaternion_fp32_t * minuend, const bgc_quaternion_fp32_t * subtrahend, bgc_quaternion_fp32_t * difference) { difference->s0 = minuend->s0 - subtrahend->s0; difference->x1 = minuend->x1 - subtrahend->x1; @@ -451,7 +469,7 @@ inline void quaternion_subtract_fp32(const quaternion_fp32_t * minuend, const qu difference->x3 = minuend->x3 - subtrahend->x3; } -inline void quaternion_subtract_fp64(const quaternion_fp64_t * minuend, const quaternion_fp64_t * subtrahend, quaternion_fp64_t * difference) +inline void bgc_quaternion_subtract_fp64(const bgc_quaternion_fp64_t * minuend, const bgc_quaternion_fp64_t * subtrahend, bgc_quaternion_fp64_t * difference) { difference->s0 = minuend->s0 - subtrahend->s0; difference->x1 = minuend->x1 - subtrahend->x1; @@ -461,7 +479,7 @@ inline void quaternion_subtract_fp64(const quaternion_fp64_t * minuend, const qu // =============== Multiplication =============== // -inline void quaternion_multiply_fp32(const quaternion_fp32_t* multiplicand, const float multipier, quaternion_fp32_t* product) +inline void bgc_quaternion_multiply_fp32(const bgc_quaternion_fp32_t* multiplicand, const float multipier, bgc_quaternion_fp32_t* product) { product->s0 = multiplicand->s0 * multipier; product->x1 = multiplicand->x1 * multipier; @@ -469,7 +487,7 @@ inline void quaternion_multiply_fp32(const quaternion_fp32_t* multiplicand, cons product->x3 = multiplicand->x3 * multipier; } -inline void quaternion_multiply_fp64(const quaternion_fp64_t* multiplicand, const double multipier, quaternion_fp64_t* product) +inline void bgc_quaternion_multiply_fp64(const bgc_quaternion_fp64_t* multiplicand, const double multipier, bgc_quaternion_fp64_t* product) { product->s0 = multiplicand->s0 * multipier; product->x1 = multiplicand->x1 * multipier; @@ -479,19 +497,19 @@ inline void quaternion_multiply_fp64(const quaternion_fp64_t* multiplicand, cons // ================== Division ================== // -inline void quaternion_divide_fp32(const quaternion_fp32_t* dividend, const float divisor, quaternion_fp32_t* quotient) +inline void bgc_quaternion_divide_fp32(const bgc_quaternion_fp32_t* dividend, const float divisor, bgc_quaternion_fp32_t* quotient) { - quaternion_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_quaternion_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void quaternion_fp64_divide(const quaternion_fp64_t* dividend, const double divisor, quaternion_fp64_t* quotient) +inline void bgc_quaternion_divide_fp64(const bgc_quaternion_fp64_t* dividend, const double divisor, bgc_quaternion_fp64_t* quotient) { - quaternion_multiply_fp64(dividend, 1.0 / divisor, quotient); + bgc_quaternion_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ================== Product =================== // -inline void quaternion_get_product_fp32(const quaternion_fp32_t* left, const quaternion_fp32_t* right, quaternion_fp32_t* product) +inline void bgc_quaternion_get_product_fp32(const bgc_quaternion_fp32_t* left, const bgc_quaternion_fp32_t* right, bgc_quaternion_fp32_t* product) { 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); @@ -504,7 +522,7 @@ inline void quaternion_get_product_fp32(const quaternion_fp32_t* left, const qua product->x3 = x3; } -inline void quaternion_get_product_fp64(const quaternion_fp64_t* left, const quaternion_fp64_t* right, quaternion_fp64_t* product) +inline void bgc_quaternion_get_product_fp64(const bgc_quaternion_fp64_t* left, const bgc_quaternion_fp64_t* right, bgc_quaternion_fp64_t* product) { 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); @@ -517,4 +535,4 @@ inline void quaternion_get_product_fp64(const quaternion_fp64_t* left, const qua product->x3 = x3; } -#endif // _GEOMETRY_QUATERNION_H_ +#endif // _BGC_QUATERNION_H_ diff --git a/basic-geometry/rotation3.c b/basic-geometry/rotation3.c index b413fcf..b9bd481 100644 --- a/basic-geometry/rotation3.c +++ b/basic-geometry/rotation3.c @@ -1,5 +1,5 @@ #include "rotation3.h" -const rotation3_fp32_t FP32_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f}; +const bgc_rotation3_fp32_t BGC_IDLE_ROTATION3_FP32 = { {0.0f, 0.0f, 0.0f}, 0.0f}; -const rotation3_fp64_t FP64_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0}; +const bgc_rotation3_fp64_t BGC_IDLE_ROTATION3_FP64 = { {0.0, 0.0, 0.0}, 0.0}; diff --git a/basic-geometry/rotation3.h b/basic-geometry/rotation3.h index 93aa57d..db9b9ba 100644 --- a/basic-geometry/rotation3.h +++ b/basic-geometry/rotation3.h @@ -1,27 +1,27 @@ -#ifndef _BASIC_GEOMETRY_ROTATION3_H_ -#define _BASIC_GEOMETRY_ROTATION3_H_ +#ifndef _BGC_ROTATION3_H_ +#define _BGC_ROTATION3_H_ -#include "basis.h" +#include "utilities.h" #include "angle.h" #include "vector3.h" typedef struct { - vector3_fp32_t axis; + bgc_vector3_fp32_t axis; float radians; -} rotation3_fp32_t; +} bgc_rotation3_fp32_t; typedef struct { - vector3_fp64_t axis; + bgc_vector3_fp64_t axis; double radians; -} rotation3_fp64_t; +} bgc_rotation3_fp64_t; -extern const rotation3_fp32_t FP32_IDLE_ROTATION3; +extern const bgc_rotation3_fp32_t BGC_IDLE_ROTATION3_FP32; -extern const rotation3_fp64_t FP64_IDLE_ROTATION3; +extern const bgc_rotation3_fp64_t BGC_IDLE_ROTATION3_FP64; // =================== Reset ==================== // -inline void fp32_rotation_reset(rotation3_fp32_t* rotation) +inline void bgc_rotation3_reset_fp32(bgc_rotation3_fp32_t* rotation) { rotation->axis.x1 = 0.0f; rotation->axis.x2 = 0.0f; @@ -30,7 +30,7 @@ inline void fp32_rotation_reset(rotation3_fp32_t* rotation) rotation->radians = 0.0f; } -inline void fp64_rotation_reset(rotation3_fp64_t* rotation) +inline void bgc_rotation3_reset_fp64(bgc_rotation3_fp64_t* rotation) { rotation->axis.x1 = 0.0; rotation->axis.x2 = 0.0; @@ -41,14 +41,14 @@ inline void fp64_rotation_reset(rotation3_fp64_t* rotation) // ==================== Make ==================== // -inline void fp32_rotation_set_values(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, rotation3_fp32_t* rotation) +inline void bgc_rotation3_set_values_fp32(const float x1, const float x2, const float x3, const float angle, const bgc_angle_unit_t unit, bgc_rotation3_fp32_t* rotation) { rotation->axis.x1 = x1; rotation->axis.x2 = x2; rotation->axis.x3 = x3; - if (vector3_normalize_fp32(&rotation->axis)) { - rotation->radians = fp32_angle_to_radians(angle, unit); + if (bgc_vector3_normalize_fp32(&rotation->axis)) { + rotation->radians = bgc_angle_to_radians_fp32(angle, unit); } else { rotation->radians = 0.0f; @@ -56,42 +56,42 @@ inline void fp32_rotation_set_values(const float x1, const float x2, const float } -inline void fp64_rotation_set_values(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, rotation3_fp64_t* rotation) +inline void bgc_rotation3_set_values_fp64(const double x1, const double x2, const double x3, const double angle, const bgc_angle_unit_t unit, bgc_rotation3_fp64_t* rotation) { rotation->axis.x1 = x1; rotation->axis.x2 = x2; rotation->axis.x3 = x3; - if (vector3_normalize_fp64(&rotation->axis)) { - rotation->radians = fp64_angle_to_radians(angle, unit); + if (bgc_vector3_normalize_fp64(&rotation->axis)) { + rotation->radians = bgc_angle_to_radians_fp64(angle, unit); } else { rotation->radians = 0.0; } } -inline void fp32_rotation_set_with_axis(const vector3_fp32_t* axis, const float angle, const angle_unit_t unit, rotation3_fp32_t* rotation) +inline void bgc_rotation3_set_with_axis_fp32(const bgc_vector3_fp32_t* axis, const float angle, const bgc_angle_unit_t unit, bgc_rotation3_fp32_t* rotation) { rotation->axis.x1 = axis->x1; rotation->axis.x2 = axis->x2; rotation->axis.x3 = axis->x3; - if (vector3_normalize_fp32(&rotation->axis)) { - rotation->radians = fp32_angle_to_radians(angle, unit); + if (bgc_vector3_normalize_fp32(&rotation->axis)) { + rotation->radians = bgc_angle_to_radians_fp32(angle, unit); } else { rotation->radians = 0.0f; } } -inline void fp64_rotation_set_with_axis(const vector3_fp64_t* axis, const double angle, const angle_unit_t unit, rotation3_fp64_t* rotation) +inline void bgc_rotation3_set_with_axis_fp64(const bgc_vector3_fp64_t* axis, const double angle, const bgc_angle_unit_t unit, bgc_rotation3_fp64_t* rotation) { rotation->axis.x1 = axis->x1; rotation->axis.x2 = axis->x2; rotation->axis.x3 = axis->x3; - if (vector3_normalize_fp64(&rotation->axis)) { - rotation->radians = fp64_angle_to_radians(angle, unit); + if (bgc_vector3_normalize_fp64(&rotation->axis)) { + rotation->radians = bgc_angle_to_radians_fp64(angle, unit); } else { rotation->radians = 0.0; diff --git a/basic-geometry/tangent.c b/basic-geometry/tangent.c index 7b48806..32d2eb5 100644 --- a/basic-geometry/tangent.c +++ b/basic-geometry/tangent.c @@ -1,5 +1,5 @@ #include "tangent.h" -const tangent_fp32_t FP32_IDLE_TANGENT = { 1.0f, 0.0f }; +const bgc_tangent_fp32_t BGC_IDLE_TANGENT_FP32 = { 1.0f, 0.0f }; -const tangent_fp64_t FP64_IDLE_TANGENT = { 1.0, 0.0 }; +const bgc_tangent_fp64_t BGC_IDLE_TANGENT_FP64 = { 1.0, 0.0 }; diff --git a/basic-geometry/tangent.h b/basic-geometry/tangent.h index ec29dc6..7d11be6 100644 --- a/basic-geometry/tangent.h +++ b/basic-geometry/tangent.h @@ -1,9 +1,9 @@ -#ifndef _BASIC_GEOMETRY_TANGENT_H_ -#define _BASIC_GEOMETRY_TANGENT_H_ +#ifndef _BGC_TANGENT_H_ +#define _BGC_TANGENT_H_ #include -#include "basis.h" +#include "utilities.h" #include "angle.h" #include "vector2.h" #include "matrix2x2.h" @@ -13,41 +13,41 @@ typedef struct { const float cos, sin; -} tangent_fp32_t; +} bgc_tangent_fp32_t; typedef struct { const double cos, sin; -} tangent_fp64_t; +} bgc_tangent_fp64_t; // ================= Dark Twins ================= // typedef struct { float cos, sin; -} __BgFP32DarkTwinTangent; +} _bgc_dark_twin_tangent_fp32_t; typedef struct { double cos, sin; -} __BgFP64DarkTwinTangent; +} _bgc_dark_twin_tangent_fp64_t; // ================= Constants ================== // -extern const tangent_fp32_t FP32_IDLE_TANGENT; -extern const tangent_fp64_t FP64_IDLE_TANGENT; +extern const bgc_tangent_fp32_t BGC_IDLE_TANGENT_FP32; +extern const bgc_tangent_fp64_t BGC_IDLE_TANGENT_FP64; // =================== Reset ==================== // -inline void tangent_reset_fp32(tangent_fp32_t* tangent) +inline void bgc_tangent_reset_fp32(bgc_tangent_fp32_t* tangent) { - __BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent; twin->cos = 1.0f; twin->sin = 0.0f; } -inline void tangent_reset_fp64(tangent_fp64_t* tangent) +inline void bgc_tangent_reset_fp64(bgc_tangent_fp64_t* tangent) { - __BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent; twin->cos = 1.0; twin->sin = 0.0; @@ -55,20 +55,20 @@ inline void tangent_reset_fp64(tangent_fp64_t* tangent) // ==================== Set ===================== // -inline void tangent_set_values_fp32(const float x1, const float x2, tangent_fp32_t* tangent) +inline void bgc_tangent_set_values_fp32(const float x1, const float x2, bgc_tangent_fp32_t* tangent) { const float square_module = x1 * x1 + x2 * x2; - __BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent; twin->cos = x1; twin->sin = x2; - if (1.0f - FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_module && square_module <= 1.0f + BGC_TWO_EPSYLON_FP32) { return; } - if (square_module <= FP32_SQUARE_EPSYLON) { + if (square_module <= BGC_SQUARE_EPSYLON_FP32) { twin->cos = 1.0f; twin->sin = 0.0f; return; @@ -80,20 +80,20 @@ inline void tangent_set_values_fp32(const float x1, const float x2, tangent_fp32 twin->sin = x2 * multiplier; } -inline void tangent_set_values_fp64(const double x1, const double x2, tangent_fp64_t* tangent) +inline void bgc_tangent_set_values_fp64(const double x1, const double x2, bgc_tangent_fp64_t* tangent) { const double square_module = x1 * x1 + x2 * x2; - __BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent; twin->cos = x1; twin->sin = x2; - if (1.0 - FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_module && square_module <= 1.0 + BGC_TWO_EPSYLON_FP64) { return; } - if (square_module <= FP64_SQUARE_EPSYLON) { + if (square_module <= BGC_SQUARE_EPSYLON_FP64) { twin->cos = 1.0; twin->sin = 0.0; return; @@ -107,17 +107,17 @@ inline void tangent_set_values_fp64(const double x1, const double x2, tangent_fp // ==================== Copy ==================== // -inline void tangent_copy_fp32(const tangent_fp32_t* from, tangent_fp32_t* to) +inline void bgc_tangent_copy_fp32(const bgc_tangent_fp32_t* from, bgc_tangent_fp32_t* to) { - __BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)to; + _bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)to; twin->cos = from->cos; twin->sin = from->sin; } -inline void tangent_copy_fp64(const tangent_fp64_t* from, tangent_fp64_t* to) +inline void bgc_tangent_copy_fp64(const bgc_tangent_fp64_t* from, bgc_tangent_fp64_t* to) { - __BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)to; + _bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)to; twin->cos = from->cos; twin->sin = from->sin; @@ -125,33 +125,33 @@ inline void tangent_copy_fp64(const tangent_fp64_t* from, tangent_fp64_t* to) // ==================== Swap ==================== // -inline void tangent_swap_fp32(tangent_fp32_t* tangent1, tangent_fp32_t* tangent2) +inline void bgc_tangent_swap_fp32(bgc_tangent_fp32_t* tangent1, bgc_tangent_fp32_t* tangent2) { const float cos = tangent1->cos; const float sin = tangent1->sin; - __BgFP32DarkTwinTangent* twin1 = (__BgFP32DarkTwinTangent*)tangent1; + _bgc_dark_twin_tangent_fp32_t* twin1 = (_bgc_dark_twin_tangent_fp32_t*)tangent1; twin1->cos = tangent2->cos; twin1->sin = tangent2->sin; - __BgFP32DarkTwinTangent* twin2 = (__BgFP32DarkTwinTangent*)tangent2; + _bgc_dark_twin_tangent_fp32_t* twin2 = (_bgc_dark_twin_tangent_fp32_t*)tangent2; twin2->cos = cos; twin2->sin = sin; } -inline void tangent_swap_fp64(tangent_fp64_t* tangent1, tangent_fp64_t* tangent2) +inline void bgc_tangent_swap_fp64(bgc_tangent_fp64_t* tangent1, bgc_tangent_fp64_t* tangent2) { const double cos = tangent1->cos; const double sin = tangent1->sin; - __BgFP64DarkTwinTangent* twin1 = (__BgFP64DarkTwinTangent*)tangent1; + _bgc_dark_twin_tangent_fp64_t* twin1 = (_bgc_dark_twin_tangent_fp64_t*)tangent1; twin1->cos = tangent2->cos; twin1->sin = tangent2->sin; - __BgFP64DarkTwinTangent* twin2 = (__BgFP64DarkTwinTangent*)tangent2; + _bgc_dark_twin_tangent_fp64_t* twin2 = (_bgc_dark_twin_tangent_fp64_t*)tangent2; twin2->cos = cos; twin2->sin = sin; @@ -159,21 +159,21 @@ inline void tangent_swap_fp64(tangent_fp64_t* tangent1, tangent_fp64_t* tangent2 // ================== Set Turn ================== // -inline void tangent_fp32_set_turn(const float angle, const angle_unit_t unit, tangent_fp32_t* tangent) +inline void bgc_tangent_set_turn_fp32(const float angle, const bgc_angle_unit_t unit, bgc_tangent_fp32_t* tangent) { - const float radians = fp32_angle_to_radians(angle, unit); + const float radians = bgc_angle_to_radians_fp32(angle, unit); - __BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent; twin->cos = cosf(radians); twin->sin = sinf(radians); } -inline void tangent_fp64_set_turn(const double angle, const angle_unit_t unit, tangent_fp64_t* tangent) +inline void bgc_tangent_set_turn_fp64(const double angle, const bgc_angle_unit_t unit, bgc_tangent_fp64_t* tangent) { - const double radians = fp64_angle_to_radians(angle, unit); + const double radians = bgc_angle_to_radians_fp64(angle, unit); - __BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent; + _bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent; twin->cos = cos(radians); twin->sin = sin(radians); @@ -181,41 +181,41 @@ inline void tangent_fp64_set_turn(const double angle, const angle_unit_t unit, t // ============= Copy to twin type ============== // -inline void tangent_convert_fp64_to_fp32(const tangent_fp64_t* from, tangent_fp32_t* to) +inline void bgc_tangent_convert_fp64_to_fp32(const bgc_tangent_fp64_t* from, bgc_tangent_fp32_t* to) { - tangent_set_values_fp32((float)from->cos, (float)from->sin, to); + bgc_tangent_set_values_fp32((float)from->cos, (float)from->sin, to); } -inline void tangent_convert_fp32_to_fp64(const tangent_fp32_t* from, tangent_fp64_t* to) +inline void bgc_tangent_convert_fp32_to_fp64(const bgc_tangent_fp32_t* from, bgc_tangent_fp64_t* to) { - tangent_set_values_fp64((double)from->cos, (double)from->sin, to); + bgc_tangent_set_values_fp64((double)from->cos, (double)from->sin, to); } // ================= Inversion ================== // -inline void tangent_invert_fp32(tangent_fp32_t* tangent) +inline void bgc_tangent_invert_fp32(bgc_tangent_fp32_t* tangent) { - ((__BgFP32DarkTwinTangent*)tangent)->sin = -tangent->sin; + ((_bgc_dark_twin_tangent_fp32_t*)tangent)->sin = -tangent->sin; } -inline void tangent_invert_fp64(tangent_fp64_t* tangent) +inline void bgc_tangent_invert_fp64(bgc_tangent_fp64_t* tangent) { - ((__BgFP64DarkTwinTangent*)tangent)->sin = -tangent->sin; + ((_bgc_dark_twin_tangent_fp64_t*)tangent)->sin = -tangent->sin; } // ================ Set Inverted ================ // -inline void tangent_set_inverted_fp32(const tangent_fp32_t* tangent, tangent_fp32_t* result) +inline void bgc_tangent_set_inverted_fp32(const bgc_tangent_fp32_t* tangent, bgc_tangent_fp32_t* result) { - __BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)result; + _bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)result; twin->cos = tangent->cos; twin->sin = -tangent->sin; } -inline void tangent_set_inverted_fp64(const tangent_fp64_t* tangent, tangent_fp64_t* result) +inline void bgc_tangent_set_inverted_fp64(const bgc_tangent_fp64_t* tangent, bgc_tangent_fp64_t* result) { - __BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)result; + _bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)result; twin->cos = tangent->cos; twin->sin = -tangent->sin; @@ -223,7 +223,7 @@ inline void tangent_set_inverted_fp64(const tangent_fp64_t* tangent, tangent_fp6 // ============== Rotation Matrix =============== // -inline void tangent_fp32_make_rotation_matrix(const tangent_fp32_t* tangent, matrix2x2_fp32_t* matrix) +inline void bgc_tangent_make_rotation_matrix_fp32(const bgc_tangent_fp32_t* tangent, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = -tangent->sin; @@ -231,7 +231,7 @@ inline void tangent_fp32_make_rotation_matrix(const tangent_fp32_t* tangent, mat matrix->r2c2 = tangent->cos; } -inline void tangent_fp64_make_rotation_matrix(const tangent_fp64_t* tangent, matrix2x2_fp64_t* matrix) +inline void bgc_tangent_make_rotation_matrix_fp64(const bgc_tangent_fp64_t* tangent, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = -tangent->sin; @@ -241,7 +241,7 @@ inline void tangent_fp64_make_rotation_matrix(const tangent_fp64_t* tangent, mat // ============== Reverse Matrix ================ // -inline void tangent_fp32_make_reverse_matrix(const tangent_fp32_t* tangent, matrix2x2_fp32_t* matrix) +inline void bgc_tangent_make_reverse_matrix_fp32(const bgc_tangent_fp32_t* tangent, bgc_matrix2x2_fp32_t* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = tangent->sin; @@ -249,7 +249,7 @@ inline void tangent_fp32_make_reverse_matrix(const tangent_fp32_t* tangent, matr matrix->r2c2 = tangent->cos; } -inline void tangent_fp64_make_reverse_matrix(const tangent_fp64_t* tangent, matrix2x2_fp64_t* matrix) +inline void bgc_tangent_make_reverse_matrix_fp64(const bgc_tangent_fp64_t* tangent, bgc_matrix2x2_fp64_t* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = tangent->sin; @@ -259,62 +259,62 @@ inline void tangent_fp64_make_reverse_matrix(const tangent_fp64_t* tangent, matr // =================== Angle =================== // -inline float tangent_get_angle_fp32(const tangent_fp32_t* tangent, const angle_unit_t unit) +inline float bgc_tangent_get_angle_fp32(const bgc_tangent_fp32_t* tangent, const bgc_angle_unit_t unit) { - if (tangent->cos >= 1.0f - FP32_TWO_EPSYLON) { + if (tangent->cos >= 1.0f - BGC_TWO_EPSYLON_FP32) { return 0.0f; } - if (tangent->cos <= -1.0f + FP32_TWO_EPSYLON) { - return fp32_angle_get_half_circle(unit); + if (tangent->cos <= -1.0f + BGC_TWO_EPSYLON_FP32) { + return bgc_angle_get_half_circle_fp32(unit); } - if (tangent->sin >= 1.0f - FP32_TWO_EPSYLON) { - return fp32_angle_get_quater_circle(unit); + if (tangent->sin >= 1.0f - BGC_TWO_EPSYLON_FP32) { + return bgc_angle_get_quater_circle_fp32(unit); } - if (tangent->sin <= -1.0f + FP32_TWO_EPSYLON) { - return 0.75f * fp32_angle_get_full_circle(unit); + if (tangent->sin <= -1.0f + BGC_TWO_EPSYLON_FP32) { + return 0.75f * bgc_angle_get_full_circle_fp32(unit); } - return fp32_radians_to_units(atan2f(tangent->cos, tangent->sin), unit); + return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit); } -inline double tangent_get_angle_fp64(const tangent_fp64_t* tangent, const angle_unit_t unit) +inline double bgc_tangent_get_angle_fp64(const bgc_tangent_fp64_t* tangent, const bgc_angle_unit_t unit) { - if (tangent->cos >= 1.0 - FP64_TWO_EPSYLON) { + if (tangent->cos >= 1.0 - BGC_TWO_EPSYLON_FP64) { return 0.0; } - if (tangent->cos <= -1.0 + FP64_TWO_EPSYLON) { - return fp64_angle_get_half_circle(unit); + if (tangent->cos <= -1.0 + BGC_TWO_EPSYLON_FP64) { + return bgc_angle_get_half_circle_fp64(unit); } - if (tangent->sin >= 1.0 - FP64_TWO_EPSYLON) { - return fp64_angle_get_quater_circle(unit); + if (tangent->sin >= 1.0 - BGC_TWO_EPSYLON_FP64) { + return bgc_angle_get_quater_circle_fp64(unit); } - if (tangent->sin <= -1.0 + FP64_TWO_EPSYLON) { - return 0.75 * fp64_angle_get_full_circle(unit); + if (tangent->sin <= -1.0 + BGC_TWO_EPSYLON_FP64) { + return 0.75 * bgc_angle_get_full_circle_fp64(unit); } - return fp64_radians_to_units(atan2(tangent->cos, tangent->sin), unit); + return bgc_radians_to_units_fp64(atan2(tangent->cos, tangent->sin), unit); } // ================ Combination ================= // -inline void tangent_fp32_combine(const tangent_fp32_t* tangent1, const tangent_fp32_t* tangent2, tangent_fp32_t* result) +inline void bgc_tangent_combine_fp32(const bgc_tangent_fp32_t* tangent1, const bgc_tangent_fp32_t* tangent2, bgc_tangent_fp32_t* result) { - tangent_set_values_fp32( + bgc_tangent_set_values_fp32( tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin, tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos, result ); } -inline void tangent_fp64_combine(const tangent_fp64_t* tangent1, const tangent_fp64_t* tangent2, tangent_fp64_t* result) +inline void bgc_tangent_combine_fp64(const bgc_tangent_fp64_t* tangent1, const bgc_tangent_fp64_t* tangent2, bgc_tangent_fp64_t* result) { - tangent_set_values_fp64( + bgc_tangent_set_values_fp64( tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin, tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos, result @@ -323,7 +323,7 @@ inline void tangent_fp64_combine(const tangent_fp64_t* tangent1, const tangent_f // ================ Turn Vector ================= // -inline void tangent_fp32_turn(const tangent_fp32_t* tangent, const vector2_fp32_t* vector, vector2_fp32_t* result) +inline void bgc_tangent_turn_vector_fp32(const bgc_tangent_fp32_t* tangent, const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result) { const float x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2; const float x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2; @@ -332,7 +332,7 @@ inline void tangent_fp32_turn(const tangent_fp32_t* tangent, const vector2_fp32_ result->x2 = x2; } -inline void tangent_fp64_turn(const tangent_fp64_t* tangent, const vector2_fp64_t* vector, vector2_fp64_t* result) +inline void bgc_tangent_turn_vector_fp64(const bgc_tangent_fp64_t* tangent, const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result) { const double x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2; const double x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2; @@ -343,7 +343,7 @@ inline void tangent_fp64_turn(const tangent_fp64_t* tangent, const vector2_fp64_ // ============ Turn Vector Backward ============ // -inline void tangent_fp32_turn_back(const tangent_fp32_t* tangent, const vector2_fp32_t* vector, vector2_fp32_t* result) +inline void bgc_tangent_turn_vector_back_fp32(const bgc_tangent_fp32_t* tangent, const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result) { const float x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1; const float x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1; @@ -352,7 +352,7 @@ inline void tangent_fp32_turn_back(const tangent_fp32_t* tangent, const vector2_ result->x2 = x2; } -inline void tangent_fp64_turn_back(const tangent_fp64_t* tangent, const vector2_fp64_t* vector, vector2_fp64_t* result) +inline void bgc_tangent_turn_vector_back_fp64(const bgc_tangent_fp64_t* tangent, const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result) { const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1; const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1; diff --git a/basic-geometry/utilities.h b/basic-geometry/utilities.h new file mode 100644 index 0000000..d49feeb --- /dev/null +++ b/basic-geometry/utilities.h @@ -0,0 +1,56 @@ +#ifndef _BGC_UTILITIES_H_ +#define _BGC_UTILITIES_H_ + +#define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 10.0f + +#define BGC_EPSYLON_FP32 5E-7f +#define BGC_TWO_EPSYLON_FP32 1E-6f +#define BGC_SQUARE_EPSYLON_FP32 2.5E-13f + +#define BGC_ONE_THIRD_FP32 0.333333333f +#define BGC_ONE_SIXTH_FP32 0.166666667f +#define BGC_ONE_NINETH_FP32 0.111111111f + +#define BGC_GOLDEN_RATIO_HIGH_FP32 1.618034f +#define BGC_GOLDEN_RATIO_LOW_FP32 0.618034f + +#define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 10.0 + +#define BGC_EPSYLON_FP64 5E-14 +#define BGC_TWO_EPSYLON_FP64 1E-13 +#define BGC_SQUARE_EPSYLON_FP64 2.5E-27 + +#define BGC_ONE_THIRD_FP64 0.333333333333333333 +#define BGC_ONE_SIXTH_FP64 0.166666666666666667 +#define BGC_ONE_NINETH_FP64 0.111111111111111111 + +#define BGC_GOLDEN_RATIO_HIGH_FP64 1.61803398874989485 +#define BGC_GOLDEN_RATIO_LOW_FP64 0.61803398874989485 + +inline int bgc_are_equal_fp32(const float value1, const float value2) +{ + if (-BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 < value1 && value1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { + return -BGC_EPSYLON_FP32 <= (value1 - value2) && (value1 - value2) <= BGC_EPSYLON_FP32; + } + + if (value1 < 0.0f) { + return (1.0f + BGC_EPSYLON_FP32) * value2 <= value1 && (1.0f + BGC_EPSYLON_FP32) * value1 <= value2; + } + + return value2 <= value1 * (1.0f + BGC_EPSYLON_FP32) && value1 <= value2 * (1.0f + BGC_EPSYLON_FP32); +} + +inline int bgc_are_equal_fp64(const double value1, const double value2) +{ + if (-BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 < value1 && value1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { + return -BGC_EPSYLON_FP64 <= (value1 - value2) && (value1 - value2) <= BGC_EPSYLON_FP64; + } + + if (value1 < 0.0) { + return (1.0 + BGC_EPSYLON_FP64) * value2 <= value1 && (1.0 + BGC_EPSYLON_FP64) * value1 <= value2; + } + + return value2 <= value1 * (1.0 + BGC_EPSYLON_FP64) && value1 <= value2 * (1.0 + BGC_EPSYLON_FP64); +} + +#endif diff --git a/basic-geometry/vector2.c b/basic-geometry/vector2.c index 30cf01f..e2adb61 100644 --- a/basic-geometry/vector2.c +++ b/basic-geometry/vector2.c @@ -2,64 +2,64 @@ // =================== Angle ==================== // -float vector2_get_angle_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, const angle_unit_t unit) +float bgc_vector2_get_angle_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, const bgc_angle_unit_t unit) { if (vector1 == 0 || vector2 == 0) { return 0.0f; } - const float square_modulus1 = vector2_get_square_modulus_fp32(vector1); + const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1); - if (square_modulus1 <= FP32_SQUARE_EPSYLON) { + if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) { return 0.0f; } - const float square_modulus2 = vector2_get_square_modulus_fp32(vector2); + const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2); - if (square_modulus2 <= FP32_SQUARE_EPSYLON) { + if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) { return 0.0f; } - const float cosine = vector2_fp32_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2); + const float cosine = bgc_vector2_scalar_product_fp32(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2); - if (cosine >= 1.0f - FP32_EPSYLON) { + if (cosine >= 1.0f - BGC_EPSYLON_FP32) { return 0.0f; } - if (cosine <= -1.0f + FP32_EPSYLON) { - return fp32_angle_get_half_circle(unit); + if (cosine <= -1.0f + BGC_EPSYLON_FP32) { + return bgc_angle_get_half_circle_fp32(unit); } - return fp32_radians_to_units(acosf(cosine), unit); + return bgc_radians_to_units_fp32(acosf(cosine), unit); } -double vector2_get_angle_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, const angle_unit_t unit) +double bgc_vector2_get_angle_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, const bgc_angle_unit_t unit) { if (vector1 == 0 || vector2 == 0) { return 0.0; } - const double square_modulus1 = vector2_get_square_modulus_fp64(vector1); + const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1); - if (square_modulus1 <= FP64_SQUARE_EPSYLON) { + if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) { return 0.0; } - const double square_modulus2 = vector2_get_square_modulus_fp64(vector2); + const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2); - if (square_modulus2 <= FP64_SQUARE_EPSYLON) { + if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) { return 0.0; } - const double cosine = vector2_fp64_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2); + const double cosine = bgc_vector2_scalar_product_fp64(vector1, vector2) / sqrt(square_modulus1 * square_modulus2); - if (cosine >= 1.0 - FP64_EPSYLON) { + if (cosine >= 1.0 - BGC_EPSYLON_FP64) { return 0.0; } - if (cosine <= -1.0 + FP64_EPSYLON) { - return fp64_angle_get_half_circle(unit); + if (cosine <= -1.0 + BGC_EPSYLON_FP64) { + return bgc_angle_get_half_circle_fp64(unit); } - return fp64_radians_to_units(acos(cosine), unit); + return bgc_radians_to_units_fp64(acos(cosine), unit); } diff --git a/basic-geometry/vector2.h b/basic-geometry/vector2.h index e7f6266..de01a83 100644 --- a/basic-geometry/vector2.h +++ b/basic-geometry/vector2.h @@ -1,7 +1,7 @@ -#ifndef _BASIC_GEOMETRY_VECTOR2_H_ -#define _BASIC_GEOMETRY_VECTOR2_H_ +#ifndef _BGC_VECTOR2_H_ +#define _BGC_VECTOR2_H_ -#include "basis.h" +#include "utilities.h" #include "angle.h" #include @@ -9,22 +9,22 @@ typedef struct { float x1, x2; -} vector2_fp32_t; +} bgc_vector2_fp32_t; typedef struct { double x1, x2; -} vector2_fp64_t; +} bgc_vector2_fp64_t; // =================== Reset ==================== // -inline void vector2_reset_fp32(vector2_fp32_t* vector) +inline void bgc_vector2_reset_fp32(bgc_vector2_fp32_t* vector) { vector->x1 = 0.0f; vector->x2 = 0.0f; } -inline void vector2_reset_fp64(vector2_fp64_t* vector) +inline void bgc_vector2_reset_fp64(bgc_vector2_fp64_t* vector) { vector->x1 = 0.0; vector->x2 = 0.0; @@ -32,13 +32,13 @@ inline void vector2_reset_fp64(vector2_fp64_t* vector) // ==================== Set ===================== // -inline void vector2_set_values_fp32(const float x1, const float x2, vector2_fp32_t* to) +inline void bgc_vector2_set_values_fp32(const float x1, const float x2, bgc_vector2_fp32_t* to) { to->x1 = x1; to->x2 = x2; } -inline void vector2_set_values_fp64(const double x1, const double x2, vector2_fp64_t* to) +inline void bgc_vector2_set_values_fp64(const double x1, const double x2, bgc_vector2_fp64_t* to) { to->x1 = x1; to->x2 = x2; @@ -46,13 +46,13 @@ inline void vector2_set_values_fp64(const double x1, const double x2, vector2_fp // ==================== Copy ==================== // -inline void vector2_copy_fp32(const vector2_fp32_t* from, vector2_fp32_t* to) +inline void bgc_vector2_copy_fp32(const bgc_vector2_fp32_t* from, bgc_vector2_fp32_t* to) { to->x1 = from->x1; to->x2 = from->x2; } -inline void vector2_copy_fp64(const vector2_fp64_t* from, vector2_fp64_t* to) +inline void bgc_vector2_copy_fp64(const bgc_vector2_fp64_t* from, bgc_vector2_fp64_t* to) { to->x1 = from->x1; to->x2 = from->x2; @@ -60,7 +60,7 @@ inline void vector2_copy_fp64(const vector2_fp64_t* from, vector2_fp64_t* to) // ==================== Swap ==================== // -inline void vector2_swap_fp32(vector2_fp32_t* vector1, vector2_fp32_t* vector2) +inline void bgc_vector2_swap_fp32(bgc_vector2_fp32_t* vector1, bgc_vector2_fp32_t* vector2) { const float x1 = vector2->x1; const float x2 = vector2->x2; @@ -72,7 +72,7 @@ inline void vector2_swap_fp32(vector2_fp32_t* vector1, vector2_fp32_t* vector2) vector1->x2 = x2; } -inline void vector2_swap_fp64(vector2_fp64_t* vector1, vector2_fp64_t* vector2) +inline void bgc_vector2_swap_fp64(bgc_vector2_fp64_t* vector1, bgc_vector2_fp64_t* vector2) { const double x1 = vector2->x1; const double x2 = vector2->x2; @@ -86,13 +86,13 @@ inline void vector2_swap_fp64(vector2_fp64_t* vector1, vector2_fp64_t* vector2) // ============= Copy to twin type ============== // -inline void vector2_convert_fp64_to_fp32(const vector2_fp64_t* from, vector2_fp32_t* to) +inline void bgc_vector2_convert_fp64_to_fp32(const bgc_vector2_fp64_t* from, bgc_vector2_fp32_t* to) { to->x1 = (float)from->x1; to->x2 = (float)from->x2; } -inline void vector2_convert_fp32_to_fp64(const vector2_fp32_t* from, vector2_fp64_t* to) +inline void bgc_vector2_convert_fp32_to_fp64(const bgc_vector2_fp32_t* from, bgc_vector2_fp64_t* to) { to->x1 = from->x1; to->x2 = from->x2; @@ -100,13 +100,13 @@ inline void vector2_convert_fp32_to_fp64(const vector2_fp32_t* from, vector2_fp6 // =================== Reverse ================== // -inline void vector2_fp32_set_reverse(const vector2_fp32_t* from, vector2_fp32_t* to) +inline void bgc_vector2_set_reverse_fp32(const bgc_vector2_fp32_t* from, bgc_vector2_fp32_t* to) { to->x1 = -from->x1; to->x2 = -from->x2; } -inline void vector2_fp64_set_reverse(const vector2_fp64_t* from, vector2_fp64_t* to) +inline void bgc_vector2_set_reverse_fp64(const bgc_vector2_fp64_t* from, bgc_vector2_fp64_t* to) { to->x1 = -from->x1; to->x2 = -from->x2; @@ -114,13 +114,13 @@ inline void vector2_fp64_set_reverse(const vector2_fp64_t* from, vector2_fp64_t* // ============= Reverse twin type ============== // -inline void vector2_fp32_set_reverse_fp64(const vector2_fp64_t* from, vector2_fp32_t* to) +inline void bgc_vector2_set_reverse_fp64_to_fp32(const bgc_vector2_fp64_t* from, bgc_vector2_fp32_t* to) { to->x1 = (float) -from->x1; to->x2 = (float) -from->x2; } -inline void vector2_fp64_set_reverse_fp32(const vector2_fp32_t* from, vector2_fp64_t* to) +inline void bgc_vector2_set_reverse_fp32_to_fp64(const bgc_vector2_fp32_t* from, bgc_vector2_fp64_t* to) { to->x1 = -from->x1; to->x2 = -from->x2; @@ -128,75 +128,89 @@ inline void vector2_fp64_set_reverse_fp32(const vector2_fp32_t* from, vector2_fp // =================== Module =================== // -inline float vector2_get_square_modulus_fp32(const vector2_fp32_t* vector) +inline float bgc_vector2_get_square_modulus_fp32(const bgc_vector2_fp32_t* vector) { return vector->x1 * vector->x1 + vector->x2 * vector->x2; } -inline double vector2_get_square_modulus_fp64(const vector2_fp64_t* vector) +inline double bgc_vector2_get_square_modulus_fp64(const bgc_vector2_fp64_t* vector) { return vector->x1 * vector->x1 + vector->x2 * vector->x2; } -inline float vector2_get_modulus_fp32(const vector2_fp32_t* vector) +inline float bgc_vector2_get_modulus_fp32(const bgc_vector2_fp32_t* vector) { - return sqrtf(vector2_get_square_modulus_fp32(vector)); + return sqrtf(bgc_vector2_get_square_modulus_fp32(vector)); } -inline double vector2_get_modulus_fp64(const vector2_fp64_t* vector) +inline double bgc_vector2_get_modulus_fp64(const bgc_vector2_fp64_t* vector) { - return sqrt(vector2_get_square_modulus_fp64(vector)); + return sqrt(bgc_vector2_get_square_modulus_fp64(vector)); } // ================= Comparison ================= // -inline int vector2_fp32_is_zero(const vector2_fp32_t* vector) +inline int bgc_vector2_is_zero_fp32(const bgc_vector2_fp32_t* vector) { - return vector2_get_square_modulus_fp32(vector) <= FP32_SQUARE_EPSYLON; + return bgc_vector2_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32; } -inline int vector2_fp64_is_zero(const vector2_fp64_t* vector) +inline int bgc_vector2_is_zero_fp64(const bgc_vector2_fp64_t* vector) { - return vector2_get_square_modulus_fp64(vector) <= FP64_SQUARE_EPSYLON; + return bgc_vector2_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64; } -inline int vector2_fp32_is_unit(const vector2_fp32_t* vector) +inline int bgc_vector2_is_unit_fp32(const bgc_vector2_fp32_t* vector) { - const float square_modulus = vector2_get_square_modulus_fp32(vector); + const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector); - return 1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON; + return 1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32; } -inline int vector2_fp64_is_unit(const vector2_fp64_t* vector) +inline int bgc_vector2_is_unit_fp64(const bgc_vector2_fp64_t* vector) { - const double square_modulus = vector2_get_square_modulus_fp64(vector); + const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector); - return 1.0f - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP64_TWO_EPSYLON; + return 1.0f - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP64; } // ==================== Add ===================== // -inline void vector2_add_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* sum) +inline void bgc_vector2_add_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* sum) { sum->x1 = vector1->x1 + vector2->x1; sum->x2 = vector1->x2 + vector2->x2; } -inline void vector2_add_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* sum) +inline void bgc_vector2_add_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* sum) { sum->x1 = vector1->x1 + vector2->x1; sum->x2 = vector1->x2 + vector2->x2; } +// ================ Append scaled =============== // + +inline void bgc_vector2_add_scaled_fp32(const bgc_vector2_fp32_t* basic_vector, const bgc_vector2_fp32_t* scalable_vector, const float scale, bgc_vector2_fp32_t* sum) +{ + sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; + sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; +} + +inline void bgc_vector2_add_scaled_fp64(const bgc_vector2_fp64_t* basic_vector, const bgc_vector2_fp64_t* scalable_vector, const double scale, bgc_vector2_fp64_t* sum) +{ + sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale; + sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale; +} + // ================ Subtraction ================= // -inline void vector2_subtract_fp32(const vector2_fp32_t* minuend, const vector2_fp32_t* subtrahend, vector2_fp32_t* difference) +inline void bgc_vector2_subtract_fp32(const bgc_vector2_fp32_t* minuend, const bgc_vector2_fp32_t* subtrahend, bgc_vector2_fp32_t* difference) { difference->x1 = minuend->x1 - subtrahend->x1; difference->x2 = minuend->x2 - subtrahend->x2; } -inline void vector2_subtract_fp64(const vector2_fp64_t* minuend, const vector2_fp64_t* subtrahend, vector2_fp64_t* difference) +inline void bgc_vector2_subtract_fp64(const bgc_vector2_fp64_t* minuend, const bgc_vector2_fp64_t* subtrahend, bgc_vector2_fp64_t* difference) { difference->x1 = minuend->x1 - subtrahend->x1; difference->x2 = minuend->x2 - subtrahend->x2; @@ -204,13 +218,13 @@ inline void vector2_subtract_fp64(const vector2_fp64_t* minuend, const vector2_f // =============== Multiplication =============== // -inline void vector2_multiply_fp32(const vector2_fp32_t* multiplicand, const float multiplier, vector2_fp32_t* product) +inline void bgc_vector2_multiply_fp32(const bgc_vector2_fp32_t* multiplicand, const float multiplier, bgc_vector2_fp32_t* product) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; } -inline void vector2_multiply_fp64(const vector2_fp64_t* multiplicand, const double multiplier, vector2_fp64_t* product) +inline void bgc_vector2_multiply_fp64(const bgc_vector2_fp64_t* multiplicand, const double multiplier, bgc_vector2_fp64_t* product) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; @@ -218,39 +232,25 @@ inline void vector2_multiply_fp64(const vector2_fp64_t* multiplicand, const doub // ================== Division ================== // -inline void vector2_divide_fp32(const vector2_fp32_t* dividend, const float divisor, vector2_fp32_t* quotient) +inline void bgc_vector2_divide_fp32(const bgc_vector2_fp32_t* dividend, const float divisor, bgc_vector2_fp32_t* quotient) { - vector2_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_vector2_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void vector2_fp64_divide(const vector2_fp64_t* dividend, const double divisor, vector2_fp64_t* quotient) +inline void bgc_vector2_divide_fp64(const bgc_vector2_fp64_t* dividend, const double divisor, bgc_vector2_fp64_t* quotient) { - vector2_multiply_fp64(dividend, 1.0 / divisor, quotient); -} - -// ================ Append scaled =============== // - -inline void vector2_add_scaled_fp32(vector2_fp32_t* basic_vector, const vector2_fp32_t* scalable_vector, const float scale) -{ - basic_vector->x1 += scalable_vector->x1 * scale; - basic_vector->x2 += scalable_vector->x2 * scale; -} - -inline void vector2_add_scaled_fp64(vector2_fp64_t* basic_vector, const vector2_fp64_t* scalable_vector, const double scale) -{ - basic_vector->x1 += scalable_vector->x1 * scale; - basic_vector->x2 += scalable_vector->x2 * scale; + bgc_vector2_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ================== Average2 ================== // -inline void vector2_fp32_get_mean2(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* result) +inline void bgc_vector2_mean_of_two_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* result) { result->x1 = (vector1->x1 + vector2->x1) * 0.5f; result->x2 = (vector1->x2 + vector2->x2) * 0.5f; } -inline void vector2_fp64_get_mean2(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* result) +inline void bgc_vector2_mean_of_two_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* result) { result->x1 = (vector1->x1 + vector2->x1) * 0.5; result->x2 = (vector1->x2 + vector2->x2) * 0.5; @@ -258,45 +258,45 @@ inline void vector2_fp64_get_mean2(const vector2_fp64_t* vector1, const vector2_ // ================== Average3 ================== // -inline void vector2_fp32_get_mean3(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, const vector2_fp32_t* vector3, vector2_fp32_t* result) +inline void bgc_vector2_mean_of_three_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, const bgc_vector2_fp32_t* vector3, bgc_vector2_fp32_t* result) { - result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP32_ONE_THIRD; - result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP32_ONE_THIRD; + result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32; + result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32; } -inline void vector2_fp64_get_mean3(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, const vector2_fp64_t* vector3, vector2_fp64_t* result) +inline void bgc_vector2_mean_of_three_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, const bgc_vector2_fp64_t* vector3, bgc_vector2_fp64_t* result) { - result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP64_ONE_THIRD; - result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP64_ONE_THIRD; + result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64; + result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64; } // =============== Scalar Product =============== // -inline float vector2_fp32_scalar_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2) +inline float bgc_vector2_scalar_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2) { return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2; } -inline double vector2_fp64_scalar_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2) +inline double bgc_vector2_scalar_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2) { return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2; } // =============== Cross Product ================ // -inline float vector2_fp32_cross_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2) +inline float bgc_vector2_cross_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2) { return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; } -inline double vector2_fp64_cross_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2) +inline double bgc_vector2_cross_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2) { return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1; } // ============== Complex Product =============== // -inline void vector2_fp32_complex_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* result) +inline void bgc_vector2_complex_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* result) { const float x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2; const float x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1; @@ -305,7 +305,7 @@ inline void vector2_fp32_complex_product(const vector2_fp32_t* vector1, const ve result->x2 = x2; } -inline void vector2_fp64_complex_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* result) +inline void bgc_vector2_complex_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* result) { const double x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2; const double x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1; @@ -316,63 +316,63 @@ inline void vector2_fp64_complex_product(const vector2_fp64_t* vector1, const ve // =============== Normalization ================ // -inline int vector2_normalize_fp32(vector2_fp32_t* vector) +inline int bgc_vector2_normalize_fp32(bgc_vector2_fp32_t* vector) { - const float square_modulus = vector2_get_square_modulus_fp32(vector); + const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector); - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return 1; } - if (square_modulus <= FP32_SQUARE_EPSYLON) { - vector2_reset_fp32(vector); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) { + bgc_vector2_reset_fp32(vector); return 0; } - vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector); + bgc_vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector); return 1; } -inline int vector2_normalize_fp64(vector2_fp64_t* vector) +inline int bgc_vector2_normalize_fp64(bgc_vector2_fp64_t* vector) { - const double square_modulus = vector2_get_square_modulus_fp64(vector); + const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector); - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return 1; } - if (square_modulus <= FP64_SQUARE_EPSYLON) { - vector2_reset_fp64(vector); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) { + bgc_vector2_reset_fp64(vector); return 0; } - vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector); + bgc_vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector); return 1; } // =============== Get Normalized =============== // -inline int vector2_fp32_set_normalized(const vector2_fp32_t* vector, vector2_fp32_t* result) +inline int bgc_vector2_set_normalized_fp32(const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result) { - vector2_copy_fp32(vector, result); - return vector2_normalize_fp32(result); + bgc_vector2_copy_fp32(vector, result); + return bgc_vector2_normalize_fp32(result); } -inline int vector2_fp64_set_normalized(const vector2_fp64_t* vector, vector2_fp64_t* result) +inline int bgc_vector2_set_normalized_fp64(const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result) { - vector2_copy_fp64(vector, result); - return vector2_normalize_fp64(result); + bgc_vector2_copy_fp64(vector, result); + return bgc_vector2_normalize_fp64(result); } // =================== Angle ==================== // -float vector2_get_angle_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, const angle_unit_t unit); +float bgc_vector2_get_angle_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, const bgc_angle_unit_t unit); -double vector2_get_angle_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, const angle_unit_t unit); +double bgc_vector2_get_angle_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, const bgc_angle_unit_t unit); // =============== Square Distance ============== // -inline float vector2_get_square_distance_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2) +inline float bgc_vector2_get_square_distance_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2) { const float dx1 = (vector1->x1 - vector2->x1); const float dx2 = (vector1->x2 - vector2->x2); @@ -380,7 +380,7 @@ inline float vector2_get_square_distance_fp32(const vector2_fp32_t* vector1, con return dx1 * dx1 + dx2 * dx2; } -inline double vector2_get_square_distance_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2) +inline double bgc_vector2_get_square_distance_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2) { const double dx1 = (vector1->x1 - vector2->x1); const double dx2 = (vector1->x2 - vector2->x2); @@ -390,52 +390,52 @@ inline double vector2_get_square_distance_fp64(const vector2_fp64_t* vector1, co // ================== Distance ================== // -inline float vector2_get_distance_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2) +inline float bgc_vector2_get_distance_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2) { - return sqrtf(vector2_get_square_distance_fp32(vector1, vector2)); + return sqrtf(bgc_vector2_get_square_distance_fp32(vector1, vector2)); } -inline double vector2_get_distance_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2) +inline double bgc_vector2_get_distance_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2) { - return sqrt(vector2_get_square_distance_fp64(vector1, vector2)); + return sqrt(bgc_vector2_get_square_distance_fp64(vector1, vector2)); } // ================== Are Equal ================= // -inline int vector2_are_equal_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2) +inline int bgc_vector2_are_equal_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2) { - const float square_modulus1 = vector2_get_square_modulus_fp32(vector1); - const float square_modulus2 = vector2_get_square_modulus_fp32(vector2); - const float square_modulus3 = vector2_get_square_distance_fp32(vector1, vector2); + const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1); + const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2); + const float square_modulus3 = bgc_vector2_get_square_distance_fp32(vector1, vector2); // 2.0f means dimension amount - if (square_modulus1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) { - return square_modulus3 < (2.0f * FP32_SQUARE_EPSYLON); + if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { + return square_modulus3 < (2.0f * BGC_SQUARE_EPSYLON_FP32); } if (square_modulus1 <= square_modulus2) { - return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus2; + return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2; } - return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus1; + return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1; } -inline int vector2_are_equal_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2) +inline int bgc_vector2_are_equal_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2) { - const double square_modulus1 = vector2_get_square_modulus_fp64(vector1); - const double square_modulus2 = vector2_get_square_modulus_fp64(vector2); - const double square_modulus3 = vector2_get_square_distance_fp64(vector1, vector2); + const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1); + const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2); + const double square_modulus3 = bgc_vector2_get_square_distance_fp64(vector1, vector2); // 2.0 means dimension amount - if (square_modulus1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) { - return square_modulus3 < (2.0 * FP64_SQUARE_EPSYLON); + if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { + return square_modulus3 < (2.0 * BGC_SQUARE_EPSYLON_FP64); } if (square_modulus1 <= square_modulus2) { - return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus2; + return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2; } - return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus1; + return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1; } #endif diff --git a/basic-geometry/vector3.c b/basic-geometry/vector3.c index 284175f..3997c7f 100644 --- a/basic-geometry/vector3.c +++ b/basic-geometry/vector3.c @@ -2,64 +2,64 @@ // =================== Angle ==================== // -float vector3_get_angle_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, const angle_unit_t unit) +float bgc_vector3_get_angle_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_angle_unit_t unit) { if (vector1 == 0 || vector2 == 0) { return 0.0f; } - const float square_modulus1 = vector3_get_square_modulus_fp32(vector1); + const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1); - if (square_modulus1 <= FP32_SQUARE_EPSYLON) { + if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) { return 0.0f; } - const float square_modulus2 = vector3_get_square_modulus_fp32(vector2); + const float square_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2); - if (square_modulus2 <= FP32_SQUARE_EPSYLON) { + if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) { return 0.0f; } - const float cosine = vector3_scalar_product_fp32(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2); + const float cosine = bgc_vector3_scalar_product_fp32(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2); - if (cosine >= 1.0f - FP32_EPSYLON) { + if (cosine >= 1.0f - BGC_EPSYLON_FP32) { return 0.0f; } - if (cosine <= -1.0f + FP32_EPSYLON) { - return fp32_angle_get_half_circle(unit); + if (cosine <= -1.0f + BGC_EPSYLON_FP32) { + return bgc_angle_get_half_circle_fp32(unit); } - return fp32_radians_to_units(acosf(cosine), unit); + return bgc_radians_to_units_fp32(acosf(cosine), unit); } -double vector3_get_angle_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, const angle_unit_t unit) +double bgc_vector3_get_angle_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_angle_unit_t unit) { if (vector1 == 0 || vector2 == 0) { return 0.0; } - const double square_modulus1 = vector3_get_square_modulus_fp64(vector1); + const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1); - if (square_modulus1 <= FP64_SQUARE_EPSYLON) { + if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) { return 0.0; } - const double square_modulus2 = vector3_get_square_modulus_fp64(vector2); + const double square_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2); - if (square_modulus2 <= FP64_SQUARE_EPSYLON) { + if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) { return 0.0; } - const double cosine = vector3_scalar_product_fp64(vector1, vector2) / sqrt(square_modulus1 * square_modulus2); + const double cosine = bgc_vector3_scalar_product_fp64(vector1, vector2) / sqrt(square_modulus1 * square_modulus2); - if (cosine >= 1.0 - FP64_EPSYLON) { + if (cosine >= 1.0 - BGC_EPSYLON_FP64) { return 0.0; } - if (cosine <= -1.0 + FP64_EPSYLON) { - return fp64_angle_get_half_circle(unit); + if (cosine <= -1.0 + BGC_EPSYLON_FP64) { + return bgc_angle_get_half_circle_fp64(unit); } - return fp64_radians_to_units(acos(cosine), unit); + return bgc_radians_to_units_fp64(acos(cosine), unit); } diff --git a/basic-geometry/vector3.h b/basic-geometry/vector3.h index 6b4cf5c..510df16 100644 --- a/basic-geometry/vector3.h +++ b/basic-geometry/vector3.h @@ -1,7 +1,7 @@ -#ifndef _BASIC_GEOMETRY_VECTOR3_H_ -#define _BASIC_GEOMETRY_VECTOR3_H_ +#ifndef _BGC_VECTOR3_H_ +#define _BGC_VECTOR3_H_ -#include "basis.h" +#include "utilities.h" #include "angle.h" #include @@ -11,23 +11,23 @@ typedef struct { float x1, x2, x3; -} vector3_fp32_t; +} bgc_vector3_fp32_t; typedef struct { double x1, x2, x3; -} vector3_fp64_t; +} bgc_vector3_fp64_t; // =================== Reset ==================== // -inline void vector3_reset_fp32(vector3_fp32_t* vector) +inline void bgc_vector3_reset_fp32(bgc_vector3_fp32_t* vector) { vector->x1 = 0.0f; vector->x2 = 0.0f; vector->x3 = 0.0f; } -inline void vector3_reset_fp64(vector3_fp64_t* vector) +inline void bgc_vector3_reset_fp64(bgc_vector3_fp64_t* vector) { vector->x1 = 0.0; vector->x2 = 0.0; @@ -36,14 +36,14 @@ inline void vector3_reset_fp64(vector3_fp64_t* vector) // ==================== Set ===================== // -inline void vector3_set_values_fp32(const float x1, const float x2, const float x3, vector3_fp32_t* to) +inline void bgc_vector3_set_values_fp32(const float x1, const float x2, const float x3, bgc_vector3_fp32_t* to) { to->x1 = x1; to->x2 = x2; to->x3 = x3; } -inline void vector3_set_values_fp64(const double x1, const double x2, const double x3, vector3_fp64_t* to) +inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const double x3, bgc_vector3_fp64_t* to) { to->x1 = x1; to->x2 = x2; @@ -52,14 +52,14 @@ inline void vector3_set_values_fp64(const double x1, const double x2, const doub // ==================== Copy ==================== // -inline void vector3_copy_fp32(const vector3_fp32_t* from, vector3_fp32_t* to) +inline void bgc_vector3_copy_fp32(const bgc_vector3_fp32_t* from, bgc_vector3_fp32_t* to) { to->x1 = from->x1; to->x2 = from->x2; to->x3 = from->x3; } -inline void vector3_copy_fp64(const vector3_fp64_t* from, vector3_fp64_t* to) +inline void bgc_vector3_copy_fp64(const bgc_vector3_fp64_t* from, bgc_vector3_fp64_t* to) { to->x1 = from->x1; to->x2 = from->x2; @@ -68,14 +68,14 @@ inline void vector3_copy_fp64(const vector3_fp64_t* from, vector3_fp64_t* to) // ================== Convert =================== // -inline void vector3_convert__fp64_to_fp32(const vector3_fp64_t* from, vector3_fp32_t* to) +inline void bgc_vector3_convert_fp64_to_fp32(const bgc_vector3_fp64_t* from, bgc_vector3_fp32_t* to) { to->x1 = (float) from->x1; to->x2 = (float) from->x2; to->x3 = (float) from->x3; } -inline void vector3_convert__fp32_to_fp64(const vector3_fp32_t* from, vector3_fp64_t* to) +inline void bgc_vector3_convert_fp32_to_fp64(const bgc_vector3_fp32_t* from, bgc_vector3_fp64_t* to) { to->x1 = from->x1; to->x2 = from->x2; @@ -84,7 +84,7 @@ inline void vector3_convert__fp32_to_fp64(const vector3_fp32_t* from, vector3_fp // ==================== Swap ==================== // -inline void vector3_swap_fp32(vector3_fp32_t* vector1, vector3_fp32_t* vector2) +inline void bgc_vector3_swap_fp32(bgc_vector3_fp32_t* vector1, bgc_vector3_fp32_t* vector2) { const float x1 = vector2->x1; const float x2 = vector2->x2; @@ -99,7 +99,7 @@ inline void vector3_swap_fp32(vector3_fp32_t* vector1, vector3_fp32_t* vector2) vector1->x3 = x3; } -inline void vector3_swap_fp64(vector3_fp64_t* vector1, vector3_fp64_t* vector2) +inline void bgc_vector3_swap_fp64(bgc_vector3_fp64_t* vector1, bgc_vector3_fp64_t* vector2) { const double x1 = vector2->x1; const double x2 = vector2->x2; @@ -116,14 +116,14 @@ inline void vector3_swap_fp64(vector3_fp64_t* vector1, vector3_fp64_t* vector2) // ==================== Invert ================== // -inline void vector3_invert_fp32(vector3_fp32_t* vector) +inline void bgc_vector3_invert_fp32(bgc_vector3_fp32_t* vector) { vector->x1 = -vector->x1; vector->x2 = -vector->x2; vector->x3 = -vector->x3; } -inline void vector3_invert_fp64(vector3_fp64_t* vector) +inline void bgc_vector3_invert_fp64(bgc_vector3_fp64_t* vector) { vector->x1 = -vector->x1; vector->x2 = -vector->x2; @@ -132,14 +132,14 @@ inline void vector3_invert_fp64(vector3_fp64_t* vector) // ================ Make Inverted =============== // -inline void vector3_set_inverted_fp32(const vector3_fp32_t* vector, vector3_fp32_t* result) +inline void bgc_vector3_set_inverted_fp32(const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* result) { result->x1 = -vector->x1; result->x2 = -vector->x2; result->x3 = -vector->x3; } -inline void vector3_set_inverted_fp64(const vector3_fp64_t* vector, vector3_fp64_t* result) +inline void bgc_vector3_set_inverted_fp64(const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* result) { result->x1 = -vector->x1; result->x2 = -vector->x2; @@ -148,14 +148,14 @@ inline void vector3_set_inverted_fp64(const vector3_fp64_t* vector, vector3_fp64 // ============== Make Inverted Twin ============ // -inline void vector3_set_inverted_fp32_to_fp64(const vector3_fp32_t* vector, vector3_fp64_t* result) +inline void bgc_vector3_set_inverted_fp32_to_fp64(const bgc_vector3_fp32_t* vector, bgc_vector3_fp64_t* result) { result->x1 = -vector->x1; result->x2 = -vector->x2; result->x3 = -vector->x3; } -inline void vector3_set_inverted_fp64_to_fp32(const vector3_fp64_t* vector, vector3_fp32_t* result) +inline void bgc_vector3_set_inverted_fp64_to_fp32(const bgc_vector3_fp64_t* vector, bgc_vector3_fp32_t* result) { result->x1 = (float) -vector->x1; result->x2 = (float) -vector->x2; @@ -164,94 +164,78 @@ inline void vector3_set_inverted_fp64_to_fp32(const vector3_fp64_t* vector, vect // =================== Module =================== // -inline float vector3_get_square_modulus_fp32(const vector3_fp32_t* vector) +inline float bgc_vector3_get_square_modulus_fp32(const bgc_vector3_fp32_t* vector) { return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; } -inline double vector3_get_square_modulus_fp64(const vector3_fp64_t* vector) +inline double bgc_vector3_get_square_modulus_fp64(const bgc_vector3_fp64_t* vector) { return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; } -inline float vector3_get_modulus_fp32(const vector3_fp32_t* vector) +inline float bgc_vector3_get_modulus_fp32(const bgc_vector3_fp32_t* vector) { - return sqrtf(vector3_get_square_modulus_fp32(vector)); + return sqrtf(bgc_vector3_get_square_modulus_fp32(vector)); } -inline double vector3_get_modulus_fp64(const vector3_fp64_t* vector) +inline double bgc_vector3_get_modulus_fp64(const bgc_vector3_fp64_t* vector) { - return sqrt(vector3_get_square_modulus_fp64(vector)); + return sqrt(bgc_vector3_get_square_modulus_fp64(vector)); } // ================= Comparison ================= // -inline int vector3_fp32_is_zero(const vector3_fp32_t* vector) +inline int bgc_vector3_is_zero_fp32(const bgc_vector3_fp32_t* vector) { - return vector3_get_square_modulus_fp32(vector) <= FP32_SQUARE_EPSYLON; + return bgc_vector3_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32; } -inline int vector3_fp64_is_zero(const vector3_fp64_t* vector) +inline int bgc_vector3_is_zero_fp64(const bgc_vector3_fp64_t* vector) { - return vector3_get_square_modulus_fp64(vector) <= FP64_SQUARE_EPSYLON; + return bgc_vector3_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64; } -inline int vector3_fp32_is_unit(const vector3_fp32_t* vector) +inline int bgc_vector3_is_unit_fp32(const bgc_vector3_fp32_t* vector) { - const float square_modulus = vector3_get_square_modulus_fp32(vector); + const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector); - return 1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON; + return 1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32; } -inline int vector3_fp64_is_unit(const vector3_fp64_t* vector) +inline int bgc_vector3_is_unit_fp64(const bgc_vector3_fp64_t* vector) { - const double square_modulus = vector3_get_square_modulus_fp64(vector); + const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector); - return 1.0f - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP64_TWO_EPSYLON; + return 1.0f - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP64; } // ==================== Add ===================== // -inline void vector3_add_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, vector3_fp32_t* sum) +inline void bgc_vector3_add_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* sum) { sum->x1 = vector1->x1 + vector2->x1; sum->x2 = vector1->x2 + vector2->x2; sum->x3 = vector1->x3 + vector2->x3; } -inline void vector3_add_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, vector3_fp64_t* sum) +inline void bgc_vector3_add_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* sum) { sum->x1 = vector1->x1 + vector2->x1; sum->x2 = vector1->x2 + vector2->x2; sum->x3 = vector1->x3 + vector2->x3; } -// ==================== Sum ===================== // - -inline void vector3_set_sum_fp32_to_fp64(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, vector3_fp64_t* sum) -{ - sum->x1 = vector1->x1 + vector2->x1; - sum->x2 = vector1->x2 + vector2->x2; - sum->x3 = vector1->x3 + vector2->x3; -} - -inline void vector3_set_sum_fp64_to_fp32(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, vector3_fp32_t* sum) -{ - sum->x1 = (float)(vector1->x1 + vector2->x1); - sum->x2 = (float)(vector1->x2 + vector2->x2); - sum->x3 = (float)(vector1->x3 + vector2->x3); -} - // ================= Add scaled ================= // -inline void vector3_add_scaled_fp32(const vector3_fp32_t* basic_vector, const vector3_fp32_t* scalable_vector, const float scale, vector3_fp32_t* result) +inline void bgc_vector3_add_scaled_fp32(const bgc_vector3_fp32_t* basic_vector, const bgc_vector3_fp32_t* scalable_vector, const float scale, bgc_vector3_fp32_t* result) { result->x1 = basic_vector->x1 + scalable_vector->x1 * scale; result->x2 = basic_vector->x2 + scalable_vector->x2 * scale; result->x3 = basic_vector->x3 + scalable_vector->x3 * scale; } -inline void vector3_add_scaled_fp64(const vector3_fp64_t* basic_vector, const vector3_fp64_t* scalable_vector, const double scale, vector3_fp64_t* result) +inline void bgc_vector3_add_scaled_fp64(const bgc_vector3_fp64_t* basic_vector, const bgc_vector3_fp64_t* scalable_vector, const double scale, bgc_vector3_fp64_t* result) { result->x1 = basic_vector->x1 + scalable_vector->x1 * scale; result->x2 = basic_vector->x2 + scalable_vector->x2 * scale; @@ -260,102 +244,58 @@ inline void vector3_add_scaled_fp64(const vector3_fp64_t* basic_vector, const ve // ================ Subtraction ================= // -inline void vector3_subtract_fp32(const vector3_fp32_t* minuend, const vector3_fp32_t* subtrahend, vector3_fp32_t* difference) +inline void bgc_vector3_subtract_fp32(const bgc_vector3_fp32_t* minuend, const bgc_vector3_fp32_t* subtrahend, bgc_vector3_fp32_t* difference) { difference->x1 = minuend->x1 - subtrahend->x1; difference->x2 = minuend->x2 - subtrahend->x2; difference->x3 = minuend->x3 - subtrahend->x3; } -inline void vector3_subtract_fp64(const vector3_fp64_t* minuend, const vector3_fp64_t* subtrahend, vector3_fp64_t* difference) +inline void bgc_vector3_subtract_fp64(const bgc_vector3_fp64_t* minuend, const bgc_vector3_fp64_t* subtrahend, bgc_vector3_fp64_t* difference) { difference->x1 = minuend->x1 - subtrahend->x1; difference->x2 = minuend->x2 - subtrahend->x2; difference->x3 = minuend->x3 - subtrahend->x3; } -// ================= Difference ================= // - -inline void vector3_set_difference_fp32_to_fp64(const vector3_fp32_t* minuend, const vector3_fp32_t* subtrahend, vector3_fp64_t* difference) -{ - difference->x1 = minuend->x1 - subtrahend->x1; - difference->x2 = minuend->x2 - subtrahend->x2; - difference->x3 = minuend->x3 - subtrahend->x3; -} - -inline void vector3_set_difference_fp64_to_fp32(const vector3_fp64_t* minuend, const vector3_fp64_t* subtrahend, vector3_fp64_t* difference) -{ - difference->x1 = (float)(minuend->x1 - subtrahend->x1); - difference->x2 = (float)(minuend->x2 - subtrahend->x2); - difference->x3 = (float)(minuend->x3 - subtrahend->x3); -} - // =============== Multiplication =============== // -inline void vector3_multiply_fp32(const vector3_fp32_t* multiplicand, const float multiplier, vector3_fp32_t* product) +inline void bgc_vector3_multiply_fp32(const bgc_vector3_fp32_t* multiplicand, const float multiplier, bgc_vector3_fp32_t* product) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; product->x3 = multiplicand->x3 * multiplier; } -inline void vector3_multiply_fp64(const vector3_fp64_t* multiplicand, const double multiplier, vector3_fp64_t* product) +inline void bgc_vector3_multiply_fp64(const bgc_vector3_fp64_t* multiplicand, const double multiplier, bgc_vector3_fp64_t* product) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; product->x3 = multiplicand->x3 * multiplier; } -// =============== Multiplication =============== // - -inline void vector3_set_product_fp32_to_fp64(const vector3_fp32_t* multiplicand, const double multiplier, vector3_fp64_t* product) -{ - product->x1 = multiplicand->x1 * multiplier; - product->x2 = multiplicand->x2 * multiplier; - product->x3 = multiplicand->x3 * multiplier; -} - -inline void vector3_set_product_fp64_to_fp32(const vector3_fp64_t* multiplicand, const double multiplier, vector3_fp32_t* product) -{ - product->x1 = (float)(multiplicand->x1 * multiplier); - product->x2 = (float)(multiplicand->x2 * multiplier); - product->x3 = (float)(multiplicand->x3 * multiplier); -} - // ================== Division ================== // -inline void vector3_divide_fp32(const vector3_fp32_t* dividend, const float divisor, vector3_fp32_t* quotient) +inline void bgc_vector3_divide_fp32(const bgc_vector3_fp32_t* dividend, const float divisor, bgc_vector3_fp32_t* quotient) { - vector3_multiply_fp32(dividend, 1.0f / divisor, quotient); + bgc_vector3_multiply_fp32(dividend, 1.0f / divisor, quotient); } -inline void vector3_divide_fp64(const vector3_fp64_t* dividend, const double divisor, vector3_fp64_t* quotient) +inline void bgc_vector3_divide_fp64(const bgc_vector3_fp64_t* dividend, const double divisor, bgc_vector3_fp64_t* quotient) { - vector3_multiply_fp64(dividend, 1.0 / divisor, quotient); -} - -// ================== Quotient ================== // - -inline void vector3_set_quotient_fp32_to_fp64(const vector3_fp32_t* dividend, const double divisor, vector3_fp64_t* quotient) -{ - vector3_set_product_fp32_to_fp64(dividend, 1.0 / divisor, quotient); -} - -inline void vector3_set_quotient_fp64_to_fp32(const vector3_fp64_t* dividend, const double divisor, vector3_fp32_t* quotient) -{ - vector3_set_product_fp64_to_fp32(dividend, 1.0f / divisor, quotient); + bgc_vector3_multiply_fp64(dividend, 1.0 / divisor, quotient); } // ================== Average2 ================== // -inline void vector3_mean_of_two_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, vector3_fp32_t* result) +inline void bgc_vector3_mean_of_two_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* 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; } -inline void vector3_mean_of_two_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, vector3_fp64_t* result) +inline void bgc_vector3_mean_of_two_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* result) { result->x1 = (vector1->x1 + vector2->x1) * 0.5; result->x2 = (vector1->x2 + vector2->x2) * 0.5; @@ -364,42 +304,42 @@ inline void vector3_mean_of_two_fp64(const vector3_fp64_t* vector1, const vector // ================== Average3 ================== // -inline void vector3_mean_of_three_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, const vector3_fp32_t* vector3, vector3_fp32_t* result) +inline void bgc_vector3_mean_of_three_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* vector3, bgc_vector3_fp32_t* result) { - result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP32_ONE_THIRD; - result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP32_ONE_THIRD; - result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * FP32_ONE_THIRD; + result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32; + result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32; + result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP32; } -inline void vector3_mean_of_three_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, const vector3_fp64_t* vector3, vector3_fp64_t* result) +inline void bgc_vector3_mean_of_three_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3, bgc_vector3_fp64_t* result) { - result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP64_ONE_THIRD; - result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP64_ONE_THIRD; - result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * FP64_ONE_THIRD; + result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64; + result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64; + result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP64; } // =============== Scalar Product =============== // -inline float vector3_scalar_product_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2) +inline float bgc_vector3_scalar_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2) { return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3; } -inline double vector3_scalar_product_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2) +inline double bgc_vector3_scalar_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2) { return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3; } // =============== Triple Product =============== // -inline float vector3_triple_product_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, const vector3_fp32_t* vector3) +inline float bgc_vector3_triple_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* 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); } -inline double vector3_triple_product_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, const vector3_fp64_t* vector3) +inline double bgc_vector3_triple_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3) { return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2) + vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3) @@ -408,7 +348,7 @@ inline double vector3_triple_product_fp64(const vector3_fp64_t* vector1, const v // =============== Cross Product ================ // -inline void vector3_cross_product_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, vector3_fp32_t* result) +inline void bgc_vector3_cross_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* result) { const float x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; const float x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; @@ -419,7 +359,7 @@ inline void vector3_cross_product_fp32(const vector3_fp32_t* vector1, const vect result->x3 = x3; } -inline void vector3_cross_product_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, vector3_fp64_t* result) +inline void bgc_vector3_cross_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* result) { const double x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2; const double x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3; @@ -432,20 +372,20 @@ inline void vector3_cross_product_fp64(const vector3_fp64_t* vector1, const vect // ============ Double Cross Product ============ // -inline void vector3_double_cross_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, const vector3_fp32_t* vector3, vector3_fp32_t* result) +inline void bgc_vector3_double_cross_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* vector3, bgc_vector3_fp32_t* result) { - const float ac = vector3_scalar_product_fp32(vector1, vector3); - const float ab = vector3_scalar_product_fp32(vector1, vector2); + const float ac = bgc_vector3_scalar_product_fp32(vector1, vector3); + const float ab = bgc_vector3_scalar_product_fp32(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; } -inline void vector3_double_cross_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, const vector3_fp64_t* vector3, vector3_fp64_t* result) +inline void bgc_vector3_double_cross_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3, bgc_vector3_fp64_t* result) { - const double ac = vector3_scalar_product_fp64(vector1, vector3); - const double ab = vector3_scalar_product_fp64(vector1, vector2); + const double ac = bgc_vector3_scalar_product_fp64(vector1, vector3); + const double ab = bgc_vector3_scalar_product_fp64(vector1, vector2); result->x1 = vector2->x1 * ac - vector3->x1 * ab; result->x2 = vector2->x2 * ac - vector3->x2 * ab; @@ -454,63 +394,63 @@ inline void vector3_double_cross_fp64(const vector3_fp64_t* vector1, const vecto // =============== Normalization ================ // -inline int vector3_normalize_fp32(vector3_fp32_t* vector) +inline int bgc_vector3_normalize_fp32(bgc_vector3_fp32_t* vector) { - const float square_modulus = vector3_get_square_modulus_fp32(vector); + const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector); - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return 1; } - if (square_modulus <= FP32_SQUARE_EPSYLON) { - vector3_reset_fp32(vector); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) { + bgc_vector3_reset_fp32(vector); return 0; } - vector3_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector); + bgc_vector3_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector); return 1; } -inline int vector3_normalize_fp64(vector3_fp64_t* vector) +inline int bgc_vector3_normalize_fp64(bgc_vector3_fp64_t* vector) { - const double square_modulus = vector3_get_square_modulus_fp64(vector); + const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector); - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return 1; } - if (square_modulus <= FP64_SQUARE_EPSYLON) { - vector3_reset_fp64(vector); + if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) { + bgc_vector3_reset_fp64(vector); return 0; } - vector3_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector); + bgc_vector3_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector); return 1; } // =============== Set Normalized =============== // -inline int vector3_set_normalized_fp32(const vector3_fp32_t* vector, vector3_fp32_t* result) +inline int bgc_vector3_set_normalized_fp32(const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* result) { - vector3_copy_fp32(vector, result); - return vector3_normalize_fp32(result); + bgc_vector3_copy_fp32(vector, result); + return bgc_vector3_normalize_fp32(result); } -inline int vector3_set_normalized_fp64(const vector3_fp64_t* vector, vector3_fp64_t* result) +inline int bgc_vector3_set_normalized_fp64(const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* result) { - vector3_copy_fp64(vector, result); - return vector3_normalize_fp64(result); + bgc_vector3_copy_fp64(vector, result); + return bgc_vector3_normalize_fp64(result); } // =================== Angle ==================== // -float vector3_get_angle_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2, const angle_unit_t unit); +float bgc_vector3_get_angle_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_angle_unit_t unit); -double vector3_get_angle_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2, const angle_unit_t unit); +double bgc_vector3_get_angle_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_angle_unit_t unit); // =============== Square Distance ============== // -inline float vector3_get_square_distance_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2) +inline float bgc_vector3_get_square_distance_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2) { const float dx1 = (vector1->x1 - vector2->x1); const float dx2 = (vector1->x2 - vector2->x2); @@ -519,7 +459,7 @@ inline float vector3_get_square_distance_fp32(const vector3_fp32_t* vector1, con return dx1 * dx1 + dx2 * dx2 + dx3 * dx3; } -inline double vector3_get_square_distance_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2) +inline double bgc_vector3_get_square_distance_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2) { const double dx1 = (vector1->x1 - vector2->x1); const double dx2 = (vector1->x2 - vector2->x2); @@ -530,52 +470,52 @@ inline double vector3_get_square_distance_fp64(const vector3_fp64_t* vector1, co // ================== Distance ================== // -inline float vector3_get_distance_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2) +inline float bgc_vector3_get_distance_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2) { - return sqrtf(vector3_get_square_distance_fp32(vector1, vector2)); + return sqrtf(bgc_vector3_get_square_distance_fp32(vector1, vector2)); } -inline double vector3_get_distance_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2) +inline double bgc_vector3_get_distance_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2) { - return sqrt(vector3_get_square_distance_fp64(vector1, vector2)); + return sqrt(bgc_vector3_get_square_distance_fp64(vector1, vector2)); } // ================== Are Equal ================= // -inline int vector3_are_equal_fp32(const vector3_fp32_t* vector1, const vector3_fp32_t* vector2) +inline int bgc_vector3_are_equal_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2) { - const float square_modulus1 = vector3_get_square_modulus_fp32(vector1); - const float square_modulus2 = vector3_get_square_modulus_fp32(vector2); - const float square_modulus3 = vector3_get_square_distance_fp32(vector1, vector2); + const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1); + const float square_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2); + const float square_modulus3 = bgc_vector3_get_square_distance_fp32(vector1, vector2); // 3.0f means dimension amount - if (square_modulus1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) { - return square_modulus3 < (3.0f * FP32_SQUARE_EPSYLON); + if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { + return square_modulus3 < (3.0f * BGC_SQUARE_EPSYLON_FP32); } if (square_modulus1 <= square_modulus2) { - return square_modulus3 <= (3.0f * FP32_SQUARE_EPSYLON) * square_modulus2; + return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2; } - return square_modulus3 <= (3.0f * FP32_SQUARE_EPSYLON) * square_modulus1; + return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1; } -inline int vector3_are_equal_fp64(const vector3_fp64_t* vector1, const vector3_fp64_t* vector2) +inline int bgc_vector3_are_equal_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2) { - const double square_modulus1 = vector3_get_square_modulus_fp64(vector1); - const double square_modulus2 = vector3_get_square_modulus_fp64(vector2); - const double square_modulus3 = vector3_get_square_distance_fp64(vector1, vector2); + const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1); + const double square_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2); + const double square_modulus3 = bgc_vector3_get_square_distance_fp64(vector1, vector2); // 3.0 means dimension amount - if (square_modulus1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) { - return square_modulus3 < (3.0 * FP64_SQUARE_EPSYLON); + if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { + return square_modulus3 < (3.0 * BGC_SQUARE_EPSYLON_FP64); } if (square_modulus1 <= square_modulus2) { - return square_modulus3 <= (3.0 * FP64_SQUARE_EPSYLON) * square_modulus2; + return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2; } - return square_modulus3 <= (3.0 * FP64_SQUARE_EPSYLON) * square_modulus1; + return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1; } #endif diff --git a/basic-geometry/versor.c b/basic-geometry/versor.c index 2dd540e..abe9758 100644 --- a/basic-geometry/versor.c +++ b/basic-geometry/versor.c @@ -3,68 +3,68 @@ #include "angle.h" #include "versor.h" -const versor_fp32_t FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f }; +const bgc_versor_fp32_t BGC_IDLE_VERSOR_FP32 = { 1.0f, 0.0f, 0.0f, 0.0f }; -const versor_fp64_t FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 }; +const bgc_versor_fp64_t BGC_IDLE_VERSOR_FP64 = { 1.0, 0.0, 0.0, 0.0 }; // =============== Set Crude Turn =============== // -void versor_set_crude_turn_fp32(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, versor_fp32_t* result) +void bgc_versor_set_crude_turn_fp32(const float x1, const float x2, const float x3, const float angle, const bgc_angle_unit_t unit, bgc_versor_fp32_t* result) { const float square_vector = x1 * x1 + x2 * x2 + x3 * x3; - if (square_vector <= FP32_SQUARE_EPSYLON) { - versor_reset_fp32(result); + if (square_vector <= BGC_SQUARE_EPSYLON_FP32) { + bgc_versor_reset_fp32(result); return; } - const float half_angle = fp32_angle_to_radians(0.5f * angle, unit); + const float half_angle = bgc_angle_to_radians_fp32(0.5f * angle, unit); const float sine = sinf(half_angle); - if (-FP32_EPSYLON <= sine && sine <= FP32_EPSYLON) { - versor_reset_fp32(result); + if (-BGC_EPSYLON_FP32 <= sine && sine <= BGC_EPSYLON_FP32) { + bgc_versor_reset_fp32(result); return; } const float multiplier = sine / sqrtf(square_vector); - versor_set_values_fp32(cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result); + bgc_versor_set_values_fp32(cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result); } -void versor_set_crude_turn_fp64(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, versor_fp64_t* result) +void bgc_versor_set_crude_turn_fp64(const double x1, const double x2, const double x3, const double angle, const bgc_angle_unit_t unit, bgc_versor_fp64_t* result) { const double square_vector = x1 * x1 + x2 * x2 + x3 * x3; - if (square_vector <= FP64_SQUARE_EPSYLON) { - versor_reset_fp64(result); + if (square_vector <= BGC_SQUARE_EPSYLON_FP64) { + bgc_versor_reset_fp64(result); return; } - const double half_angle = fp64_angle_to_radians(0.5 * angle, unit); + const double half_angle = bgc_angle_to_radians_fp64(0.5 * angle, unit); const double sine = sin(half_angle); - if (-FP64_EPSYLON <= sine && sine <= FP64_EPSYLON) { - versor_reset_fp64(result); + if (-BGC_EPSYLON_FP64 <= sine && sine <= BGC_EPSYLON_FP64) { + bgc_versor_reset_fp64(result); return; } const double multiplier = sine / sqrt(square_vector); - versor_set_values_fp64(cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result); + bgc_versor_set_values_fp64(cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result); } // ================= Rotation3 ================== // -void versor_get_rotation_fp32(const versor_fp32_t* versor, rotation3_fp32_t* result) +void bgc_versor_get_rotation_fp32(const bgc_versor_fp32_t* versor, bgc_rotation3_fp32_t* result) { if (versor == 0 || result == 0) { return; } - if (versor->s0 <= -(1.0f - FP32_EPSYLON) || 1.0f - FP32_EPSYLON <= versor->s0) { - fp32_rotation_reset(result); + if (versor->s0 <= -(1.0f - BGC_EPSYLON_FP32) || 1.0f - BGC_EPSYLON_FP32 <= versor->s0) { + bgc_rotation3_reset_fp32(result); return; } @@ -79,14 +79,14 @@ void versor_get_rotation_fp32(const versor_fp32_t* versor, rotation3_fp32_t* res result->axis.x3 = versor->x3 * multiplier; } -void versor_get_rotation_fp64(const versor_fp64_t* versor, rotation3_fp64_t* result) +void bgc_versor_get_rotation_fp64(const bgc_versor_fp64_t* versor, bgc_rotation3_fp64_t* result) { if (versor == 0 || result == 0) { return; } - if (versor->s0 <= -(1.0 - FP64_EPSYLON) || 1.0 - FP64_EPSYLON <= versor->s0) { - fp64_rotation_reset(result); + if (versor->s0 <= -(1.0 - BGC_EPSYLON_FP64) || 1.0 - BGC_EPSYLON_FP64 <= versor->s0) { + bgc_rotation3_reset_fp64(result); return; } diff --git a/basic-geometry/versor.h b/basic-geometry/versor.h index 7dbb219..72befad 100644 --- a/basic-geometry/versor.h +++ b/basic-geometry/versor.h @@ -1,9 +1,9 @@ -#ifndef _BASIC_GEOMETRY_VERSOR_H_ -#define _BASIC_GEOMETRY_VERSOR_H_ +#ifndef _BGC_VERSOR_H_ +#define _BGC_VERSOR_H_ #include -#include "basis.h" +#include "utilities.h" #include "angle.h" #include "vector3.h" #include "rotation3.h" @@ -13,32 +13,32 @@ typedef struct { const float s0, x1, x2, x3; -} versor_fp32_t; +} bgc_versor_fp32_t; typedef struct { const double s0, x1, x2, x3; -} versor_fp64_t; +} bgc_versor_fp64_t; // ================= Dark Twins ================= // typedef struct { float s0, x1, x2, x3; -} __BgFP32DarkTwinVersor; +} _bgc_dark_twin_versor_fp32_t; typedef struct { double s0, x1, x2, x3; -} __BgFP64DarkTwinVersor; +} _bgc_dark_twin_versor_fp64_t; // ================= Constants ================== // -extern const versor_fp32_t FP32_IDLE_VERSOR; -extern const versor_fp64_t FP64_IDLE_VERSOR; +extern const bgc_versor_fp32_t BGC_IDLE_VERSOR_FP32; +extern const bgc_versor_fp64_t BGC_IDLE_VERSOR_FP64; // =================== Reset ==================== // -inline void versor_reset_fp32(versor_fp32_t* versor) +inline void bgc_versor_reset_fp32(bgc_versor_fp32_t* versor) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)versor; twin->s0 = 1.0f; twin->x1 = 0.0f; @@ -46,9 +46,9 @@ inline void versor_reset_fp32(versor_fp32_t* versor) twin->x3 = 0.0f; } -inline void versor_reset_fp64(versor_fp64_t* versor) +inline void bgc_versor_reset_fp64(bgc_versor_fp64_t* versor) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)versor; twin->s0 = 1.0; twin->x1 = 0.0; @@ -58,9 +58,9 @@ inline void versor_reset_fp64(versor_fp64_t* versor) // ==================== Set ===================== // -inline void versor_set_values_fp32(const float s0, const float x1, const float x2, const float x3, versor_fp32_t* versor) +inline void bgc_versor_set_values_fp32(const float s0, const float x1, const float x2, const float x3, bgc_versor_fp32_t* versor) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)versor; twin->s0 = s0; twin->x1 = x1; @@ -69,11 +69,11 @@ inline void versor_set_values_fp32(const float s0, const float x1, const float x const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return; } - if (square_modulus <= FP32_SQUARE_EPSYLON) { + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) { twin->s0 = 1.0f; twin->x1 = 0.0f; twin->x2 = 0.0f; @@ -89,9 +89,9 @@ inline void versor_set_values_fp32(const float s0, const float x1, const float x twin->x3 *= multiplier; } -inline void versor_set_values_fp64(const double s0, const double x1, const double x2, const double x3, versor_fp64_t* versor) +inline void bgc_versor_set_values_fp64(const double s0, const double x1, const double x2, const double x3, bgc_versor_fp64_t* versor) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)versor; twin->s0 = s0; twin->x1 = x1; @@ -100,11 +100,11 @@ inline void versor_set_values_fp64(const double s0, const double x1, const doubl const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return; } - if (square_modulus <= FP64_SQUARE_EPSYLON) { + if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) { twin->s0 = 1.0; twin->x1 = 0.0; twin->x2 = 0.0; @@ -122,9 +122,9 @@ inline void versor_set_values_fp64(const double s0, const double x1, const doubl // ==================== Copy ==================== // -inline void versor_copy_fp32(const versor_fp32_t* from, versor_fp32_t* to) +inline void bgc_versor_copy_fp32(const bgc_versor_fp32_t* from, bgc_versor_fp32_t* to) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)to; twin->s0 = from->s0; twin->x1 = from->x1; @@ -132,9 +132,9 @@ inline void versor_copy_fp32(const versor_fp32_t* from, versor_fp32_t* to) twin->x3 = from->x3; } -inline void versor_copy_fp64(const versor_fp64_t* from, versor_fp64_t* to) +inline void bgc_versor_copy_fp64(const bgc_versor_fp64_t* from, bgc_versor_fp64_t* to) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)to; twin->s0 = from->s0; twin->x1 = from->x1; @@ -144,21 +144,21 @@ inline void versor_copy_fp64(const versor_fp64_t* from, versor_fp64_t* to) // ==================== Swap ==================== // -inline void versor_swap_fp32(versor_fp32_t* versor1, versor_fp32_t* versor2) +inline void bgc_versor_swap_fp32(bgc_versor_fp32_t* versor1, bgc_versor_fp32_t* versor2) { const float s0 = versor1->s0; const float x1 = versor1->x1; const float x2 = versor1->x2; const float x3 = versor1->x3; - __BgFP32DarkTwinVersor* twin1 = (__BgFP32DarkTwinVersor*)versor1; + _bgc_dark_twin_versor_fp32_t* twin1 = (_bgc_dark_twin_versor_fp32_t*)versor1; twin1->s0 = versor2->s0; twin1->x1 = versor2->x1; twin1->x2 = versor2->x2; twin1->x3 = versor2->x3; - __BgFP32DarkTwinVersor* twin2 = (__BgFP32DarkTwinVersor*)versor2; + _bgc_dark_twin_versor_fp32_t* twin2 = (_bgc_dark_twin_versor_fp32_t*)versor2; twin2->s0 = s0; twin2->x1 = x1; @@ -166,21 +166,21 @@ inline void versor_swap_fp32(versor_fp32_t* versor1, versor_fp32_t* versor2) twin2->x3 = x3; } -inline void versor_swap_fp64(versor_fp64_t* versor1, versor_fp64_t* versor2) +inline void bgc_versor_swap_fp64(bgc_versor_fp64_t* versor1, bgc_versor_fp64_t* versor2) { const double s0 = versor1->s0; const double x1 = versor1->x1; const double x2 = versor1->x2; const double x3 = versor1->x3; - __BgFP64DarkTwinVersor* twin1 = (__BgFP64DarkTwinVersor*)versor1; + _bgc_dark_twin_versor_fp64_t* twin1 = (_bgc_dark_twin_versor_fp64_t*)versor1; twin1->s0 = versor2->s0; twin1->x1 = versor2->x1; twin1->x2 = versor2->x2; twin1->x3 = versor2->x3; - __BgFP64DarkTwinVersor* twin2 = (__BgFP64DarkTwinVersor*)versor2; + _bgc_dark_twin_versor_fp64_t* twin2 = (_bgc_dark_twin_versor_fp64_t*)versor2; twin2->s0 = s0; twin2->x1 = x1; @@ -190,51 +190,51 @@ inline void versor_swap_fp64(versor_fp64_t* versor1, versor_fp64_t* versor2) // =============== Set Crude Turn =============== // -void versor_set_crude_turn_fp32(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, versor_fp32_t* result); +void bgc_versor_set_crude_turn_fp32(const float x1, const float x2, const float x3, const float angle, const bgc_angle_unit_t unit, bgc_versor_fp32_t* result); -void versor_set_crude_turn_fp64(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, versor_fp64_t* result); +void bgc_versor_set_crude_turn_fp64(const double x1, const double x2, const double x3, const double angle, const bgc_angle_unit_t unit, bgc_versor_fp64_t* result); // ================== Set Turn ================== // -inline void versor_set_turn_fp32(const vector3_fp32_t* axis, const float angle, const angle_unit_t unit, versor_fp32_t* result) +inline void bgc_versor_set_turn_fp32(const bgc_vector3_fp32_t* axis, const float angle, const bgc_angle_unit_t unit, bgc_versor_fp32_t* result) { - versor_set_crude_turn_fp32(axis->x1, axis->x2, axis->x3, angle, unit, result); + bgc_versor_set_crude_turn_fp32(axis->x1, axis->x2, axis->x3, angle, unit, result); } -inline void versor_set_turn_fp64(const vector3_fp32_t* axis, const double angle, const angle_unit_t unit, versor_fp64_t* result) +inline void bgc_versor_set_turn_fp64(const bgc_vector3_fp32_t* axis, const double angle, const bgc_angle_unit_t unit, bgc_versor_fp64_t* result) { - versor_set_crude_turn_fp64(axis->x1, axis->x2, axis->x3, angle, unit, result); + bgc_versor_set_crude_turn_fp64(axis->x1, axis->x2, axis->x3, angle, unit, result); } // ================ Set Rotation ================ // -inline void versor_set_rotation_fp32(const rotation3_fp32_t* rotation, versor_fp32_t* result) +inline void bgc_versor_set_rotation_fp32(const bgc_rotation3_fp32_t* rotation, bgc_versor_fp32_t* result) { - versor_set_crude_turn_fp32(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result); + bgc_versor_set_crude_turn_fp32(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS, result); } -inline void versor_set_rotation_fp64(const rotation3_fp64_t* rotation, versor_fp64_t* result) +inline void bgc_versor_set_rotation_fp64(const bgc_rotation3_fp64_t* rotation, bgc_versor_fp64_t* result) { - versor_set_crude_turn_fp64(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result); + bgc_versor_set_crude_turn_fp64(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BGC_ANGLE_UNIT_RADIANS, result); } // ================= Comparison ================= // -inline int versor_is_idle_fp32(const versor_fp32_t* versor) +inline int bgc_versor_is_idle_fp32(const bgc_versor_fp32_t* versor) { - return 1.0f - FP32_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - FP32_EPSYLON); + return 1.0f - BGC_EPSYLON_FP32 <= versor->s0 || versor->s0 <= -(1.0 - BGC_EPSYLON_FP32); } -inline int versor_is_idle_fp64(const versor_fp64_t* versor) +inline int bgc_versor_is_idle_fp64(const bgc_versor_fp64_t* versor) { - return 1.0 - FP64_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - FP64_EPSYLON); + return 1.0 - BGC_EPSYLON_FP64 <= versor->s0 || versor->s0 <= -(1.0 - BGC_EPSYLON_FP64); } // ============= Copy to twin type ============== // -inline void versor_convert_fp64_to_fp32(const versor_fp64_t* versor, versor_fp32_t* result) +inline void bgc_versor_convert_fp64_to_fp32(const bgc_versor_fp64_t* versor, bgc_versor_fp32_t* result) { - versor_set_values_fp32( + bgc_versor_set_values_fp32( (float) versor->s0, (float) versor->x1, (float) versor->x2, @@ -243,9 +243,9 @@ inline void versor_convert_fp64_to_fp32(const versor_fp64_t* versor, versor_fp32 ); } -inline void versor_convert_fp32_to_fp64(const versor_fp32_t* versor, versor_fp64_t* result) +inline void bgc_versor_convert_fp32_to_fp64(const bgc_versor_fp32_t* versor, bgc_versor_fp64_t* result) { - versor_set_values_fp64( + bgc_versor_set_values_fp64( versor->s0, versor->x1, versor->x2, @@ -256,26 +256,26 @@ inline void versor_convert_fp32_to_fp64(const versor_fp32_t* versor, versor_fp64 // ================== Shorten =================== // -inline void versor_shorten_fp32(versor_fp32_t* versor) +inline void bgc_versor_shorten_fp32(bgc_versor_fp32_t* versor) { if (versor->s0 >= 0.0f) { return; } - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)versor; twin->s0 = -versor->s0; twin->x1 = -versor->x1; twin->x2 = -versor->x2; twin->x3 = -versor->x3; } -inline void versor_shorten_fp64(versor_fp64_t* versor) +inline void bgc_versor_shorten_fp64(bgc_versor_fp64_t* versor) { if (versor->s0 >= 0.0f) { return; } - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)versor; twin->s0 = -versor->s0; twin->x1 = -versor->x1; twin->x2 = -versor->x2; @@ -284,9 +284,9 @@ inline void versor_shorten_fp64(versor_fp64_t* versor) // ================== Shorten =================== // -inline void versor_set_shortened_fp32(const versor_fp32_t* versor, versor_fp32_t* shortened) +inline void bgc_versor_set_shortened_fp32(const bgc_versor_fp32_t* versor, bgc_versor_fp32_t* shortened) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)shortened; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)shortened; if (versor->s0 >= 0.0f) { twin->x1 = versor->s0; @@ -302,9 +302,9 @@ inline void versor_set_shortened_fp32(const versor_fp32_t* versor, versor_fp32_t twin->x3 = -versor->x3; } -inline void versor_set_shortened_fp64(const versor_fp64_t* versor, versor_fp64_t* shortened) +inline void bgc_versor_set_shortened_fp64(const bgc_versor_fp64_t* versor, bgc_versor_fp64_t* shortened) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)shortened; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)shortened; if (versor->s0 >= 0.0) { twin->x1 = versor->s0; @@ -322,17 +322,17 @@ inline void versor_set_shortened_fp64(const versor_fp64_t* versor, versor_fp64_t // ================= Inversion ================== // -inline void versor_invert_fp32(versor_fp32_t* versor) +inline void bgc_versor_invert_fp32(bgc_versor_fp32_t* versor) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)versor; twin->x1 = -versor->x1; twin->x2 = -versor->x2; twin->x3 = -versor->x3; } -inline void versor_invert_fp64(versor_fp64_t* versor) +inline void bgc_versor_invert_fp64(bgc_versor_fp64_t* versor) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)versor; twin->x1 = -versor->x1; twin->x2 = -versor->x2; twin->x3 = -versor->x3; @@ -340,18 +340,18 @@ inline void versor_invert_fp64(versor_fp64_t* versor) // ================ Set Inverted ================ // -inline void versor_set_inverted_fp32(const versor_fp32_t* versor, versor_fp32_t* to) +inline void bgc_versor_set_inverted_fp32(const bgc_versor_fp32_t* versor, bgc_versor_fp32_t* to) { - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)to; twin->s0 = versor->s0; twin->x1 = -versor->x1; twin->x2 = -versor->x2; twin->x3 = -versor->x3; } -inline void versor_set_inverted_fp64(const versor_fp64_t* versor, versor_fp64_t* to) +inline void bgc_versor_set_inverted_fp64(const bgc_versor_fp64_t* versor, bgc_versor_fp64_t* to) { - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)to; twin->s0 = versor->s0; twin->x1 = -versor->x1; twin->x2 = -versor->x2; @@ -360,9 +360,9 @@ inline void versor_set_inverted_fp64(const versor_fp64_t* versor, versor_fp64_t* // ================ Set Inverted ================ // -inline void versor_set_inverted_fp64_to_fp32(const versor_fp64_t* versor, versor_fp32_t* to) +inline void bgc_versor_set_inverted_fp64_to_fp32(const bgc_versor_fp64_t* versor, bgc_versor_fp32_t* to) { - versor_set_values_fp32( + bgc_versor_set_values_fp32( (float) versor->s0, (float) -versor->x1, (float) -versor->x2, @@ -371,9 +371,9 @@ inline void versor_set_inverted_fp64_to_fp32(const versor_fp64_t* versor, versor ); } -inline void versor_set_inverted_fp32_to_fp64(const versor_fp32_t* versor, versor_fp64_t* to) +inline void bgc_versor_set_inverted_fp32_to_fp64(const bgc_versor_fp32_t* versor, bgc_versor_fp64_t* to) { - versor_set_values_fp64( + bgc_versor_set_values_fp64( versor->s0, -versor->x1, -versor->x2, @@ -384,7 +384,7 @@ inline void versor_set_inverted_fp32_to_fp64(const versor_fp32_t* versor, versor // ================ Combination ================= // -inline void versor_combine_fp32(const versor_fp32_t* second, const versor_fp32_t* first, versor_fp32_t* result) +inline void bgc_versor_combine_fp32(const bgc_versor_fp32_t* second, const bgc_versor_fp32_t* first, bgc_versor_fp32_t* 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); @@ -393,14 +393,14 @@ inline void versor_combine_fp32(const versor_fp32_t* second, const versor_fp32_t const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)result; twin->s0 = s0; twin->x1 = x1; twin->x2 = x2; twin->x3 = x3; - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return; } @@ -412,7 +412,7 @@ inline void versor_combine_fp32(const versor_fp32_t* second, const versor_fp32_t twin->x3 *= multiplier; } -inline void versor_combine_fp64(const versor_fp64_t* second, const versor_fp64_t* first, versor_fp64_t* result) +inline void bgc_versor_combine_fp64(const bgc_versor_fp64_t* second, const bgc_versor_fp64_t* first, bgc_versor_fp64_t* 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); @@ -421,14 +421,14 @@ inline void versor_combine_fp64(const versor_fp64_t* second, const versor_fp64_t const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)result; twin->s0 = s0; twin->x1 = x1; twin->x2 = x2; twin->x3 = x3; - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return; } @@ -442,7 +442,7 @@ inline void versor_combine_fp64(const versor_fp64_t* second, const versor_fp64_t // ============ Combination of three ============ // -inline void versor_combine3_fp32(const versor_fp32_t* third, const versor_fp32_t* second, const versor_fp32_t* first, versor_fp32_t* result) +inline void bgc_versor_combine3_fp32(const bgc_versor_fp32_t* third, const bgc_versor_fp32_t* second, const bgc_versor_fp32_t* first, bgc_versor_fp32_t* result) { const float s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3); const float x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3); @@ -456,14 +456,14 @@ inline void versor_combine3_fp32(const versor_fp32_t* third, const versor_fp32_t const float square_modulus = (s0b * s0b + x1b * x1b) + (x2b * x2b + x3b * x3b); - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)result; twin->s0 = s0b; twin->x1 = x1b; twin->x2 = x2b; twin->x3 = x3b; - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return; } @@ -475,7 +475,7 @@ inline void versor_combine3_fp32(const versor_fp32_t* third, const versor_fp32_t twin->x3 *= multiplier; } -inline void versor_combine3_fp64(const versor_fp64_t* third, const versor_fp64_t* second, const versor_fp64_t* first, versor_fp64_t* result) +inline void bgc_versor_combine3_fp64(const bgc_versor_fp64_t* third, const bgc_versor_fp64_t* second, const bgc_versor_fp64_t* first, bgc_versor_fp64_t* result) { const double s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3); const double x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3); @@ -489,14 +489,14 @@ inline void versor_combine3_fp64(const versor_fp64_t* third, const versor_fp64_t const double square_modulus = (s0b * s0b + x1b * x1b) + (x2b * x2b + x3b * x3b); - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)result; twin->s0 = s0b; twin->x1 = x1b; twin->x2 = x2b; twin->x3 = x3b; - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return; } @@ -510,7 +510,7 @@ inline void versor_combine3_fp64(const versor_fp64_t* third, const versor_fp64_t // ================= Exclusion ================== // -inline void versor_exclude_fp32(const versor_fp32_t* basic, const versor_fp32_t* exclusion, versor_fp32_t* result) +inline void bgc_versor_exclude_fp32(const bgc_versor_fp32_t* basic, const bgc_versor_fp32_t* exclusion, bgc_versor_fp32_t* result) { const float s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3); const float x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3); @@ -519,14 +519,14 @@ inline void versor_exclude_fp32(const versor_fp32_t* basic, const versor_fp32_t* const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp32_t* twin = (_bgc_dark_twin_versor_fp32_t*)result; twin->s0 = s0; twin->x1 = x1; twin->x2 = x2; twin->x3 = x3; - if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) { + if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) { return; } @@ -538,7 +538,7 @@ inline void versor_exclude_fp32(const versor_fp32_t* basic, const versor_fp32_t* twin->x3 *= multiplier; } -inline void versor_exclude_fp64(const versor_fp64_t* basic, const versor_fp64_t* exclusion, versor_fp64_t* result) +inline void bgc_versor_exclude_fp64(const bgc_versor_fp64_t* basic, const bgc_versor_fp64_t* exclusion, bgc_versor_fp64_t* result) { const double s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3); const double x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3); @@ -547,14 +547,14 @@ inline void versor_exclude_fp64(const versor_fp64_t* basic, const versor_fp64_t* const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); - __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result; + _bgc_dark_twin_versor_fp64_t* twin = (_bgc_dark_twin_versor_fp64_t*)result; twin->s0 = s0; twin->x1 = x1; twin->x2 = x2; twin->x3 = x3; - if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) { + if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) { return; } @@ -568,13 +568,13 @@ inline void versor_exclude_fp64(const versor_fp64_t* basic, const versor_fp64_t* // ================= Rotation3 ================== // -void versor_get_rotation_fp32(const versor_fp32_t* versor, rotation3_fp32_t* result); +void bgc_versor_get_rotation_fp32(const bgc_versor_fp32_t* versor, bgc_rotation3_fp32_t* result); -void versor_get_rotation_fp64(const versor_fp64_t* versor, rotation3_fp64_t* result); +void bgc_versor_get_rotation_fp64(const bgc_versor_fp64_t* versor, bgc_rotation3_fp64_t* result); // =========== Make Rotation Matrix3x3 ========== // -inline void versor_make_rotation_matrix_fp32(const versor_fp32_t* versor, matrix3x3_fp32_t* matrix) +inline void bgc_versor_make_rotation_matrix_fp32(const bgc_versor_fp32_t* versor, bgc_matrix3x3_fp32_t* matrix) { const float s0s0 = versor->s0 * versor->s0; const float x1x1 = versor->x1 * versor->x1; @@ -602,7 +602,7 @@ inline void versor_make_rotation_matrix_fp32(const versor_fp32_t* versor, matrix matrix->r1c3 = x1x3 + s0x2; } -inline void versor_make_rotation_matrix_fp64(const versor_fp64_t* versor, matrix3x3_fp64_t* matrix) +inline void bgc_versor_make_rotation_matrix_fp64(const bgc_versor_fp64_t* versor, bgc_matrix3x3_fp64_t* matrix) { const double s0s0 = versor->s0 * versor->s0; const double x1x1 = versor->x1 * versor->x1; @@ -632,7 +632,7 @@ inline void versor_make_rotation_matrix_fp64(const versor_fp64_t* versor, matrix // =========== Make Reverse Matrix3x3 =========== // -inline void versor_make_reverse_matrix_fp32(const versor_fp32_t* versor, matrix3x3_fp32_t* matrix) +inline void bgc_versor_make_reverse_matrix_fp32(const bgc_versor_fp32_t* versor, bgc_matrix3x3_fp32_t* matrix) { const float s0s0 = versor->s0 * versor->s0; const float x1x1 = versor->x1 * versor->x1; @@ -660,7 +660,7 @@ inline void versor_make_reverse_matrix_fp32(const versor_fp32_t* versor, matrix3 matrix->r1c3 = x1x3 - s0x2; } -inline void versor_make_reverse_matrix_fp64(const versor_fp64_t* versor, matrix3x3_fp64_t* matrix) +inline void bgc_versor_make_reverse_matrix_fp64(const bgc_versor_fp64_t* versor, bgc_matrix3x3_fp64_t* matrix) { const double s0s0 = versor->s0 * versor->s0; const double x1x1 = versor->x1 * versor->x1; @@ -690,7 +690,7 @@ inline void versor_make_reverse_matrix_fp64(const versor_fp64_t* versor, matrix3 // ================ Turn Vector ================= // -inline void versor_turn_vector_fp32(const versor_fp32_t* versor, const vector3_fp32_t* vector, vector3_fp32_t* result) +inline void bgc_versor_turn_vector_fp32(const bgc_versor_fp32_t* versor, const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* 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); @@ -705,7 +705,7 @@ inline void versor_turn_vector_fp32(const versor_fp32_t* versor, const vector3_f result->x3 = x3; } -inline void versor_turn_vector_fp64(const versor_fp64_t* versor, const vector3_fp64_t* vector, vector3_fp64_t* result) +inline void bgc_versor_turn_vector_fp64(const bgc_versor_fp64_t* versor, const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* 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); @@ -722,7 +722,7 @@ inline void versor_turn_vector_fp64(const versor_fp64_t* versor, const vector3_f // ============== Turn Vector Back ============== // -inline void versor_turn_vector_back_fp32(const versor_fp32_t* versor, const vector3_fp32_t* vector, vector3_fp32_t* result) +inline void bgc_versor_turn_vector_back_fp32(const bgc_versor_fp32_t* versor, const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* 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); @@ -737,7 +737,7 @@ inline void versor_turn_vector_back_fp32(const versor_fp32_t* versor, const vect result->x3 = x3; } -inline void versor_turn_vector_back_fp64(const versor_fp64_t* versor, const vector3_fp64_t* vector, vector3_fp64_t* result) +inline void bgc_versor_turn_vector_back_fp64(const bgc_versor_fp64_t* versor, const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* 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);