Исправление существовавших и добавление новых функций сравнения

This commit is contained in:
Andrey Pokidov 2025-02-05 23:43:02 +07:00
parent 847c022533
commit 421ca77cb4
15 changed files with 174 additions and 74 deletions

View file

@ -1,6 +1,6 @@
# Basic Geometry # Basic Geometry Computations
## Library of basic geometric computations ## Library of basic geometric computations for C
[Версия на русском языке / Russian version](./README.md) [Версия на русском языке / Russian version](./README.md)

View file

@ -1,6 +1,6 @@
# Basic Geometry # Basic Geometry Computations
## Библиотека базовых геометрических вычислений ## Библиотека базовых геометрических вычислений для Си
(English: library of basic geometric computations) (English: library of basic geometric computations)
@ -36,5 +36,5 @@
типа **float**, а другая - для данных типа **double**. Но между этими половинами типа **float**, а другая - для данных типа **double**. Но между этими половинами
есть мостики - функции преобразования типа. есть мостики - функции преобразования типа.
Однако в библиотеке нет функций, которые используют для вычисления данные разных Однако в библиотеке мало функций, которые используют для вычисления данные разных
типов (**float** и *double* одновременно). типов (**float** и **double** одновременно).

View file

@ -59,3 +59,6 @@ extern inline void bgc_quaternion_divide_fp64(const BgcQuaternionFP64* dividend,
extern inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product); extern inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product);
extern inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product); extern inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product);
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);

View file

@ -535,4 +535,42 @@ inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const
product->x3 = x3; product->x3 = x3;
} }
// ================== Are Close ================= //
inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2)
{
const float ds0 = quaternion1->s0 - quaternion2->s0;
const float dx1 = quaternion1->x1 - quaternion2->x1;
const float dx2 = quaternion1->x2 - quaternion2->x2;
const float dx3 = quaternion1->x3 - quaternion2->x3;
const float square_modulus1 = bgc_quaternion_get_square_modulus_fp32(quaternion1);
const float square_modulus2 = bgc_quaternion_get_square_modulus_fp32(quaternion2);
const float square_distance = (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3);
if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
return square_distance <= BGC_SQUARE_EPSYLON_FP32;
}
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
}
inline int bgc_quaternion_are_close_fp64(const BgcQuaternionFP64* quaternion1, const BgcQuaternionFP64* quaternion2)
{
const double ds0 = quaternion1->s0 - quaternion2->s0;
const double dx1 = quaternion1->x1 - quaternion2->x1;
const double dx2 = quaternion1->x2 - quaternion2->x2;
const double dx3 = quaternion1->x3 - quaternion2->x3;
const double square_modulus1 = bgc_quaternion_get_square_modulus_fp64(quaternion1);
const double square_modulus2 = bgc_quaternion_get_square_modulus_fp64(quaternion2);
const double square_distance = (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3);
if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
}
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
}
#endif // _BGC_QUATERNION_H_ #endif // _BGC_QUATERNION_H_

View file

@ -46,6 +46,9 @@ extern inline void bgc_tangent_turn_vector_fp64(const BgcTangentFP64* tangent, c
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_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 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) void _bgc_tangent_normalize_fp32(const float square_modulus, _BgcDarkTwinTangentFP32* twin)
{ {
// (square_modulus != square_modulus) is true when square_modulus is NaN // (square_modulus != square_modulus) is true when square_modulus is NaN

View file

@ -343,4 +343,22 @@ inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, con
result->x2 = x2; result->x2 = x2;
} }
// ================== Are Close ================= //
inline int bgc_tangent_are_close_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2)
{
const float d_cos = tangent1->cos - tangent2->cos;
const float d_sin = tangent1->sin - tangent2->sin;
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)
{
const double d_cos = tangent1->cos - tangent2->cos;
const double d_sin = tangent1->sin - tangent2->sin;
return d_cos * d_cos + d_sin * d_sin <= BGC_SQUARE_EPSYLON_FP64;
}
#endif #endif

View file

@ -10,5 +10,5 @@ extern inline int bgc_is_unit_fp64(const double square_value);
extern inline int bgc_is_sqare_value_unit_fp32(const float square_value); extern inline int bgc_is_sqare_value_unit_fp32(const float square_value);
extern inline int bgc_is_sqare_value_unit_fp64(const double square_value); extern inline int bgc_is_sqare_value_unit_fp64(const double square_value);
extern inline int bgc_are_equal_fp32(const float value1, const float value2); extern inline int bgc_are_close_fp32(const float value1, const float value2);
extern inline int bgc_are_equal_fp64(const double value1, const double value2); extern inline int bgc_are_close_fp64(const double value1, const double value2);

View file

@ -1,7 +1,7 @@
#ifndef _BGC_UTILITIES_H_ #ifndef _BGC_UTILITIES_H_
#define _BGC_UTILITIES_H_ #define _BGC_UTILITIES_H_
#define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 10.0f #define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 1.0f
#define BGC_EPSYLON_FP32 5E-7f #define BGC_EPSYLON_FP32 5E-7f
#define BGC_SQUARE_EPSYLON_FP32 2.5E-13f #define BGC_SQUARE_EPSYLON_FP32 2.5E-13f
@ -13,7 +13,7 @@
#define BGC_GOLDEN_RATIO_HIGH_FP32 1.618034f #define BGC_GOLDEN_RATIO_HIGH_FP32 1.618034f
#define BGC_GOLDEN_RATIO_LOW_FP32 0.618034f #define BGC_GOLDEN_RATIO_LOW_FP32 0.618034f
#define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 10.0 #define BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 1.0
#define BGC_EPSYLON_FP64 5E-14 #define BGC_EPSYLON_FP64 5E-14
#define BGC_SQUARE_EPSYLON_FP64 2.5E-27 #define BGC_SQUARE_EPSYLON_FP64 2.5E-27
@ -57,31 +57,34 @@ inline int bgc_is_sqare_value_unit_fp64(const double square_value)
return (1.0 - 2.0 * BGC_EPSYLON_FP64 <= square_value) && (square_value <= 1.0 + 2.0 * BGC_EPSYLON_FP64); return (1.0 - 2.0 * BGC_EPSYLON_FP64 <= square_value) && (square_value <= 1.0 + 2.0 * BGC_EPSYLON_FP64);
} }
// ================== Are Close ================= //
inline int bgc_are_equal_fp32(const float value1, const float value2) inline int bgc_are_close_fp32(const float value1, const float value2)
{ {
if (-BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 < value1 && value1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { const float difference = value1 - value2;
return -BGC_EPSYLON_FP32 <= (value1 - value2) && (value1 - value2) <= BGC_EPSYLON_FP32; const float square_value1 = value1 * value1;
const float square_value2 = value2 * value2;
const float square_difference = difference * difference;
if (square_value1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_value2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
return square_difference <= BGC_SQUARE_EPSYLON_FP32;
} }
if (value1 < 0.0f) { return square_difference <= BGC_SQUARE_EPSYLON_FP32 * square_value1 && square_difference <= BGC_SQUARE_EPSYLON_FP32 * square_value2;
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) inline int bgc_are_close_fp64(const double value1, const double value2)
{ {
if (-BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 < value1 && value1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { const double difference = value1 - value2;
return -BGC_EPSYLON_FP64 <= (value1 - value2) && (value1 - value2) <= BGC_EPSYLON_FP64; const double square_value1 = value1 * value1;
const double square_value2 = value2 * value2;
const double square_difference = difference * difference;
if (square_value1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_value2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
return square_difference <= BGC_SQUARE_EPSYLON_FP64;
} }
if (value1 < 0.0) { return square_difference <= BGC_SQUARE_EPSYLON_FP64 * square_value1 && square_difference <= BGC_SQUARE_EPSYLON_FP64 * square_value2;
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 #endif

View file

@ -75,8 +75,11 @@ extern inline double bgc_vector2_get_square_distance_fp64(const BgcVector2FP64*
extern inline float bgc_vector2_get_distance_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2); extern inline float bgc_vector2_get_distance_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
extern inline double bgc_vector2_get_distance_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2); extern inline double bgc_vector2_get_distance_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
extern inline int bgc_vector2_are_equal_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2); extern inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance);
extern inline int bgc_vector2_are_equal_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2); extern inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance);
extern inline int bgc_vector2_are_close_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
extern inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
// =================== Angle ==================== // // =================== Angle ==================== //

View file

@ -396,42 +396,44 @@ inline double bgc_vector2_get_distance_fp64(const BgcVector2FP64* vector1, const
return sqrt(bgc_vector2_get_square_distance_fp64(vector1, vector2)); return sqrt(bgc_vector2_get_square_distance_fp64(vector1, vector2));
} }
// ================== Are Equal ================= // // ============== Are Close Enough ============== //
inline int bgc_vector2_are_equal_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2) inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance)
{
return bgc_vector2_get_square_distance_fp32(vector1, vector2) <= distance * distance;
}
inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance)
{
return bgc_vector2_get_square_distance_fp64(vector1, vector2) <= distance * distance;
}
// ================== Are Close ================= //
inline int bgc_vector2_are_close_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
{ {
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1); 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_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
const float square_modulus3 = bgc_vector2_get_square_distance_fp32(vector1, vector2); const float square_distance = bgc_vector2_get_square_distance_fp32(vector1, vector2);
// 2.0f means dimension amount if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { return square_distance <= BGC_SQUARE_EPSYLON_FP32;
return square_modulus3 < (2.0f * BGC_SQUARE_EPSYLON_FP32);
} }
if (square_modulus1 <= square_modulus2) { return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2;
}
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1;
} }
inline int bgc_vector2_are_equal_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2) inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
{ {
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1); 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_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
const double square_modulus3 = bgc_vector2_get_square_distance_fp64(vector1, vector2); const double square_distance = bgc_vector2_get_square_distance_fp64(vector1, vector2);
// 2.0 means dimension amount if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { return square_distance <= BGC_SQUARE_EPSYLON_FP64;
return square_modulus3 < (2.0 * BGC_SQUARE_EPSYLON_FP64);
} }
if (square_modulus1 <= square_modulus2) { return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2;
}
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1;
} }
#endif #endif

