Исправление существовавших и добавление новых функций сравнения
This commit is contained in:
parent
847c022533
commit
421ca77cb4
15 changed files with 174 additions and 74 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Basic Geometry
|
||||
# Basic Geometry Computations
|
||||
|
||||
## Библиотека базовых геометрических вычислений
|
||||
## Библиотека базовых геометрических вычислений для Си
|
||||
|
||||
(English: library of basic geometric computations)
|
||||
|
||||
|
|
@ -36,5 +36,5 @@
|
|||
типа **float**, а другая - для данных типа **double**. Но между этими половинами
|
||||
есть мостики - функции преобразования типа.
|
||||
|
||||
Однако в библиотеке нет функций, которые используют для вычисления данные разных
|
||||
типов (**float** и *double* одновременно).
|
||||
Однако в библиотеке мало функций, которые используют для вычисления данные разных
|
||||
типов (**float** и **double** одновременно).
|
||||
|
|
@ -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_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);
|
||||
|
|
|
|||
|
|
@ -535,4 +535,42 @@ inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const
|
|||
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_
|
||||
|
|
|
|||
|
|
@ -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_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
|
||||
|
|
|
|||
|
|
@ -343,4 +343,22 @@ inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, con
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||