diff --git a/basic-geometry-dev/main.c b/basic-geometry-dev/main.c index 06bb601..b1f5468 100644 --- a/basic-geometry-dev/main.c +++ b/basic-geometry-dev/main.c @@ -1,3 +1,4 @@ +/* #include #include #include @@ -59,7 +60,7 @@ structure_fp32_t* make_structures(const unsigned int amount) ); bgc_vector3_reset_fp32(&list[i].vector2); - */ + *//* } return list; @@ -137,23 +138,16 @@ int main() } */ -//#include -//#include - #include #include int main() { - BgcVector3FP32 my_vector1, my_vector2; + BgcVector3FP32 my_vector; - bgc_vector3_set_values_fp32(-2, 7, 5, &my_vector1); - bgc_vector3_set_values_fp32(10, -1, -3, &my_vector2); + bgc_vector3_set_values_fp32(-2, 7, 10, &my_vector); - bgc_vector3_swap_fp32(&my_vector1, &my_vector2); - - printf("Vector #1: x1 = %f, x2 = %f, x3 = %f\n", my_vector1.x1, my_vector1.x2, my_vector1.x3); - printf("Vector #2: x1 = %f, x2 = %f, x3 = %f\n", my_vector2.x1, my_vector2.x2, my_vector2.x3); + printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3); return 0; } diff --git a/basic-geometry/basic-geometry.h b/basic-geometry/basic-geometry.h index 7a608d8..5a3923c 100644 --- a/basic-geometry/basic-geometry.h +++ b/basic-geometry/basic-geometry.h @@ -14,7 +14,7 @@ #include "matrix3x2.h" #include "matrix3x3.h" -#include "tangent.h" +#include "tangent-pair.h" #include "rotation3.h" diff --git a/basic-geometry/basic-geometry.vcxproj b/basic-geometry/basic-geometry.vcxproj index 8a228bb..98620b5 100644 --- a/basic-geometry/basic-geometry.vcxproj +++ b/basic-geometry/basic-geometry.vcxproj @@ -28,7 +28,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/basic-geometry/basic-geometry.vcxproj.filters b/basic-geometry/basic-geometry.vcxproj.filters index 2cb8892..2349250 100644 --- a/basic-geometry/basic-geometry.vcxproj.filters +++ b/basic-geometry/basic-geometry.vcxproj.filters @@ -54,7 +54,7 @@ Файлы заголовков - + Файлы заголовков @@ -95,7 +95,7 @@ Исходные файлы - + Исходные файлы diff --git a/basic-geometry/tangent-pair.c b/basic-geometry/tangent-pair.c new file mode 100644 index 0000000..e0bce76 --- /dev/null +++ b/basic-geometry/tangent-pair.c @@ -0,0 +1,82 @@ +#include "tangent-pair.h" + +const BgcTangentPairFP32 BGC_IDLE_TANGENT_PAIR_FP32 = { 1.0f, 0.0f }; + +const BgcTangentPairFP64 BGC_IDLE_TANGENT_PAIR_FP64 = { 1.0, 0.0 }; + +extern inline void bgc_tangent_pair_reset_fp32(BgcTangentPairFP32* tangent); +extern inline void bgc_tangent_pair_reset_fp64(BgcTangentPairFP64* tangent); + +extern inline void bgc_tangent_pair_set_values_fp32(const float x1, const float x2, BgcTangentPairFP32* tangent); +extern inline void bgc_tangent_pair_set_values_fp64(const double x1, const double x2, BgcTangentPairFP64* tangent); + +extern inline void bgc_tangent_pair_copy_fp32(const BgcTangentPairFP32* from, BgcTangentPairFP32* to); +extern inline void bgc_tangent_pair_copy_fp64(const BgcTangentPairFP64* from, BgcTangentPairFP64* to); + +extern inline void bgc_tangent_pair_swap_fp32(BgcTangentPairFP32* tangent1, BgcTangentPairFP32* tangent2); +extern inline void bgc_tangent_pair_swap_fp64(BgcTangentPairFP64* tangent1, BgcTangentPairFP64* tangent2); + +extern inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent); +extern inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent); + +extern inline void bgc_tangent_pair_convert_fp64_to_fp32(const BgcTangentPairFP64* from, BgcTangentPairFP32* to); +extern inline void bgc_tangent_pair_convert_fp32_to_fp64(const BgcTangentPairFP32* from, BgcTangentPairFP64* to); + +extern inline void bgc_tangent_pair_invert_fp32(BgcTangentPairFP32* tangent); +extern inline void bgc_tangent_pair_invert_fp64(BgcTangentPairFP64* tangent); + +extern inline void bgc_tangent_pair_set_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result); +extern inline void bgc_tangent_pair_set_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result); + +extern inline void bgc_tangent_pair_make_rotation_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix); +extern inline void bgc_tangent_pair_make_rotation_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix); + +extern inline void bgc_tangent_pair_make_reverse_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix); +extern inline void bgc_tangent_pair_make_reverse_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix); + +extern inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit); +extern inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit); + +extern inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result); +extern inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result); + +extern inline void bgc_tangent_pair_turn_vector_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result); +extern inline void bgc_tangent_pair_turn_vector_fp64(const BgcTangentPairFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result); + +extern inline void bgc_tangent_pair_turn_vector_back_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result); +extern inline void bgc_tangent_pair_turn_vector_back_fp64(const BgcTangentPairFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result); + +extern inline int bgc_tangent_pair_are_close_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2); +extern inline int bgc_tangent_pair_are_close_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2); + +void _bgc_tangent_pair_normalize_fp32(const float square_modulus, _BgcTwinTangentPairFP32* twin) +{ + // (square_modulus != square_modulus) is true when square_modulus is NaN + + if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) { + twin->cos = 1.0f; + twin->sin = 0.0f; + return; + } + + const float multiplier = sqrtf(1.0f / square_modulus); + + twin->cos *= multiplier; + twin->sin *= multiplier; +} + +void _bgc_tangent_pair_normalize_fp64(const double square_modulus, _BgcTwinTangentPairFP64* twin) +{ + // (square_modulus != square_modulus) is true when square_modulus is NaN + + if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) { + twin->cos = 1.0; + twin->sin = 0.0; + return; + } + + const double multiplier = sqrt(1.0 / square_modulus); + + twin->cos *= multiplier; + twin->sin *= multiplier; +} diff --git a/basic-geometry/tangent.h b/basic-geometry/tangent-pair.h similarity index 52% rename from basic-geometry/tangent.h rename to basic-geometry/tangent-pair.h index 8e26e49..e2fd296 100644 --- a/basic-geometry/tangent.h +++ b/basic-geometry/tangent-pair.h @@ -1,5 +1,5 @@ -#ifndef _BGC_TANGENT_H_ -#define _BGC_TANGENT_H_ +#ifndef _bgc_tangent_pair_H_ +#define _bgc_tangent_pair_H_ #include @@ -13,41 +13,41 @@ typedef struct { const float cos, sin; -} BgcTangentFP32; +} BgcTangentPairFP32; typedef struct { const double cos, sin; -} BgcTangentFP64; +} BgcTangentPairFP64; // ================= Dark Twins ================= // typedef struct { float cos, sin; -} _BgcDarkTwinTangentFP32; +} _BgcTwinTangentPairFP32; typedef struct { double cos, sin; -} _BgcDarkTwinTangentFP64; +} _BgcTwinTangentPairFP64; // ================= Constants ================== // -extern const BgcTangentFP32 BGC_IDLE_TANGENT_FP32; -extern const BgcTangentFP64 BGC_IDLE_TANGENT_FP64; +extern const BgcTangentPairFP32 BGC_IDLE_TANGENT_PAIR_FP32; +extern const BgcTangentPairFP64 BGC_IDLE_TANGENT_PAIR_FP64; // =================== Reset ==================== // -inline void bgc_tangent_reset_fp32(BgcTangentFP32* tangent) +inline void bgc_tangent_pair_reset_fp32(BgcTangentPairFP32* tangent) { - _BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent; + _BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)tangent; twin->cos = 1.0f; twin->sin = 0.0f; } -inline void bgc_tangent_reset_fp64(BgcTangentFP64* tangent) +inline void bgc_tangent_pair_reset_fp64(BgcTangentPairFP64* tangent) { - _BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent; + _BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)tangent; twin->cos = 1.0; twin->sin = 0.0; @@ -55,51 +55,51 @@ inline void bgc_tangent_reset_fp64(BgcTangentFP64* tangent) // ==================== Set ===================== // -void _bgc_tangent_normalize_fp32(const float square_modulus, _BgcDarkTwinTangentFP32* twin); +void _bgc_tangent_pair_normalize_fp32(const float square_modulus, _BgcTwinTangentPairFP32* twin); -void _bgc_tangent_normalize_fp64(const double square_modulus, _BgcDarkTwinTangentFP64* twin); +void _bgc_tangent_pair_normalize_fp64(const double square_modulus, _BgcTwinTangentPairFP64* twin); -inline void bgc_tangent_set_values_fp32(const float x1, const float x2, BgcTangentFP32* tangent) +inline void bgc_tangent_pair_set_values_fp32(const float x1, const float x2, BgcTangentPairFP32* tangent) { const float square_modulus = x1 * x1 + x2 * x2; - _BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent; + _BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)tangent; twin->cos = x1; twin->sin = x2; if (!bgc_is_sqare_value_unit_fp32(square_modulus)) { - _bgc_tangent_normalize_fp32(square_modulus, twin); + _bgc_tangent_pair_normalize_fp32(square_modulus, twin); } } -inline void bgc_tangent_set_values_fp64(const double x1, const double x2, BgcTangentFP64* tangent) +inline void bgc_tangent_pair_set_values_fp64(const double x1, const double x2, BgcTangentPairFP64* tangent) { const double square_modulus = x1 * x1 + x2 * x2; - _BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent; + _BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)tangent; twin->cos = x1; twin->sin = x2; if (!bgc_is_sqare_value_unit_fp64(square_modulus)) { - _bgc_tangent_normalize_fp64(square_modulus, twin); + _bgc_tangent_pair_normalize_fp64(square_modulus, twin); } } // ==================== Copy ==================== // -inline void bgc_tangent_copy_fp32(const BgcTangentFP32* from, BgcTangentFP32* to) +inline void bgc_tangent_pair_copy_fp32(const BgcTangentPairFP32* from, BgcTangentPairFP32* to) { - _BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)to; + _BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)to; twin->cos = from->cos; twin->sin = from->sin; } -inline void bgc_tangent_copy_fp64(const BgcTangentFP64* from, BgcTangentFP64* to) +inline void bgc_tangent_pair_copy_fp64(const BgcTangentPairFP64* from, BgcTangentPairFP64* to) { - _BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)to; + _BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)to; twin->cos = from->cos; twin->sin = from->sin; @@ -107,33 +107,33 @@ inline void bgc_tangent_copy_fp64(const BgcTangentFP64* from, BgcTangentFP64* to // ==================== Swap ==================== // -inline void bgc_tangent_swap_fp32(BgcTangentFP32* tangent1, BgcTangentFP32* tangent2) +inline void bgc_tangent_pair_swap_fp32(BgcTangentPairFP32* tangent1, BgcTangentPairFP32* tangent2) { const float cos = tangent1->cos; const float sin = tangent1->sin; - _BgcDarkTwinTangentFP32* twin1 = (_BgcDarkTwinTangentFP32*)tangent1; + _BgcTwinTangentPairFP32* twin1 = (_BgcTwinTangentPairFP32*)tangent1; twin1->cos = tangent2->cos; twin1->sin = tangent2->sin; - _BgcDarkTwinTangentFP32* twin2 = (_BgcDarkTwinTangentFP32*)tangent2; + _BgcTwinTangentPairFP32* twin2 = (_BgcTwinTangentPairFP32*)tangent2; twin2->cos = cos; twin2->sin = sin; } -inline void bgc_tangent_swap_fp64(BgcTangentFP64* tangent1, BgcTangentFP64* tangent2) +inline void bgc_tangent_pair_swap_fp64(BgcTangentPairFP64* tangent1, BgcTangentPairFP64* tangent2) { const double cos = tangent1->cos; const double sin = tangent1->sin; - _BgcDarkTwinTangentFP64* twin1 = (_BgcDarkTwinTangentFP64*)tangent1; + _BgcTwinTangentPairFP64* twin1 = (_BgcTwinTangentPairFP64*)tangent1; twin1->cos = tangent2->cos; twin1->sin = tangent2->sin; - _BgcDarkTwinTangentFP64* twin2 = (_BgcDarkTwinTangentFP64*)tangent2; + _BgcTwinTangentPairFP64* twin2 = (_BgcTwinTangentPairFP64*)tangent2; twin2->cos = cos; twin2->sin = sin; @@ -141,21 +141,21 @@ inline void bgc_tangent_swap_fp64(BgcTangentFP64* tangent1, BgcTangentFP64* tang // ================== Set Turn ================== // -inline void bgc_tangent_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentFP32* tangent) +inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent) { const float radians = bgc_angle_to_radians_fp32(angle, unit); - _BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent; + _BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)tangent; twin->cos = cosf(radians); twin->sin = sinf(radians); } -inline void bgc_tangent_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentFP64* tangent) +inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent) { const double radians = bgc_angle_to_radians_fp64(angle, unit); - _BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent; + _BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)tangent; twin->cos = cos(radians); twin->sin = sin(radians); @@ -163,41 +163,41 @@ inline void bgc_tangent_set_turn_fp64(const double angle, const BgcAngleUnitEnum // ============= Copy to twin type ============== // -inline void bgc_tangent_convert_fp64_to_fp32(const BgcTangentFP64* from, BgcTangentFP32* to) +inline void bgc_tangent_pair_convert_fp64_to_fp32(const BgcTangentPairFP64* from, BgcTangentPairFP32* to) { - bgc_tangent_set_values_fp32((float)from->cos, (float)from->sin, to); + bgc_tangent_pair_set_values_fp32((float)from->cos, (float)from->sin, to); } -inline void bgc_tangent_convert_fp32_to_fp64(const BgcTangentFP32* from, BgcTangentFP64* to) +inline void bgc_tangent_pair_convert_fp32_to_fp64(const BgcTangentPairFP32* from, BgcTangentPairFP64* to) { - bgc_tangent_set_values_fp64((double)from->cos, (double)from->sin, to); + bgc_tangent_pair_set_values_fp64((double)from->cos, (double)from->sin, to); } // ================= Inversion ================== // -inline void bgc_tangent_invert_fp32(BgcTangentFP32* tangent) +inline void bgc_tangent_pair_invert_fp32(BgcTangentPairFP32* tangent) { - ((_BgcDarkTwinTangentFP32*)tangent)->sin = -tangent->sin; + ((_BgcTwinTangentPairFP32*)tangent)->sin = -tangent->sin; } -inline void bgc_tangent_invert_fp64(BgcTangentFP64* tangent) +inline void bgc_tangent_pair_invert_fp64(BgcTangentPairFP64* tangent) { - ((_BgcDarkTwinTangentFP64*)tangent)->sin = -tangent->sin; + ((_BgcTwinTangentPairFP64*)tangent)->sin = -tangent->sin; } // ================ Set Inverted ================ // -inline void bgc_tangent_set_inverted_fp32(const BgcTangentFP32* tangent, BgcTangentFP32* result) +inline void bgc_tangent_pair_set_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result) { - _BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)result; + _BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)result; twin->cos = tangent->cos; twin->sin = -tangent->sin; } -inline void bgc_tangent_set_inverted_fp64(const BgcTangentFP64* tangent, BgcTangentFP64* result) +inline void bgc_tangent_pair_set_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result) { - _BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)result; + _BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)result; twin->cos = tangent->cos; twin->sin = -tangent->sin; @@ -205,7 +205,7 @@ inline void bgc_tangent_set_inverted_fp64(const BgcTangentFP64* tangent, BgcTang // ============== Rotation Matrix =============== // -inline void bgc_tangent_make_rotation_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix) +inline void bgc_tangent_pair_make_rotation_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = -tangent->sin; @@ -213,7 +213,7 @@ inline void bgc_tangent_make_rotation_matrix_fp32(const BgcTangentFP32* tangent, matrix->r2c2 = tangent->cos; } -inline void bgc_tangent_make_rotation_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix) +inline void bgc_tangent_pair_make_rotation_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = -tangent->sin; @@ -223,7 +223,7 @@ inline void bgc_tangent_make_rotation_matrix_fp64(const BgcTangentFP64* tangent, // ============== Reverse Matrix ================ // -inline void bgc_tangent_make_reverse_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix) +inline void bgc_tangent_pair_make_reverse_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = tangent->sin; @@ -231,7 +231,7 @@ inline void bgc_tangent_make_reverse_matrix_fp32(const BgcTangentFP32* tangent, matrix->r2c2 = tangent->cos; } -inline void bgc_tangent_make_reverse_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix) +inline void bgc_tangent_pair_make_reverse_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix) { matrix->r1c1 = tangent->cos; matrix->r1c2 = tangent->sin; @@ -241,7 +241,7 @@ inline void bgc_tangent_make_reverse_matrix_fp64(const BgcTangentFP64* tangent, // =================== Angle =================== // -inline float bgc_tangent_get_angle_fp32(const BgcTangentFP32* tangent, const BgcAngleUnitEnum unit) +inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit) { if (tangent->cos >= 1.0f - BGC_EPSYLON_FP32) { return 0.0f; @@ -262,7 +262,7 @@ inline float bgc_tangent_get_angle_fp32(const BgcTangentFP32* tangent, const Bgc return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit); } -inline double bgc_tangent_get_angle_fp64(const BgcTangentFP64* tangent, const BgcAngleUnitEnum unit) +inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit) { if (tangent->cos >= 1.0 - BGC_EPSYLON_FP64) { return 0.0; @@ -285,18 +285,18 @@ inline double bgc_tangent_get_angle_fp64(const BgcTangentFP64* tangent, const Bg // ================ Combination ================= // -inline void bgc_tangent_combine_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2, BgcTangentFP32* result) +inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result) { - bgc_tangent_set_values_fp32( + bgc_tangent_pair_set_values_fp32( tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin, tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos, result ); } -inline void bgc_tangent_combine_fp64(const BgcTangentFP64* tangent1, const BgcTangentFP64* tangent2, BgcTangentFP64* result) +inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result) { - bgc_tangent_set_values_fp64( + bgc_tangent_pair_set_values_fp64( tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin, tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos, result @@ -305,7 +305,7 @@ inline void bgc_tangent_combine_fp64(const BgcTangentFP64* tangent1, const BgcTa // ================ Turn Vector ================= // -inline void bgc_tangent_turn_vector_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result) +inline void bgc_tangent_pair_turn_vector_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result) { const float x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2; const float x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2; @@ -314,7 +314,7 @@ inline void bgc_tangent_turn_vector_fp32(const BgcTangentFP32* tangent, const Bg result->x2 = x2; } -inline void bgc_tangent_turn_vector_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result) +inline void bgc_tangent_pair_turn_vector_fp64(const BgcTangentPairFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result) { const double x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2; const double x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2; @@ -325,7 +325,7 @@ inline void bgc_tangent_turn_vector_fp64(const BgcTangentFP64* tangent, const Bg // ============ Turn Vector Backward ============ // -inline void bgc_tangent_turn_vector_back_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result) +inline void bgc_tangent_pair_turn_vector_back_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result) { const float x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1; const float x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1; @@ -334,7 +334,7 @@ inline void bgc_tangent_turn_vector_back_fp32(const BgcTangentFP32* tangent, con result->x2 = x2; } -inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result) +inline void bgc_tangent_pair_turn_vector_back_fp64(const BgcTangentPairFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result) { const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1; const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1; @@ -345,7 +345,7 @@ inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, con // ================== Are Close ================= // -inline int bgc_tangent_are_close_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2) +inline int bgc_tangent_pair_are_close_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2) { const float d_cos = tangent1->cos - tangent2->cos; const float d_sin = tangent1->sin - tangent2->sin; @@ -353,7 +353,7 @@ inline int bgc_tangent_are_close_fp32(const BgcTangentFP32* tangent1, const BgcT return d_cos * d_cos + d_sin * d_sin <= BGC_SQUARE_EPSYLON_FP32; } -inline int bgc_tangent_are_close_fp64(const BgcTangentFP64* tangent1, const BgcTangentFP64* tangent2) +inline int bgc_tangent_pair_are_close_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2) { const double d_cos = tangent1->cos - tangent2->cos; const double d_sin = tangent1->sin - tangent2->sin; diff --git a/basic-geometry/tangent.c b/basic-geometry/tangent.c deleted file mode 100644 index ee74ca1..0000000 --- a/basic-geometry/tangent.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "tangent.h" - -const BgcTangentFP32 BGC_IDLE_TANGENT_FP32 = { 1.0f, 0.0f }; - -const BgcTangentFP64 BGC_IDLE_TANGENT_FP64 = { 1.0, 0.0 }; - -extern inline void bgc_tangent_reset_fp32(BgcTangentFP32* tangent); -extern inline void bgc_tangent_reset_fp64(BgcTangentFP64* tangent); - -extern inline void bgc_tangent_set_values_fp32(const float x1, const float x2, BgcTangentFP32* tangent); -extern inline void bgc_tangent_set_values_fp64(const double x1, const double x2, BgcTangentFP64* tangent); - -extern inline void bgc_tangent_copy_fp32(const BgcTangentFP32* from, BgcTangentFP32* to); -extern inline void bgc_tangent_copy_fp64(const BgcTangentFP64* from, BgcTangentFP64* to); - -extern inline void bgc_tangent_swap_fp32(BgcTangentFP32* tangent1, BgcTangentFP32* tangent2); -extern inline void bgc_tangent_swap_fp64(BgcTangentFP64* tangent1, BgcTangentFP64* tangent2); - -extern inline void bgc_tangent_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentFP32* tangent); -extern inline void bgc_tangent_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentFP64* tangent); - -extern inline void bgc_tangent_convert_fp64_to_fp32(const BgcTangentFP64* from, BgcTangentFP32* to); -extern inline void bgc_tangent_convert_fp32_to_fp64(const BgcTangentFP32* from, BgcTangentFP64* to); - -extern inline void bgc_tangent_invert_fp32(BgcTangentFP32* tangent); -extern inline void bgc_tangent_invert_fp64(BgcTangentFP64* tangent); - -extern inline void bgc_tangent_set_inverted_fp32(const BgcTangentFP32* tangent, BgcTangentFP32* result); -extern inline void bgc_tangent_set_inverted_fp64(const BgcTangentFP64* tangent, BgcTangentFP64* result); - -extern inline void bgc_tangent_make_rotation_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix); -extern inline void bgc_tangent_make_rotation_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix); - -extern inline void bgc_tangent_make_reverse_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix); -extern inline void bgc_tangent_make_reverse_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix); - -extern inline float bgc_tangent_get_angle_fp32(const BgcTangentFP32* tangent, const BgcAngleUnitEnum unit); -extern inline double bgc_tangent_get_angle_fp64(const BgcTangentFP64* tangent, const BgcAngleUnitEnum unit); - -extern inline void bgc_tangent_combine_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2, BgcTangentFP32* result); -extern inline void bgc_tangent_combine_fp64(const BgcTangentFP64* tangent1, const BgcTangentFP64* tangent2, BgcTangentFP64* result); - -extern inline void bgc_tangent_turn_vector_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result); -extern inline void bgc_tangent_turn_vector_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result); - -extern inline void bgc_tangent_turn_vector_back_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result); -extern inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result); - -extern inline int bgc_tangent_are_close_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2); -extern inline int bgc_tangent_are_close_fp64(const BgcTangentFP64* tangent1, const BgcTangentFP64* tangent2); - -void _bgc_tangent_normalize_fp32(const float square_modulus, _BgcDarkTwinTangentFP32* twin) -{ - // (square_modulus != square_modulus) is true when square_modulus is NaN - - if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) { - twin->cos = 1.0f; - twin->sin = 0.0f; - return; - } - - const float multiplier = sqrtf(1.0f / square_modulus); - - twin->cos *= multiplier; - twin->sin *= multiplier; -} - -void _bgc_tangent_normalize_fp64(const double square_modulus, _BgcDarkTwinTangentFP64* twin) -{ - // (square_modulus != square_modulus) is true when square_modulus is NaN - - if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) { - twin->cos = 1.0; - twin->sin = 0.0; - return; - } - - const double multiplier = sqrt(1.0 / square_modulus); - - twin->cos *= multiplier; - twin->sin *= multiplier; -} diff --git a/docs/angle-eng.md b/docs/angle-eng.md index a19e3de..9408f88 100644 --- a/docs/angle-eng.md +++ b/docs/angle-eng.md @@ -51,5 +51,4 @@ The ranges of angles are defined with an enumerated type: * BGC_ANGLE_RANGE_UNSIGNED is for the unsigned range of values; * BGC_ANGLE_RANGE_SIGNED is for the signed range of values. - [Documentation](intro-eng.md) diff --git a/docs/intro-eng.md b/docs/intro-eng.md index 5ff1441..2f06186 100644 --- a/docs/intro-eng.md +++ b/docs/intro-eng.md @@ -51,8 +51,9 @@ the type suffix: bgc_vector3_reset_fp64, bgc_radians_normalize_fp64. ## Entities +- [Angles](angle-eng.md) - [Vectors 2D](vector2-eng.md) -- Vectors 3D +- [Vectors 3D](vector3-eng.md) - [Quaternions](quaternion-eng.md) - [Versors](versor-eng.md) diff --git a/docs/intro-rus.md b/docs/intro-rus.md index 48b463f..6a6b3f2 100644 --- a/docs/intro-rus.md +++ b/docs/intro-rus.md @@ -52,7 +52,8 @@ bgc_vector3_reset_fp64, bgc_radians_normalize_fp64. ## Сущности +- [Углы](angle-rus.md) - [2D векторы](vector2-rus.md) -- 3D векторы +- [3D векторы](vector2-rus.md) - [Кватернионы](quaternion-rus.md) - [Версоры](versor-rus.md) diff --git a/docs/vector3/copy-eng.md b/docs/vector3/copy-eng.md index fceb461..1288609 100644 --- a/docs/vector3/copy-eng.md +++ b/docs/vector3/copy-eng.md @@ -48,4 +48,4 @@ int main() } ``` -[Documentation](../intro-eng.md) / [2D vectors](../vector3-eng.md) +[Documentation](../intro-eng.md) / [3D vectors](../vector3-eng.md) diff --git a/docs/vector3/copy-rus.md b/docs/vector3/copy-rus.md index c473264..c9891d1 100644 --- a/docs/vector3/copy-rus.md +++ b/docs/vector3/copy-rus.md @@ -48,4 +48,4 @@ int main() } ``` -[](../intro-rus.md) / [2D ](../vector3-rus.md) +[](../intro-rus.md) / [3D ](../vector3-rus.md) diff --git a/docs/vector3/reset-eng.md b/docs/vector3/reset-eng.md index dee9b0d..bf9242f 100644 --- a/docs/vector3/reset-eng.md +++ b/docs/vector3/reset-eng.md @@ -1,6 +1,6 @@ -# Resetting the state of a 2D vector +# Resetting the state of a 3D vector -These functions set all coordinates of 2D vectors to 0. +These functions set all coordinates of 3D vectors to 0. Function for **BgcVector3FP32**: @@ -42,4 +42,4 @@ int main() } ``` -[Documentation](../intro-eng.md) / [2D vectors](../vector3-eng.md) +[Documentation](../intro-eng.md) / [3D vectors](../vector3-eng.md) diff --git a/docs/vector3/reset-rus.md b/docs/vector3/reset-rus.md index 24c9543..952a267 100644 --- a/docs/vector3/reset-rus.md +++ b/docs/vector3/reset-rus.md @@ -42,4 +42,4 @@ int main() } ``` -[](../intro-rus.md) / [2D ](../vector3-rus.md) +[](../intro-rus.md) / [3D ](../vector3-rus.md) diff --git a/docs/vector3/set-values-eng.md b/docs/vector3/set-values-eng.md index 5102ecb..4613173 100644 --- a/docs/vector3/set-values-eng.md +++ b/docs/vector3/set-values-eng.md @@ -42,4 +42,4 @@ int main() } ``` -[Documentation](../intro-eng.md) / [2D vectors](../vector3-eng.md) +[Documentation](../intro-eng.md) / [3D vectors](../vector3-eng.md) diff --git a/docs/vector3/set-values-rus.md b/docs/vector3/set-values-rus.md index ae04ec9..eb803f8 100644 --- a/docs/vector3/set-values-rus.md +++ b/docs/vector3/set-values-rus.md @@ -42,4 +42,4 @@ int main() } ``` -[](../intro-rus.md) / [2D ](../vector3-rus.md) +[](../intro-rus.md) / [3D ](../vector3-rus.md) diff --git a/docs/vector3/swap-eng.md b/docs/vector3/swap-eng.md index 0adb099..ed60184 100644 --- a/docs/vector3/swap-eng.md +++ b/docs/vector3/swap-eng.md @@ -49,4 +49,4 @@ Vector #1: x1 = 10.000000, x2 = -1.000000, x3 = -3.000000 Vector #2: x1 = -2.000000, x2 = 7.000000, x3 = 5.000000 ``` -[Documentation](../intro-eng.md) / [2D vectors](../vector3-eng.md) +[Documentation](../intro-eng.md) / [3D vectors](../vector3-eng.md) diff --git a/docs/vector3/swap-rus.md b/docs/vector3/swap-rus.md index e458d18..a95c2e4 100644 --- a/docs/vector3/swap-rus.md +++ b/docs/vector3/swap-rus.md @@ -49,4 +49,4 @@ Vector #1: x1 = 10.000000, x2 = -1.000000, x3 = -3.000000 Vector #2: x1 = -2.000000, x2 = 7.000000, x3 = 5.000000 ``` -[Документация](../intro-rus.md) / [2D векторы](../vector3-rus.md) +[Документация](../intro-rus.md) / [3D векторы](../vector3-rus.md)