Большое переименование
This commit is contained in:
parent
e354b2425c
commit
e7616ae80c
30 changed files with 1356 additions and 1348 deletions
192
src/vector2.h
192
src/vector2.h
|
@ -9,22 +9,22 @@
|
|||
typedef struct
|
||||
{
|
||||
float x1, x2;
|
||||
} SPVector2;
|
||||
} BgFP32Vector2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2;
|
||||
} DPVector2;
|
||||
} BgFP64Vector2;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void sp_vector2_reset(SPVector2* vector)
|
||||
static inline void bg_fp32_vector2_reset(BgFP32Vector2* vector)
|
||||
{
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reset(DPVector2* vector)
|
||||
static inline void bg_fp64_vector2_reset(BgFP64Vector2* vector)
|
||||
{
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
|
@ -32,13 +32,13 @@ static inline void dp_vector2_reset(DPVector2* vector)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
static inline void sp_vector2_set_values(const float x1, const float x2, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_values(const float x1, const float x2, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_set_values(const double x1, const double x2, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_values(const double x1, const double x2, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = x1;
|
||||
to->x2 = x2;
|
||||
|
@ -46,13 +46,13 @@ static inline void dp_vector2_set_values(const double x1, const double x2, DPVec
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void sp_vector2_copy(const SPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_copy(const BgFP32Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_copy(const DPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_copy(const BgFP64Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -60,13 +60,13 @@ static inline void dp_vector2_copy(const DPVector2* from, DPVector2* to)
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void sp_vector2_copy_from_double(const DPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_from_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = (float)from->x1;
|
||||
to->x2 = (float)from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_copy_from_single(const SPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_from_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = from->x1;
|
||||
to->x2 = from->x2;
|
||||
|
@ -74,13 +74,13 @@ static inline void dp_vector2_copy_from_single(const SPVector2* from, DPVector2*
|
|||
|
||||
// =================== Reverse ================== //
|
||||
|
||||
static inline void sp_vector2_reverse(const SPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_reverse(const BgFP32Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse(const DPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_reverse(const BgFP64Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -88,13 +88,13 @@ static inline void dp_vector2_reverse(const DPVector2* from, DPVector2* to)
|
|||
|
||||
// ============= Reverse twin type ============== //
|
||||
|
||||
static inline void sp_vector2_reverse_double(const DPVector2* from, SPVector2* to)
|
||||
static inline void bg_fp32_vector2_set_reverse_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
||||
{
|
||||
to->x1 = -(float)from->x1;
|
||||
to->x2 = -(float)from->x2;
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_reverse_single(const SPVector2* from, DPVector2* to)
|
||||
static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
|
@ -102,61 +102,61 @@ static inline void dp_vector2_reverse_single(const SPVector2* from, DPVector2* t
|
|||
|
||||
// =================== Module =================== //
|
||||
|
||||
static inline float sp_vector2_get_square_module(const SPVector2* vector)
|
||||
static inline float bg_fp32_vector2_get_square_module(const BgFP32Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_square_module(const DPVector2* vector)
|
||||
static inline double bg_fp64_vector2_get_square_module(const BgFP64Vector2* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
static inline float sp_vector2_get_module(const SPVector2* vector)
|
||||
static inline float bg_fp32_vector2_get_module(const BgFP32Vector2* vector)
|
||||
{
|
||||
return sqrtf(sp_vector2_get_square_module(vector));
|
||||
return sqrtf(bg_fp32_vector2_get_square_module(vector));
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_module(const DPVector2* vector)
|
||||
static inline double bg_fp64_vector2_get_module(const BgFP64Vector2* vector)
|
||||
{
|
||||
return sqrt(dp_vector2_get_square_module(vector));
|
||||
return sqrt(bg_fp64_vector2_get_square_module(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
static inline int sp_vector2_is_zero(const SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
|
||||
{
|
||||
return sp_vector2_get_square_module(vector) <= SP_SQUARE_EPSYLON;
|
||||
return bg_fp32_vector2_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_is_zero(const DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
|
||||
{
|
||||
return dp_vector2_get_square_module(vector) <= DP_SQUARE_EPSYLON;
|
||||
return bg_fp64_vector2_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int sp_vector2_is_unit(const SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = sp_vector2_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
|
||||
return 1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_is_unit(const DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = dp_vector2_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
|
||||
return 1.0f - DP_TWO_EPSYLON <= square_module && square_module <= 1.0f + DP_TWO_EPSYLON;
|
||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void sp_vector2_add(const SPVector2* vector1, const SPVector2* vector2, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_add(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_add(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
|
@ -164,13 +164,13 @@ static inline void dp_vector2_add(const DPVector2* vector1, const DPVector2* vec
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void sp_vector2_subtract(const SPVector2* minuend, const SPVector2* subtrahend, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_subtract(const BgFP32Vector2* minuend, const BgFP32Vector2* subtrahend, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_subtract(const DPVector2* minuend, const DPVector2* subtrahend, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const BgFP64Vector2* subtrahend, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
|
@ -178,13 +178,13 @@ static inline void dp_vector2_subtract(const DPVector2* minuend, const DPVector2
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void sp_vector2_multiply(const SPVector2* multiplicand, const float multiplier, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_multiply(const BgFP32Vector2* multiplicand, const float multiplier, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_multiply(const DPVector2* multiplicand, const double multiplier, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, const double multiplier, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
|
@ -192,13 +192,13 @@ static inline void dp_vector2_multiply(const DPVector2* multiplicand, const doub
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void sp_vector2_divide(const SPVector2* dividend, const float divisor, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_divide(const BgFP32Vector2* dividend, const float divisor, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_divide(const DPVector2* dividend, const double divisor, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_divide(const BgFP64Vector2* dividend, const double divisor, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
|
@ -206,13 +206,13 @@ static inline void dp_vector2_divide(const DPVector2* dividend, const double div
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void sp_vector2_append_scaled(SPVector2* basic_vector, const SPVector2* scalable_vector, const float scale)
|
||||
static inline void bg_fp32_vector2_append_scaled(BgFP32Vector2* basic_vector, const BgFP32Vector2* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_append_scaled(DPVector2* basic_vector, const DPVector2* scalable_vector, const double scale)
|
||||
static inline void bg_fp64_vector2_append_scaled(BgFP64Vector2* basic_vector, const BgFP64Vector2* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||
|
@ -220,13 +220,13 @@ static inline void dp_vector2_append_scaled(DPVector2* basic_vector, const DPVec
|
|||
|
||||
// ================== Average2 ================== //
|
||||
|
||||
static inline void sp_vector2_get_mean2(const SPVector2* vector1, const SPVector2* vector2, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_get_mean2(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_get_mean2(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_get_mean2(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
|
@ -234,101 +234,101 @@ static inline void dp_vector2_get_mean2(const DPVector2* vector1, const DPVector
|
|||
|
||||
// ================== Average3 ================== //
|
||||
|
||||
static inline void sp_vector2_get_mean3(const SPVector2* vector1, const SPVector2* vector2, const SPVector2* vector3, SPVector2* result)
|
||||
static inline void bg_fp32_vector2_get_mean3(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const BgFP32Vector2* vector3, BgFP32Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * SP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * SP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP32_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP32_ONE_THIRD;
|
||||
}
|
||||
|
||||
static inline void dp_vector2_get_mean3(const DPVector2* vector1, const DPVector2* vector2, const DPVector2* vector3, DPVector2* result)
|
||||
static inline void bg_fp64_vector2_get_mean3(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const BgFP64Vector2* vector3, BgFP64Vector2* result)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * DP_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * DP_ONE_THIRD;
|
||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP64_ONE_THIRD;
|
||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP64_ONE_THIRD;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
||||
static inline float sp_vector2_scalar(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_dot_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_scalar(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_dot_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
// =============== Cross Product ================ //
|
||||
|
||||
static inline float sp_vector2_cross(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_cross_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_cross(const DPVector2* vector1, const DPVector2* vector2, DPVector2* result)
|
||||
static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
{
|
||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||
}
|
||||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
static inline int sp_vector2_normalize(SPVector2* vector)
|
||||
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_module = sp_vector2_get_square_module(vector);
|
||||
const float square_module = bg_fp32_vector2_get_square_module(vector);
|
||||
|
||||
if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= SP_SQUARE_EPSYLON) {
|
||||
sp_vector2_reset(vector);
|
||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sp_vector2_divide(vector, sqrtf(square_module), vector);
|
||||
bg_fp32_vector2_divide(vector, sqrtf(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_normalize(DPVector2* vector)
|
||||
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_module = dp_vector2_get_square_module(vector);
|
||||
const double square_module = bg_fp64_vector2_get_square_module(vector);
|
||||
|
||||
if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_module <= DP_SQUARE_EPSYLON) {
|
||||
dp_vector2_reset(vector);
|
||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dp_vector2_divide(vector, sqrt(square_module), vector);
|
||||
bg_fp64_vector2_divide(vector, sqrt(square_module), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Get Normalized =============== //
|
||||
|
||||
static inline int sp_vector2_get_normalized(const SPVector2* vector, SPVector2* result)
|
||||
static inline int bg_fp32_vector2_set_normalized(const BgFP32Vector2* vector, BgFP32Vector2* result)
|
||||
{
|
||||
sp_vector2_copy(vector, result);
|
||||
return sp_vector2_normalize(result);
|
||||
bg_fp32_vector2_copy(vector, result);
|
||||
return bg_fp32_vector2_normalize(result);
|
||||
}
|
||||
|
||||
static inline int dp_vector2_get_normalized(const DPVector2* vector, DPVector2* result)
|
||||
static inline int bg_fp64_vector2_set_normalized(const BgFP64Vector2* vector, BgFP64Vector2* result)
|
||||
{
|
||||
dp_vector2_copy(vector, result);
|
||||
return dp_vector2_normalize(result);
|
||||
bg_fp64_vector2_copy(vector, result);
|
||||
return bg_fp64_vector2_normalize(result);
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float sp_vector2_angle(const SPVector2* vector1, const SPVector2* vector2, const angle_unit_t unit);
|
||||
float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const angle_unit_t unit);
|
||||
|
||||
double dp_vector2_angle(const DPVector2* vector1, const DPVector2* vector2, const angle_unit_t unit);
|
||||
double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const angle_unit_t unit);
|
||||
|
||||
// =============== Square Distance ============== //
|
||||
|
||||
static inline float sp_vector2_get_square_distance(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_get_square_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
const float dx1 = (vector1->x1 - vector2->x1);
|
||||
const float dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -336,7 +336,7 @@ static inline float sp_vector2_get_square_distance(const SPVector2* vector1, con
|
|||
return dx1 * dx1 + dx2 * dx2;
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_square_distance(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_get_square_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
const double dx1 = (vector1->x1 - vector2->x1);
|
||||
const double dx2 = (vector1->x2 - vector2->x2);
|
||||
|
@ -346,52 +346,52 @@ static inline double dp_vector2_get_square_distance(const DPVector2* vector1, co
|
|||
|
||||
// ================== Distance ================== //
|
||||
|
||||
static inline float sp_vector2_get_distance(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline float bg_fp32_vector2_get_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return sqrtf(sp_vector2_get_square_distance(vector1, vector2));
|
||||
return sqrtf(bg_fp32_vector2_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
static inline double dp_vector2_get_distance(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
return sqrt(dp_vector2_get_square_distance(vector1, vector2));
|
||||
return sqrt(bg_fp64_vector2_get_square_distance(vector1, vector2));
|
||||
}
|
||||
|
||||
// ================== Are Equal ================= //
|
||||
|
||||
static inline int sp_vector2_are_equal(const SPVector2* vector1, const SPVector2* vector2)
|
||||
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
const float square_module1 = sp_vector2_get_square_module(vector1);
|
||||
const float square_module2 = sp_vector2_get_square_module(vector2);
|
||||
const float square_module3 = sp_vector2_get_square_distance(vector1, vector2);
|
||||
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
|
||||
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
|
||||
const float square_module3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0f means dimension amount
|
||||
if (square_module1 < SP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < SP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0f * SP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0f * SP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0f * SP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
static inline int dp_vector2_are_equal(const DPVector2* vector1, const DPVector2* vector2)
|
||||
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
const double square_module1 = dp_vector2_get_square_module(vector1);
|
||||
const double square_module2 = dp_vector2_get_square_module(vector2);
|
||||
const double square_module3 = dp_vector2_get_square_distance(vector1, vector2);
|
||||
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
|
||||
|
||||
// 2.0 means dimension amount
|
||||
if (square_module1 < DP_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < DP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0 * DP_SQUARE_EPSYLON);
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (2.0 * DP_SQUARE_EPSYLON) * square_module2;
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
}
|
||||
|
||||
return square_module3 <= (2.0 * DP_SQUARE_EPSYLON) * square_module1;
|
||||
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue