Упорядочивание проекта

This commit is contained in:
Andrey Pokidov 2025-11-26 22:43:29 +07:00
parent 0dcd9c0d4d
commit 89dfd7644b
32 changed files with 1730 additions and 1719 deletions

View file

@ -44,62 +44,6 @@ inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVec
destination->x2 = x2;
}
// ================= Directions ================= //
inline int bgc_vector2_get_direction_fp32(const int direction, BgcVector2FP32* vector)
{
switch (direction) {
case BGC_DIRECTION_X1:
vector->x1 = 1.0f;
vector->x2 = 0.0f;
return 1;
case BGC_DIRECTION_X2:
vector->x1 = 0.0f;
vector->x2 = 1.0f;
return 1;
case -BGC_DIRECTION_X1:
vector->x1 = -1.0f;
vector->x2 = 0.0f;
return 1;
case -BGC_DIRECTION_X2:
vector->x1 = 0.0f;
vector->x2 = -1.0f;
return 1;
}
return 0;
}
inline int bgc_vector2_get_direction_fp64(const int direction, BgcVector2FP64* vector)
{
switch (direction) {
case BGC_DIRECTION_X1:
vector->x1 = 1.0;
vector->x2 = 0.0;
return 1;
case BGC_DIRECTION_X2:
vector->x1 = 0.0;
vector->x2 = 1.0;
return 1;
case -BGC_DIRECTION_X1:
vector->x1 = -1.0;
vector->x2 = 0.0;
return 1;
case -BGC_DIRECTION_X2:
vector->x1 = 0.0;
vector->x2 = -1.0;
return 1;
}
return 0;
}
// ================== Modulus =================== //
inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector)
@ -198,66 +142,6 @@ inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* source, BgcVe
destination->x2 = source->x2;
}
// ================== Reverse =================== //
inline void bgc_vector2_reverse_fp32(const BgcVector2FP32* vector, BgcVector2FP32* reverse)
{
reverse->x1 = -vector->x1;
reverse->x2 = -vector->x2;
}
inline void bgc_vector2_reverse_fp64(const BgcVector2FP64* vector, BgcVector2FP64* reverse)
{
reverse->x1 = -vector->x1;
reverse->x2 = -vector->x2;
}
// ================= Normalize ================== //
inline int bgc_vector2_normalize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized)
{
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
if (bgc_is_sqare_unit_fp32(square_modulus)) {
normalized->x1 = vector->x1;
normalized->x2 = vector->x2;
return 1;
}
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
return 0;
}
const float multiplicand = sqrtf(1.0f / square_modulus);
normalized->x1 = vector->x1 * multiplicand;
normalized->x2 = vector->x2 * multiplicand;
return 1;
}
inline int bgc_vector2_normalize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized)
{
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
if (bgc_is_sqare_unit_fp64(square_modulus)) {
normalized->x1 = vector->x1;
normalized->x2 = vector->x2;
return 1;
}
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
return 0;
}
const double multiplicand = sqrt(1.0 / square_modulus);
normalized->x1 = vector->x1 * multiplicand;
normalized->x2 = vector->x2 * multiplicand;
return 1;
}
// ==================== Add ===================== //
inline void bgc_vector2_add_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* sum)
@ -300,20 +184,6 @@ inline void bgc_vector2_subtract_fp64(const BgcVector2FP64* minuend, const BgcVe
difference->x2 = minuend->x2 - subtrahend->x2;
}
// ============== Subtract scaled =============== //
inline void bgc_vector2_subtract_scaled_fp32(const BgcVector2FP32* basic_vector, const BgcVector2FP32* scalable_vector, const float scale, BgcVector2FP32* difference)
{
difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale;
difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale;
}
inline void bgc_vector2_subtract_scaled_fp64(const BgcVector2FP64* basic_vector, const BgcVector2FP64* scalable_vector, const double scale, BgcVector2FP64* difference)
{
difference->x1 = basic_vector->x1 - scalable_vector->x1 * scale;
difference->x2 = basic_vector->x2 - scalable_vector->x2 * scale;
}
// ================== Multiply ================== //
inline void bgc_vector2_multiply_fp32(const BgcVector2FP32* multiplicand, const float multiplier, BgcVector2FP32* product)
@ -340,7 +210,7 @@ inline void bgc_vector2_divide_fp64(const BgcVector2FP64* dividend, const double
bgc_vector2_multiply_fp64(dividend, 1.0 / divisor, quotient);
}
// ================== Average2 ================== //
// ================ Mean of Two ================= //
inline void bgc_vector2_get_mean_of_two_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* mean)
{
@ -354,7 +224,7 @@ inline void bgc_vector2_get_mean_of_two_fp64(const BgcVector2FP64* vector1, cons
mean->x2 = (vector1->x2 + vector2->x2) * 0.5;
}
// ================== Average3 ================== //
// =============== Mean of Three ================ //
inline void bgc_vector2_get_mean_of_three_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcVector2FP32* vector3, BgcVector2FP32* mean)
{
@ -370,7 +240,7 @@ inline void bgc_vector2_get_mean_of_three_fp64(const BgcVector2FP64* vector1, co
// =================== Linear =================== //
inline void bgc_vector2_interpolate_linearly_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation)
inline void bgc_vector2_interpolate_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float phase, BgcVector2FP32* interpolation)
{
const float counterphase = 1.0f - phase;
@ -378,7 +248,7 @@ inline void bgc_vector2_interpolate_linearly_fp32(const BgcVector2FP32* vector1,
interpolation->x2 = vector1->x2 * counterphase + vector2->x2 * phase;
}
inline void bgc_vector2_interpolate_linearly_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation)
inline void bgc_vector2_interpolate_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double phase, BgcVector2FP64* interpolation)
{
const double counterphase = 1.0 - phase;
@ -386,52 +256,108 @@ inline void bgc_vector2_interpolate_linearly_fp64(const BgcVector2FP64* vector1,
interpolation->x2 = vector1->x2 * counterphase + vector2->x2 * phase;
}
// ================== Minimal =================== //
// ================== Negative ================== //
inline void bgc_vector2_minimize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* minimal)
inline void bgc_vector2_make_opposite_fp32(BgcVector2FP32* vector)
{
if (vector->x1 < minimal->x1) {
minimal->x1 = vector->x1;
}
if (vector->x2 < minimal->x2) {
minimal->x2 = vector->x2;
}
vector->x1 = -vector->x1;
vector->x2 = -vector->x2;
}
inline void bgc_vector2_minimize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* minimal)
inline void bgc_vector2_make_opposite_fp64(BgcVector2FP64* vector)
{
if (vector->x1 < minimal->x1) {
minimal->x1 = vector->x1;
}
if (vector->x2 < minimal->x2) {
minimal->x2 = vector->x2;
}
vector->x1 = -vector->x1;
vector->x2 = -vector->x2;
}
// ================== Maximal =================== //
inline void bgc_vector2_maximize_fp32(const BgcVector2FP32* vector, BgcVector2FP32* maximal)
inline void bgc_vector2_get_opposite_fp32(const BgcVector2FP32* vector, BgcVector2FP32* opposite)
{
if (vector->x1 > maximal->x1) {
maximal->x1 = vector->x1;
}
if (vector->x2 > maximal->x2) {
maximal->x2 = vector->x2;
}
opposite->x1 = -vector->x1;
opposite->x2 = -vector->x2;
}
inline void bgc_vector2_maximize_fp64(const BgcVector2FP64* vector, BgcVector2FP64* maximal)
inline void bgc_vector2_get_opposite_fp64(const BgcVector2FP64* vector, BgcVector2FP64* opposite)
{
if (vector->x1 > maximal->x1) {
maximal->x1 = vector->x1;
opposite->x1 = -vector->x1;
opposite->x2 = -vector->x2;
}
// ================= Normalize ================== //
inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector)
{
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
if (bgc_is_sqare_unit_fp32(square_modulus)) {
return 1;
}
if (vector->x2 > maximal->x2) {
maximal->x2 = vector->x2;
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
return 0;
}
const float multiplier = sqrtf(1.0f / square_modulus);
vector->x1 *= multiplier;
vector->x2 *= multiplier;
return 1;
}
inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector)
{
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
if (bgc_is_sqare_unit_fp64(square_modulus)) {
return 1;
}
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
return 0;
}
const double multiplier = sqrt(1.0 / square_modulus);
vector->x1 *= multiplier;
vector->x2 *= multiplier;
return 1;
}
inline int bgc_vector2_get_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized)
{
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
if (bgc_is_sqare_unit_fp32(square_modulus)) {
bgc_vector2_copy_fp32(vector, normalized);
return 1;
}
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
bgc_vector2_reset_fp32(normalized);
return 0;
}
bgc_vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), normalized);
return 1;
}
inline int bgc_vector2_get_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized)
{
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
if (bgc_is_sqare_unit_fp64(square_modulus)) {
bgc_vector2_copy_fp64(vector, normalized);
return 1;
}
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
bgc_vector2_reset_fp64(normalized);
return 0;
}
bgc_vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), normalized);
return 1;
}
// ============= Get Scalar Product ============= //
@ -468,16 +394,16 @@ double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector
inline float bgc_vector2_get_square_distance_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
{
const float dx1 = (vector1->x1 - vector2->x1);
const float dx2 = (vector1->x2 - vector2->x2);
const float dx1 = vector1->x1 - vector2->x1;
const float dx2 = vector1->x2 - vector2->x2;
return dx1 * dx1 + dx2 * dx2;
}
inline double bgc_vector2_get_square_distance_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
{
const double dx1 = (vector1->x1 - vector2->x1);
const double dx2 = (vector1->x2 - vector2->x2);
const double dx1 = vector1->x1 - vector2->x1;
const double dx2 = vector1->x2 - vector2->x2;
return dx1 * dx1 + dx2 * dx2;
}
@ -496,14 +422,14 @@ inline double bgc_vector2_get_distance_fp64(const BgcVector2FP64* vector1, const
// ============== Are Close Enough ============== //
inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance)
inline int bgc_vector2_are_close_enough_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const float distance_limit)
{
return bgc_vector2_get_square_distance_fp32(vector1, vector2) <= distance * distance;
return bgc_vector2_get_square_distance_fp32(vector1, vector2) <= distance_limit * distance_limit;
}
inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance)
inline int bgc_vector2_are_close_enough_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const double distance_limit)
{
return bgc_vector2_get_square_distance_fp64(vector1, vector2) <= distance * distance;
return bgc_vector2_get_square_distance_fp64(vector1, vector2) <= distance_limit * distance_limit;
}
// ================== Are Close ================= //
@ -531,7 +457,143 @@ inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, const BgcVe
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
}
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
}
// ================== Parallel ================== //
inline int bgc_vector2_are_parallel_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
{
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
return 1;
}
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
return 1;
}
const float cross_product = bgc_vector2_get_cross_product_fp32(vector1, vector2);
return cross_product * cross_product <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
}
inline int bgc_vector2_are_parallel_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
{
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
return 1;
}
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
return 1;
}
const double cross_product = bgc_vector2_get_cross_product_fp64(vector1, vector2);
return cross_product * cross_product <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
}
// ================= Orthogonal ================= //
inline int bgc_vector2_are_orthogonal_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2)
{
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
return 1;
}
const float square_modulus2 = bgc_vector2_get_square_modulus_fp32(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
return 1;
}
const float scalar_product = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
}
inline int bgc_vector2_are_orthogonal_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2)
{
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
return 1;
}
const double square_modulus2 = bgc_vector2_get_square_modulus_fp64(vector2);
if (square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
return 1;
}
const double scalar_product = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
}
// ================== Attitude ================== //
inline int bgc_vector2_get_attitude_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);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
return BGC_ATTITUDE_ZERO;
}
const float square_limit = BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
const float scalar_product = bgc_vector2_get_scalar_product_fp32(vector1, vector2);
if (scalar_product * scalar_product <= square_limit) {
return BGC_ATTITUDE_ORTHOGONAL;
}
const float cross_product = bgc_vector2_get_cross_product_fp32(vector1, vector2);
if (cross_product * cross_product > square_limit) {
return BGC_ATTITUDE_ANY;
}
return scalar_product > 0.0f ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
}
inline int bgc_vector2_get_attitude_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);
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
return BGC_ATTITUDE_ZERO;
}
const double square_limit = BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
const double scalar_product = bgc_vector2_get_scalar_product_fp64(vector1, vector2);
if (scalar_product * scalar_product <= square_limit) {
return BGC_ATTITUDE_ORTHOGONAL;
}
const double cross_product = bgc_vector2_get_cross_product_fp64(vector1, vector2);
if (cross_product * cross_product > square_limit) {
return BGC_ATTITUDE_ANY;
}
return scalar_product > 0.0 ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
}
#endif