Небольшие исправления, а также добавление гомогенного трёхмерного вектора

This commit is contained in:
Andrey Pokidov 2026-02-02 20:44:10 +07:00
parent 03627f4401
commit 043cc72c81
25 changed files with 1686 additions and 1644 deletions

View file

@ -1,10 +1,10 @@
#ifndef _BGC_UTILITIES_H_
#define _BGC_UTILITIES_H_
#define BGC_FP32_EPSYLON_EFFECTIVENESS_LIMIT 1.0f
#define BGC_FP32_EPSILON_EFFECTIVENESS_LIMIT 1.0f
#define BGC_FP32_EPSYLON 4.76837E-7f
#define BGC_FP32_SQUARE_EPSYLON (BGC_FP32_EPSYLON * BGC_FP32_EPSYLON)
#define BGC_FP32_EPSILON 4.76837E-7f
#define BGC_FP32_SQUARE_EPSILON (BGC_FP32_EPSILON * BGC_FP32_EPSILON)
#define BGC_FP32_ONE_THIRD 0.3333333333f
#define BGC_FP32_ONE_SIXTH 0.1666666667f
@ -14,10 +14,10 @@
#define BGC_FP32_GOLDEN_RATIO_HIGH 1.618034f
#define BGC_FP32_GOLDEN_RATIO_LOW 0.618034f
#define BGC_FP64_EPSYLON_EFFECTIVENESS_LIMIT 1.0
#define BGC_FP64_EPSILON_EFFECTIVENESS_LIMIT 1.0
#define BGC_FP64_EPSYLON 4.996003611E-14
#define BGC_FP64_SQUARE_EPSYLON (BGC_FP64_EPSYLON * BGC_FP64_EPSYLON)
#define BGC_FP64_EPSILON 4.996003611E-14
#define BGC_FP64_SQUARE_EPSILON (BGC_FP64_EPSILON * BGC_FP64_EPSILON)
#define BGC_FP64_ONE_THIRD 0.3333333333333333333
#define BGC_FP64_ONE_SIXTH 0.1666666666666666667
@ -53,34 +53,34 @@ inline int bgc_is_correct_axis(const int axis)
inline int bgc_fp32_is_zero(const float value)
{
return (-BGC_FP32_EPSYLON <= value) && (value <= BGC_FP32_EPSYLON);
return (-BGC_FP32_EPSILON <= value) && (value <= BGC_FP32_EPSILON);
}
inline int bgc_fp64_is_zero(const double value)
{
return (-BGC_FP64_EPSYLON <= value) && (value <= BGC_FP64_EPSYLON);
return (-BGC_FP64_EPSILON <= value) && (value <= BGC_FP64_EPSILON);
}
inline int bgc_fp32_is_unit(const float value)
{
return (1.0f - BGC_FP32_EPSYLON <= value) && (value <= 1.0f + BGC_FP32_EPSYLON);
return (1.0f - BGC_FP32_EPSILON <= value) && (value <= 1.0f + BGC_FP32_EPSILON);
}
inline int bgc_fp64_is_unit(const double value)
{
return (1.0 - BGC_FP64_EPSYLON <= value) && (value <= 1.0 + BGC_FP64_EPSYLON);
return (1.0 - BGC_FP64_EPSILON <= value) && (value <= 1.0 + BGC_FP64_EPSILON);
}
inline int bgc_fp32_is_square_unit(const float square_value)
{
return (1.0f - 2.0f * BGC_FP32_EPSYLON <= square_value) && (square_value <= 1.0f + 2.0f * BGC_FP32_EPSYLON);
return (1.0f - 2.0f * BGC_FP32_EPSILON <= square_value) && (square_value <= 1.0f + 2.0f * BGC_FP32_EPSILON);
}
inline int bgc_fp64_is_square_unit(const double square_value)
{
return (1.0 - 2.0 * BGC_FP64_EPSYLON <= square_value) && (square_value <= 1.0 + 2.0 * BGC_FP64_EPSYLON);
return (1.0 - 2.0 * BGC_FP64_EPSILON <= square_value) && (square_value <= 1.0 + 2.0 * BGC_FP64_EPSILON);
}
// ================== Are Close ================= //
@ -92,11 +92,11 @@ inline int bgc_fp32_are_close(const float value1, const float value2)
const float square_value2 = value2 * value2;
const float square_difference = difference * difference;
if (square_value1 <= BGC_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_value2 <= BGC_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_difference <= BGC_FP32_SQUARE_EPSYLON;
if (square_value1 <= BGC_FP32_EPSILON_EFFECTIVENESS_LIMIT || square_value2 <= BGC_FP32_EPSILON_EFFECTIVENESS_LIMIT) {
return square_difference <= BGC_FP32_SQUARE_EPSILON;
}
return square_difference <= BGC_FP32_SQUARE_EPSYLON * square_value1 && square_difference <= BGC_FP32_SQUARE_EPSYLON * square_value2;
return square_difference <= BGC_FP32_SQUARE_EPSILON * square_value1 && square_difference <= BGC_FP32_SQUARE_EPSILON * square_value2;
}
inline int bgc_fp64_are_close(const double value1, const double value2)
@ -106,11 +106,11 @@ inline int bgc_fp64_are_close(const double value1, const double value2)
const double square_value2 = value2 * value2;
const double square_difference = difference * difference;
if (square_value1 <= BGC_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_value2 <= BGC_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_difference <= BGC_FP64_SQUARE_EPSYLON;
if (square_value1 <= BGC_FP64_EPSILON_EFFECTIVENESS_LIMIT || square_value2 <= BGC_FP64_EPSILON_EFFECTIVENESS_LIMIT) {
return square_difference <= BGC_FP64_SQUARE_EPSILON;
}
return square_difference <= BGC_FP64_SQUARE_EPSYLON * square_value1 && square_difference <= BGC_FP64_SQUARE_EPSYLON * square_value2;
return square_difference <= BGC_FP64_SQUARE_EPSILON * square_value1 && square_difference <= BGC_FP64_SQUARE_EPSILON * square_value2;
}
#endif