View file

@ -81,8 +81,11 @@ extern inline double bgc_vector3_get_square_distance_fp64(const BgcVector3FP64*
extern inline float bgc_vector3_get_distance_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2); extern inline float bgc_vector3_get_distance_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2);
extern inline double bgc_vector3_get_distance_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2); extern inline double bgc_vector3_get_distance_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2);
extern inline int bgc_vector3_are_equal_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2); extern inline int bgc_vector3_are_close_enough_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float distance);
extern inline int bgc_vector3_are_equal_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2); extern inline int bgc_vector3_are_close_enough_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double distance);
extern inline int bgc_vector3_are_close_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2);
extern inline int bgc_vector3_are_close_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2);
// =================== Angle ==================== // // =================== Angle ==================== //

View file

@ -476,42 +476,44 @@ inline double bgc_vector3_get_distance_fp64(const BgcVector3FP64* vector1, const
return sqrt(bgc_vector3_get_square_distance_fp64(vector1, vector2)); return sqrt(bgc_vector3_get_square_distance_fp64(vector1, vector2));
} }
// ================== Are Equal ================= // // ============== Are Close Enough ============== //
inline int bgc_vector3_are_equal_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2) inline int bgc_vector3_are_close_enough_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float distance)
{
return bgc_vector3_get_square_distance_fp32(vector1, vector2) <= distance * distance;
}
inline int bgc_vector3_are_close_enough_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double distance)
{
return bgc_vector3_get_square_distance_fp64(vector1, vector2) <= distance * distance;
}
// ================== Are Close ================= //
inline int bgc_vector3_are_close_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2)
{ {
const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1); 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_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2);
const float square_modulus3 = bgc_vector3_get_square_distance_fp32(vector1, vector2); const float square_distance = bgc_vector3_get_square_distance_fp32(vector1, vector2);
// 3.0f means dimension amount if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) { return square_distance <= BGC_SQUARE_EPSYLON_FP32;
return square_modulus3 < (3.0f * BGC_SQUARE_EPSYLON_FP32);
} }
if (square_modulus1 <= square_modulus2) { return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2;
}
return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1;
} }
inline int bgc_vector3_are_equal_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2) inline int bgc_vector3_are_close_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2)
{ {
const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1); 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_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2);
const double square_modulus3 = bgc_vector3_get_square_distance_fp64(vector1, vector2); const double square_distance = bgc_vector3_get_square_distance_fp64(vector1, vector2);
// 3.0 means dimension amount if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) { return square_distance <= BGC_SQUARE_EPSYLON_FP64;
return square_modulus3 < (3.0 * BGC_SQUARE_EPSYLON_FP64);
} }
if (square_modulus1 <= square_modulus2) { return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2;
}
return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1;
} }
#endif #endif

View file

@ -64,6 +64,9 @@ extern inline void bgc_versor_turn_vector_fp64(const BgcVersorFP64* versor, cons
extern inline void bgc_versor_turn_vector_back_fp32(const BgcVersorFP32* versor, const BgcVector3FP32* vector, BgcVector3FP32* result); extern inline void bgc_versor_turn_vector_back_fp32(const BgcVersorFP32* versor, const BgcVector3FP32* vector, BgcVector3FP32* result);
extern inline void bgc_versor_turn_vector_back_fp64(const BgcVersorFP64* versor, const BgcVector3FP64* vector, BgcVector3FP64* result); extern inline void bgc_versor_turn_vector_back_fp64(const BgcVersorFP64* versor, const BgcVector3FP64* vector, BgcVector3FP64* result);
extern inline int bgc_versor_are_close_fp32(const BgcVersorFP32* versor1, const BgcVersorFP32* versor2);
extern inline int bgc_versor_are_close_fp64(const BgcVersorFP64* versor1, const BgcVersorFP64* versor2);
// =============== Normalization ================ // // =============== Normalization ================ //
void _bgc_versor_normalize_fp32(const float square_modulus, _BgcDarkTwinVersorFP32* twin) void _bgc_versor_normalize_fp32(const float square_modulus, _BgcDarkTwinVersorFP32* twin)

View file

@ -600,4 +600,26 @@ inline void bgc_versor_turn_vector_back_fp64(const BgcVersorFP64* versor, const
result->x3 = x3; result->x3 = x3;
} }
// ================== Are Close ================= //
inline int bgc_versor_are_close_fp32(const BgcVersorFP32* versor1, const BgcVersorFP32* versor2)
{
const float ds0 = versor1->s0 - versor2->s0;
const float dx1 = versor1->x1 - versor2->x1;
const float dx2 = versor1->x2 - versor2->x2;
const float dx3 = versor1->x3 - versor2->x3;
return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_SQUARE_EPSYLON_FP32;
}
inline int bgc_versor_are_close_fp64(const BgcVersorFP64* versor1, const BgcVersorFP64* versor2)
{
const double ds0 = versor1->s0 - versor2->s0;
const double dx1 = versor1->x1 - versor2->x1;
const double dx2 = versor1->x2 - versor2->x2;
const double dx3 = versor1->x3 - versor2->x3;
return (ds0 * ds0 + dx1 * dx1) + (dx2 * dx2 + dx3 * dx3) <= BGC_SQUARE_EPSYLON_FP32;
}
#endif #endif

View file

@ -33,9 +33,9 @@ BgcVector3FP32, BgcMatrix3x2FP32, BgcQuaternionFP32
Типы структур, использующие тип **double** имеют суффикс **FP64**: Типы структур, использующие тип **double** имеют суффикс **FP64**:
BgcVector2FP64, BgcMatrix2x3FP64, BgcVersorFP64 BgcVector2FP64, BgcMatrix2x3FP64, BgcVersorFP64
Константы типа **float** имеют суффикс **FP32_**: BGC_PI_FP32, BGC_EPSYLON_FP32. Константы типа **float** имеют суффикс **_FP32**: BGC_PI_FP32, BGC_EPSYLON_FP32.
Константы типа **double** имеют суффикс **FP64_**: BGC_HALF_PI_FP64, Константы типа **double** имеют суффикс **_FP64**: BGC_HALF_PI_FP64,
BGC_ONE_THIRD_FP64. BGC_ONE_THIRD_FP64.
Функции, которые работают с данными типа **float** имеют суффикс **_fp32**: Функции, которые работают с данными типа **float** имеют суффикс **_fp32**: