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

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

@ -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));
}
// ================== 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_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) {
return square_modulus3 < (2.0f * BGC_SQUARE_EPSYLON_FP32);
if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
return square_distance <= BGC_SQUARE_EPSYLON_FP32;
}
if (square_modulus1 <= square_modulus2) {
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2;
}
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1;
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
}
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_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) {
return square_modulus3 < (2.0 * BGC_SQUARE_EPSYLON_FP64);
if (square_modulus1 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 <= BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
}
if (square_modulus1 <= square_modulus2) {
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2;
}
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1;
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
}
#endif