Завершение большого переименования
This commit is contained in:
parent
120e651517
commit
3805354611
31 changed files with 1213 additions and 1255 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _BASIC_GEOMETRY_VECTOR2_H_
|
||||
#define _BASIC_GEOMETRY_VECTOR2_H_
|
||||
#ifndef _BGC_VECTOR2_H_
|
||||
#define _BGC_VECTOR2_H_
|
||||
|
||||
#include "basis.h"
|
||||
#include "utilities.h"
|
||||
#include "angle.h"
|
||||
|
||||
#include <math.h>
|
||||
|
|
@ -9,22 +9,22 @@
|
|||
typedef struct
|
||||
{
|
||||
float x1, x2;
|
||||
} vector2_fp32_t;
|
||||
} bgc_vector2_fp32_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2;
|
||||
} vector2_fp64_t;
|
||||
} bgc_vector2_fp64_t;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void vector2_reset_fp32(vector2_fp32_t* vector)
|
||||
inline void bgc_vector2_reset_fp32(bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
}
|
||||
|
||||
inline void vector2_reset_fp64(vector2_fp64_t* vector)
|
||||
inline void bgc_vector2_reset_fp64(bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
|
|
@ -32,13 +32,13 @@ inline void vector2_reset_fp64(vector2_fp64_t* vector)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
inline void vector2_set_values_fp32(const float x1, const float x2, vector2_fp32_t* to)
|
||||
inline void bgc_vector2_set_values_fp32(const float x1, const float x2, bgc_vector2_fp32_t* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
}
|
||||
|
||||
inline void vector2_set_values_fp64(const double x1, const double x2, vector2_fp64_t* to)
|
||||
inline void bgc_vector2_set_values_fp64(const double x1, const double x2, bgc_vector2_fp64_t* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
|
|
@ -46,13 +46,13 @@ inline void vector2_set_values_fp64(const double x1, const double x2, vector2_fp
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void vector2_copy_fp32(const vector2_fp32_t* from, vector2_fp32_t* to)
|
||||
inline void bgc_vector2_copy_fp32(const bgc_vector2_fp32_t* from, bgc_vector2_fp32_t* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
inline void vector2_copy_fp64(const vector2_fp64_t* from, vector2_fp64_t* to)
|
||||
inline void bgc_vector2_copy_fp64(const bgc_vector2_fp64_t* from, bgc_vector2_fp64_t* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
|
@ -60,7 +60,7 @@ inline void vector2_copy_fp64(const vector2_fp64_t* from, vector2_fp64_t* to)
|
|||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void vector2_swap_fp32(vector2_fp32_t* vector1, vector2_fp32_t* vector2)
|
||||
inline void bgc_vector2_swap_fp32(bgc_vector2_fp32_t* vector1, bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
const float x1 = vector2->x1;
|
||||
const float x2 = vector2->x2;
|
||||
|
|
@ -72,7 +72,7 @@ inline void vector2_swap_fp32(vector2_fp32_t* vector1, vector2_fp32_t* vector2)
|
|||
vector1->x2 = x2;
|
||||
}
|
||||
|
||||
inline void vector2_swap_fp64(vector2_fp64_t* vector1, vector2_fp64_t* vector2)
|
||||
inline void bgc_vector2_swap_fp64(bgc_vector2_fp64_t* vector1, bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
const double x1 = vector2->x1;
|
||||
const double x2 = vector2->x2;
|
||||
|
|
@ -86,13 +86,13 @@ inline void vector2_swap_fp64(vector2_fp64_t* vector1, vector2_fp64_t* vector2)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
inline void vector2_convert_fp64_to_fp32(const vector2_fp64_t* from, vector2_fp32_t* to)
|
||||
inline void bgc_vector2_convert_fp64_to_fp32(const bgc_vector2_fp64_t* from, bgc_vector2_fp32_t* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
}
|
||||
|
||||
inline void vector2_convert_fp32_to_fp64(const vector2_fp32_t* from, vector2_fp64_t* to)
|
||||
inline void bgc_vector2_convert_fp32_to_fp64(const bgc_vector2_fp32_t* from, bgc_vector2_fp64_t* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
|
@ -100,13 +100,13 @@ inline void vector2_convert_fp32_to_fp64(const vector2_fp32_t* from, vector2_fp6
|
|||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
inline void vector2_fp32_set_reverse(const vector2_fp32_t* from, vector2_fp32_t* to)
|
||||
inline void bgc_vector2_set_reverse_fp32(const bgc_vector2_fp32_t* from, bgc_vector2_fp32_t* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
inline void vector2_fp64_set_reverse(const vector2_fp64_t* from, vector2_fp64_t* to)
|
||||
inline void bgc_vector2_set_reverse_fp64(const bgc_vector2_fp64_t* from, bgc_vector2_fp64_t* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
|
@ -114,13 +114,13 @@ inline void vector2_fp64_set_reverse(const vector2_fp64_t* from, vector2_fp64_t*
|
|||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
inline void vector2_fp32_set_reverse_fp64(const vector2_fp64_t* from, vector2_fp32_t* to)
|
||||
inline void bgc_vector2_set_reverse_fp64_to_fp32(const bgc_vector2_fp64_t* from, bgc_vector2_fp32_t* to)
|
||||
{
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
}
|
||||
|
||||
inline void vector2_fp64_set_reverse_fp32(const vector2_fp32_t* from, vector2_fp64_t* to)
|
||||
inline void bgc_vector2_set_reverse_fp32_to_fp64(const bgc_vector2_fp32_t* from, bgc_vector2_fp64_t* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
|
@ -128,75 +128,89 @@ inline void vector2_fp64_set_reverse_fp32(const vector2_fp32_t* from, vector2_fp
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
inline float vector2_get_square_modulus_fp32(const vector2_fp32_t* vector)
|
||||
inline float bgc_vector2_get_square_modulus_fp32(const bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline double vector2_get_square_modulus_fp64(const vector2_fp64_t* vector)
|
||||
inline double bgc_vector2_get_square_modulus_fp64(const bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline float vector2_get_modulus_fp32(const vector2_fp32_t* vector)
|
||||
inline float bgc_vector2_get_modulus_fp32(const bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
return sqrtf(vector2_get_square_modulus_fp32(vector));
|
||||
return sqrtf(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
inline double vector2_get_modulus_fp64(const vector2_fp64_t* vector)
|
||||
inline double bgc_vector2_get_modulus_fp64(const bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
return sqrt(vector2_get_square_modulus_fp64(vector));
|
||||
return sqrt(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
inline int vector2_fp32_is_zero(const vector2_fp32_t* vector)
|
||||
inline int bgc_vector2_is_zero_fp32(const bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
return vector2_get_square_modulus_fp32(vector) <= FP32_SQUARE_EPSYLON;
|
||||
return bgc_vector2_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int vector2_fp64_is_zero(const vector2_fp64_t* vector)
|
||||
inline int bgc_vector2_is_zero_fp64(const bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
return vector2_get_square_modulus_fp64(vector) <= FP64_SQUARE_EPSYLON;
|
||||
return bgc_vector2_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
inline int vector2_fp32_is_unit(const vector2_fp32_t* vector)
|
||||
inline int bgc_vector2_is_unit_fp32(const bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
const float square_modulus = vector2_get_square_modulus_fp32(vector);
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
return 1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON;
|
||||
return 1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int vector2_fp64_is_unit(const vector2_fp64_t* vector)
|
||||
inline int bgc_vector2_is_unit_fp64(const bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
const double square_modulus = vector2_get_square_modulus_fp64(vector);
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
return 1.0f - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP64_TWO_EPSYLON;
|
||||
return 1.0f - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void vector2_add_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* sum)
|
||||
inline void bgc_vector2_add_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* sum)
|
||||
{
|
||||
sum->x1 = vector1->x1 + vector2->x1;
|
||||
sum->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
inline void vector2_add_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* sum)
|
||||
inline void bgc_vector2_add_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* sum)
|
||||
{
|
||||
sum->x1 = vector1->x1 + vector2->x1;
|
||||
sum->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
inline void bgc_vector2_add_scaled_fp32(const bgc_vector2_fp32_t* basic_vector, const bgc_vector2_fp32_t* scalable_vector, const float scale, bgc_vector2_fp32_t* sum)
|
||||
{
|
||||
sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
||||
sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_add_scaled_fp64(const bgc_vector2_fp64_t* basic_vector, const bgc_vector2_fp64_t* scalable_vector, const double scale, bgc_vector2_fp64_t* sum)
|
||||
{
|
||||
sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
||||
sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
inline void vector2_subtract_fp32(const vector2_fp32_t* minuend, const vector2_fp32_t* subtrahend, vector2_fp32_t* difference)
|
||||
inline void bgc_vector2_subtract_fp32(const bgc_vector2_fp32_t* minuend, const bgc_vector2_fp32_t* subtrahend, bgc_vector2_fp32_t* difference)
|
||||
{
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
inline void vector2_subtract_fp64(const vector2_fp64_t* minuend, const vector2_fp64_t* subtrahend, vector2_fp64_t* difference)
|
||||
inline void bgc_vector2_subtract_fp64(const bgc_vector2_fp64_t* minuend, const bgc_vector2_fp64_t* subtrahend, bgc_vector2_fp64_t* difference)
|
||||
{
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
|
|
@ -204,13 +218,13 @@ inline void vector2_subtract_fp64(const vector2_fp64_t* minuend, const vector2_f
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
inline void vector2_multiply_fp32(const vector2_fp32_t* multiplicand, const float multiplier, vector2_fp32_t* product)
|
||||
inline void bgc_vector2_multiply_fp32(const bgc_vector2_fp32_t* multiplicand, const float multiplier, bgc_vector2_fp32_t* product)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
inline void vector2_multiply_fp64(const vector2_fp64_t* multiplicand, const double multiplier, vector2_fp64_t* product)
|
||||
inline void bgc_vector2_multiply_fp64(const bgc_vector2_fp64_t* multiplicand, const double multiplier, bgc_vector2_fp64_t* product)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
|
|
@ -218,39 +232,25 @@ inline void vector2_multiply_fp64(const vector2_fp64_t* multiplicand, const doub
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
inline void vector2_divide_fp32(const vector2_fp32_t* dividend, const float divisor, vector2_fp32_t* quotient)
|
||||
inline void bgc_vector2_divide_fp32(const bgc_vector2_fp32_t* dividend, const float divisor, bgc_vector2_fp32_t* quotient)
|
||||
{
|
||||
vector2_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
bgc_vector2_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void vector2_fp64_divide(const vector2_fp64_t* dividend, const double divisor, vector2_fp64_t* quotient)
|
||||
inline void bgc_vector2_divide_fp64(const bgc_vector2_fp64_t* dividend, const double divisor, bgc_vector2_fp64_t* quotient)
|
||||
{
|
||||
vector2_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
inline void vector2_add_scaled_fp32(vector2_fp32_t* basic_vector, const vector2_fp32_t* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
inline void vector2_add_scaled_fp64(vector2_fp64_t* basic_vector, const vector2_fp64_t* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
bgc_vector2_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
||||
inline void vector2_fp32_get_mean2(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* result)
|
||||
inline void bgc_vector2_mean_of_two_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
}
|
||||
|
||||
inline void vector2_fp64_get_mean2(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* result)
|
||||
inline void bgc_vector2_mean_of_two_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
|
|
@ -258,45 +258,45 @@ inline void vector2_fp64_get_mean2(const vector2_fp64_t* vector1, const vector2_
|
|||
|
||||
// ================== Average3 ================== //
|
||||
|
||||
inline void vector2_fp32_get_mean3(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, const vector2_fp32_t* vector3, vector2_fp32_t* result)
|
||||
inline void bgc_vector2_mean_of_three_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, const bgc_vector2_fp32_t* vector3, bgc_vector2_fp32_t* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP32_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP32_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32;
|
||||
}
|
||||
|
||||
inline void vector2_fp64_get_mean3(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, const vector2_fp64_t* vector3, vector2_fp64_t* result)
|
||||
inline void bgc_vector2_mean_of_three_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, const bgc_vector2_fp64_t* vector3, bgc_vector2_fp64_t* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP64_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP64_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
||||
inline float vector2_fp32_scalar_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2)
|
||||
inline float bgc_vector2_scalar_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
inline double vector2_fp64_scalar_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2)
|
||||
inline double bgc_vector2_scalar_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
// =============== Cross Product ================ //
|
||||
|
||||
inline float vector2_fp32_cross_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2)
|
||||
inline float bgc_vector2_cross_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
inline double vector2_fp64_cross_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2)
|
||||
inline double bgc_vector2_cross_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
// ============== Complex Product =============== //
|
||||
|
||||
inline void vector2_fp32_complex_product(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, vector2_fp32_t* result)
|
||||
inline void bgc_vector2_complex_product_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, bgc_vector2_fp32_t* result)
|
||||
{
|
||||
const float x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
||||
const float x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
||||
|
|
@ -305,7 +305,7 @@ inline void vector2_fp32_complex_product(const vector2_fp32_t* vector1, const ve
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
inline void vector2_fp64_complex_product(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, vector2_fp64_t* result)
|
||||
inline void bgc_vector2_complex_product_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, bgc_vector2_fp64_t* result)
|
||||
{
|
||||
const double x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
||||
const double x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
||||
|
|
@ -316,63 +316,63 @@ inline void vector2_fp64_complex_product(const vector2_fp64_t* vector1, const ve
|
|||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
inline int vector2_normalize_fp32(vector2_fp32_t* vector)
|
||||
inline int bgc_vector2_normalize_fp32(bgc_vector2_fp32_t* vector)
|
||||
{
|
||||
const float square_modulus = vector2_get_square_modulus_fp32(vector);
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||
if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||
vector2_reset_fp32(vector);
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
bgc_vector2_reset_fp32(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector);
|
||||
bgc_vector2_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int vector2_normalize_fp64(vector2_fp64_t* vector)
|
||||
inline int bgc_vector2_normalize_fp64(bgc_vector2_fp64_t* vector)
|
||||
{
|
||||
const double square_modulus = vector2_get_square_modulus_fp64(vector);
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||
if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= FP64_SQUARE_EPSYLON) {
|
||||
vector2_reset_fp64(vector);
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
bgc_vector2_reset_fp64(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector);
|
||||
bgc_vector2_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Get Normalized =============== //
|
||||
|
||||
inline int vector2_fp32_set_normalized(const vector2_fp32_t* vector, vector2_fp32_t* result)
|
||||
inline int bgc_vector2_set_normalized_fp32(const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result)
|
||||
{
|
||||
vector2_copy_fp32(vector, result);
|
||||
return vector2_normalize_fp32(result);
|
||||
bgc_vector2_copy_fp32(vector, result);
|
||||
return bgc_vector2_normalize_fp32(result);
|
||||
}
|
||||
|
||||
inline int vector2_fp64_set_normalized(const vector2_fp64_t* vector, vector2_fp64_t* result)
|
||||
inline int bgc_vector2_set_normalized_fp64(const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result)
|
||||
{
|
||||
vector2_copy_fp64(vector, result);
|
||||
return vector2_normalize_fp64(result);
|
||||
bgc_vector2_copy_fp64(vector, result);
|
||||
return bgc_vector2_normalize_fp64(result);
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float vector2_get_angle_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2, const angle_unit_t unit);
|
||||
float bgc_vector2_get_angle_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2, const bgc_angle_unit_t unit);
|
||||
|
||||
double vector2_get_angle_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2, const angle_unit_t unit);
|
||||
double bgc_vector2_get_angle_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2, const bgc_angle_unit_t unit);
|
||||
|
||||
// =============== Square Distance ============== //
|
||||
|
||||
inline float vector2_get_square_distance_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2)
|
||||
inline float bgc_vector2_get_square_distance_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
const float dx1 = (vector1->x1 - vector2->x1);
|
||||
const float dx2 = (vector1->x2 - vector2->x2);
|
||||
|
|
@ -380,7 +380,7 @@ inline float vector2_get_square_distance_fp32(const vector2_fp32_t* vector1, con
|
|||
return dx1 * dx1 + dx2 * dx2;
|
||||
}
|
||||
|
||||
inline double vector2_get_square_distance_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2)
|
||||
inline double bgc_vector2_get_square_distance_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
const double dx1 = (vector1->x1 - vector2->x1);
|
||||
const double dx2 = (vector1->x2 - vector2->x2);
|
||||
|
|
@ -390,52 +390,52 @@ inline double vector2_get_square_distance_fp64(const vector2_fp64_t* vector1, co
|
|||
|
||||
// ================== Distance ================== //
|
||||
|
||||
inline float vector2_get_distance_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2)
|
||||
inline float bgc_vector2_get_distance_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
return sqrtf(vector2_get_square_distance_fp32(vector1, vector2));
|
||||
return sqrtf(bgc_vector2_get_square_distance_fp32(vector1, vector2));
|
||||
}
|
||||
|
||||
inline double vector2_get_distance_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2)
|
||||
inline double bgc_vector2_get_distance_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
return sqrt(vector2_get_square_distance_fp64(vector1, vector2));
|
||||
return sqrt(bgc_vector2_get_square_distance_fp64(vector1, vector2));
|
||||
}
|
||||
|
||||
// ================== Are Equal ================= //
|
||||
|
||||
inline int vector2_are_equal_fp32(const vector2_fp32_t* vector1, const vector2_fp32_t* vector2)
|
||||
inline int bgc_vector2_are_equal_fp32(const bgc_vector2_fp32_t* vector1, const bgc_vector2_fp32_t* vector2)
|
||||
{
|
||||
const float square_modulus1 = vector2_get_square_modulus_fp32(vector1);
|
||||
const float square_modulus2 = vector2_get_square_modulus_fp32(vector2);
|
||||
const float square_modulus3 = vector2_get_square_distance_fp32(vector1, 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);
|
||||
|
||||
// 2.0f means dimension amount
|
||||
if (square_modulus1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (2.0f * FP32_SQUARE_EPSYLON);
|
||||
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 <= square_modulus2) {
|
||||
return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||
return square_modulus3 <= (2.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1;
|
||||
}
|
||||
|
||||
inline int vector2_are_equal_fp64(const vector2_fp64_t* vector1, const vector2_fp64_t* vector2)
|
||||
inline int bgc_vector2_are_equal_fp64(const bgc_vector2_fp64_t* vector1, const bgc_vector2_fp64_t* vector2)
|
||||
{
|
||||
const double square_modulus1 = vector2_get_square_modulus_fp64(vector1);
|
||||
const double square_modulus2 = vector2_get_square_modulus_fp64(vector2);
|
||||
const double square_modulus3 = vector2_get_square_distance_fp64(vector1, 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);
|
||||
|
||||
// 2.0 means dimension amount
|
||||
if (square_modulus1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (2.0 * FP64_SQUARE_EPSYLON);
|
||||
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 <= square_modulus2) {
|
||||
return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||
return square_modulus3 <= (2.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue