521 lines
18 KiB
C
521 lines
18 KiB
C
#ifndef _BGC_VECTOR3_H_
|
|
#define _BGC_VECTOR3_H_
|
|
|
|
#include "utilities.h"
|
|
#include "angle.h"
|
|
|
|
#include <math.h>
|
|
|
|
// ================== Vector3 =================== //
|
|
|
|
typedef struct
|
|
{
|
|
float x1, x2, x3;
|
|
} bgc_vector3_fp32_t;
|
|
|
|
typedef struct
|
|
{
|
|
double x1, x2, x3;
|
|
} bgc_vector3_fp64_t;
|
|
|
|
// =================== Reset ==================== //
|
|
|
|
inline void bgc_vector3_reset_fp32(bgc_vector3_fp32_t* vector)
|
|
{
|
|
vector->x1 = 0.0f;
|
|
vector->x2 = 0.0f;
|
|
vector->x3 = 0.0f;
|
|
}
|
|
|
|
inline void bgc_vector3_reset_fp64(bgc_vector3_fp64_t* vector)
|
|
{
|
|
vector->x1 = 0.0;
|
|
vector->x2 = 0.0;
|
|
vector->x3 = 0.0;
|
|
}
|
|
|
|
// ==================== Set ===================== //
|
|
|
|
inline void bgc_vector3_set_values_fp32(const float x1, const float x2, const float x3, bgc_vector3_fp32_t* to)
|
|
{
|
|
to->x1 = x1;
|
|
to->x2 = x2;
|
|
to->x3 = x3;
|
|
}
|
|
|
|
inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const double x3, bgc_vector3_fp64_t* to)
|
|
{
|
|
to->x1 = x1;
|
|
to->x2 = x2;
|
|
to->x3 = x3;
|
|
}
|
|
|
|
// ==================== Copy ==================== //
|
|
|
|
inline void bgc_vector3_copy_fp32(const bgc_vector3_fp32_t* from, bgc_vector3_fp32_t* to)
|
|
{
|
|
to->x1 = from->x1;
|
|
to->x2 = from->x2;
|
|
to->x3 = from->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_copy_fp64(const bgc_vector3_fp64_t* from, bgc_vector3_fp64_t* to)
|
|
{
|
|
to->x1 = from->x1;
|
|
to->x2 = from->x2;
|
|
to->x3 = from->x3;
|
|
}
|
|
|
|
// ================== Convert =================== //
|
|
|
|
inline void bgc_vector3_convert_fp64_to_fp32(const bgc_vector3_fp64_t* from, bgc_vector3_fp32_t* to)
|
|
{
|
|
to->x1 = (float) from->x1;
|
|
to->x2 = (float) from->x2;
|
|
to->x3 = (float) from->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_convert_fp32_to_fp64(const bgc_vector3_fp32_t* from, bgc_vector3_fp64_t* to)
|
|
{
|
|
to->x1 = from->x1;
|
|
to->x2 = from->x2;
|
|
to->x3 = from->x3;
|
|
}
|
|
|
|
// ==================== Swap ==================== //
|
|
|
|
inline void bgc_vector3_swap_fp32(bgc_vector3_fp32_t* vector1, bgc_vector3_fp32_t* vector2)
|
|
{
|
|
const float x1 = vector2->x1;
|
|
const float x2 = vector2->x2;
|
|
const float x3 = vector2->x3;
|
|
|
|
vector2->x1 = vector1->x1;
|
|
vector2->x2 = vector1->x2;
|
|
vector2->x3 = vector1->x3;
|
|
|
|
vector1->x1 = x1;
|
|
vector1->x2 = x2;
|
|
vector1->x3 = x3;
|
|
}
|
|
|
|
inline void bgc_vector3_swap_fp64(bgc_vector3_fp64_t* vector1, bgc_vector3_fp64_t* vector2)
|
|
{
|
|
const double x1 = vector2->x1;
|
|
const double x2 = vector2->x2;
|
|
const double x3 = vector2->x3;
|
|
|
|
vector2->x1 = vector1->x1;
|
|
vector2->x2 = vector1->x2;
|
|
vector2->x3 = vector1->x3;
|
|
|
|
vector1->x1 = x1;
|
|
vector1->x2 = x2;
|
|
vector1->x3 = x3;
|
|
}
|
|
|
|
// ==================== Invert ================== //
|
|
|
|
inline void bgc_vector3_invert_fp32(bgc_vector3_fp32_t* vector)
|
|
{
|
|
vector->x1 = -vector->x1;
|
|
vector->x2 = -vector->x2;
|
|
vector->x3 = -vector->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_invert_fp64(bgc_vector3_fp64_t* vector)
|
|
{
|
|
vector->x1 = -vector->x1;
|
|
vector->x2 = -vector->x2;
|
|
vector->x3 = -vector->x3;
|
|
}
|
|
|
|
// ================ Make Inverted =============== //
|
|
|
|
inline void bgc_vector3_set_inverted_fp32(const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* result)
|
|
{
|
|
result->x1 = -vector->x1;
|
|
result->x2 = -vector->x2;
|
|
result->x3 = -vector->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_set_inverted_fp64(const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* result)
|
|
{
|
|
result->x1 = -vector->x1;
|
|
result->x2 = -vector->x2;
|
|
result->x3 = -vector->x3;
|
|
}
|
|
|
|
// ============== Make Inverted Twin ============ //
|
|
|
|
inline void bgc_vector3_set_inverted_fp32_to_fp64(const bgc_vector3_fp32_t* vector, bgc_vector3_fp64_t* result)
|
|
{
|
|
result->x1 = -vector->x1;
|
|
result->x2 = -vector->x2;
|
|
result->x3 = -vector->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_set_inverted_fp64_to_fp32(const bgc_vector3_fp64_t* vector, bgc_vector3_fp32_t* result)
|
|
{
|
|
result->x1 = (float) -vector->x1;
|
|
result->x2 = (float) -vector->x2;
|
|
result->x3 = (float) -vector->x3;
|
|
}
|
|
|
|
// =================== Module =================== //
|
|
|
|
inline float bgc_vector3_get_square_modulus_fp32(const bgc_vector3_fp32_t* vector)
|
|
{
|
|
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
|
}
|
|
|
|
inline double bgc_vector3_get_square_modulus_fp64(const bgc_vector3_fp64_t* vector)
|
|
{
|
|
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
|
|
}
|
|
|
|
inline float bgc_vector3_get_modulus_fp32(const bgc_vector3_fp32_t* vector)
|
|
{
|
|
return sqrtf(bgc_vector3_get_square_modulus_fp32(vector));
|
|
}
|
|
|
|
inline double bgc_vector3_get_modulus_fp64(const bgc_vector3_fp64_t* vector)
|
|
{
|
|
return sqrt(bgc_vector3_get_square_modulus_fp64(vector));
|
|
}
|
|
|
|
// ================= Comparison ================= //
|
|
|
|
inline int bgc_vector3_is_zero_fp32(const bgc_vector3_fp32_t* vector)
|
|
{
|
|
return bgc_vector3_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32;
|
|
}
|
|
|
|
inline int bgc_vector3_is_zero_fp64(const bgc_vector3_fp64_t* vector)
|
|
{
|
|
return bgc_vector3_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64;
|
|
}
|
|
|
|
inline int bgc_vector3_is_unit_fp32(const bgc_vector3_fp32_t* vector)
|
|
{
|
|
const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector);
|
|
|
|
return 1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32;
|
|
}
|
|
|
|
inline int bgc_vector3_is_unit_fp64(const bgc_vector3_fp64_t* vector)
|
|
{
|
|
const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector);
|
|
|
|
return 1.0f - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP64;
|
|
}
|
|
|
|
// ==================== Add ===================== //
|
|
|
|
inline void bgc_vector3_add_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* sum)
|
|
{
|
|
sum->x1 = vector1->x1 + vector2->x1;
|
|
sum->x2 = vector1->x2 + vector2->x2;
|
|
sum->x3 = vector1->x3 + vector2->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_add_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* sum)
|
|
{
|
|
sum->x1 = vector1->x1 + vector2->x1;
|
|
sum->x2 = vector1->x2 + vector2->x2;
|
|
sum->x3 = vector1->x3 + vector2->x3;
|
|
}
|
|
|
|
// ================= Add scaled ================= //
|
|
|
|
inline void bgc_vector3_add_scaled_fp32(const bgc_vector3_fp32_t* basic_vector, const bgc_vector3_fp32_t* scalable_vector, const float scale, bgc_vector3_fp32_t* result)
|
|
{
|
|
result->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
|
result->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
|
result->x3 = basic_vector->x3 + scalable_vector->x3 * scale;
|
|
}
|
|
|
|
inline void bgc_vector3_add_scaled_fp64(const bgc_vector3_fp64_t* basic_vector, const bgc_vector3_fp64_t* scalable_vector, const double scale, bgc_vector3_fp64_t* result)
|
|
{
|
|
result->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
|
result->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
|
result->x3 = basic_vector->x3 + scalable_vector->x3 * scale;
|
|
}
|
|
|
|
// ================ Subtraction ================= //
|
|
|
|
inline void bgc_vector3_subtract_fp32(const bgc_vector3_fp32_t* minuend, const bgc_vector3_fp32_t* subtrahend, bgc_vector3_fp32_t* difference)
|
|
{
|
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
|
difference->x3 = minuend->x3 - subtrahend->x3;
|
|
}
|
|
|
|
inline void bgc_vector3_subtract_fp64(const bgc_vector3_fp64_t* minuend, const bgc_vector3_fp64_t* subtrahend, bgc_vector3_fp64_t* difference)
|
|
{
|
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
|
difference->x3 = minuend->x3 - subtrahend->x3;
|
|
}
|
|
|
|
// =============== Multiplication =============== //
|
|
|
|
inline void bgc_vector3_multiply_fp32(const bgc_vector3_fp32_t* multiplicand, const float multiplier, bgc_vector3_fp32_t* product)
|
|
{
|
|
product->x1 = multiplicand->x1 * multiplier;
|
|
product->x2 = multiplicand->x2 * multiplier;
|
|
product->x3 = multiplicand->x3 * multiplier;
|
|
}
|
|
|
|
inline void bgc_vector3_multiply_fp64(const bgc_vector3_fp64_t* multiplicand, const double multiplier, bgc_vector3_fp64_t* product)
|
|
{
|
|
product->x1 = multiplicand->x1 * multiplier;
|
|
product->x2 = multiplicand->x2 * multiplier;
|
|
product->x3 = multiplicand->x3 * multiplier;
|
|
}
|
|
|
|
// ================== Division ================== //
|
|
|
|
inline void bgc_vector3_divide_fp32(const bgc_vector3_fp32_t* dividend, const float divisor, bgc_vector3_fp32_t* quotient)
|
|
{
|
|
bgc_vector3_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
|
}
|
|
|
|
inline void bgc_vector3_divide_fp64(const bgc_vector3_fp64_t* dividend, const double divisor, bgc_vector3_fp64_t* quotient)
|
|
{
|
|
bgc_vector3_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
|
}
|
|
|
|
// ================== Average2 ================== //
|
|
|
|
inline void bgc_vector3_mean_of_two_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* result)
|
|
{
|
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
|
result->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
|
}
|
|
|
|
inline void bgc_vector3_mean_of_two_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* result)
|
|
{
|
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
|
result->x3 = (vector1->x3 + vector2->x3) * 0.5;
|
|
}
|
|
|
|
// ================== Average3 ================== //
|
|
|
|
inline void bgc_vector3_mean_of_three_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* vector3, bgc_vector3_fp32_t* result)
|
|
{
|
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32;
|
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32;
|
|
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP32;
|
|
}
|
|
|
|
inline void bgc_vector3_mean_of_three_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3, bgc_vector3_fp64_t* result)
|
|
{
|
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64;
|
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64;
|
|
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP64;
|
|
}
|
|
|
|
// =============== Scalar Product =============== //
|
|
|
|
inline float bgc_vector3_scalar_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2)
|
|
{
|
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
|
}
|
|
|
|
inline double bgc_vector3_scalar_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2)
|
|
{
|
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
|
}
|
|
|
|
// =============== Triple Product =============== //
|
|
|
|
inline float bgc_vector3_triple_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* vector3)
|
|
{
|
|
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
|
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
|
+ vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1);
|
|
}
|
|
|
|
inline double bgc_vector3_triple_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3)
|
|
{
|
|
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
|
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
|
+ vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1);
|
|
}
|
|
|
|
// =============== Cross Product ================ //
|
|
|
|
inline void bgc_vector3_cross_product_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, bgc_vector3_fp32_t* result)
|
|
{
|
|
const float x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
|
const float x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
|
const float x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
inline void bgc_vector3_cross_product_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, bgc_vector3_fp64_t* result)
|
|
{
|
|
const double x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
|
const double x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
|
const double x3 = vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
|
|
|
result->x1 = x1;
|
|
result->x2 = x2;
|
|
result->x3 = x3;
|
|
}
|
|
|
|
// ============ Double Cross Product ============ //
|
|
|
|
inline void bgc_vector3_double_cross_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_vector3_fp32_t* vector3, bgc_vector3_fp32_t* result)
|
|
{
|
|
const float ac = bgc_vector3_scalar_product_fp32(vector1, vector3);
|
|
const float ab = bgc_vector3_scalar_product_fp32(vector1, vector2);
|
|
|
|
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
|
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
|
result->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
|
}
|
|
|
|
inline void bgc_vector3_double_cross_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_vector3_fp64_t* vector3, bgc_vector3_fp64_t* result)
|
|
{
|
|
const double ac = bgc_vector3_scalar_product_fp64(vector1, vector3);
|
|
const double ab = bgc_vector3_scalar_product_fp64(vector1, vector2);
|
|
|
|
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
|
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
|
result->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
|
}
|
|
|
|
// =============== Normalization ================ //
|
|
|
|
inline int bgc_vector3_normalize_fp32(bgc_vector3_fp32_t* vector)
|
|
{
|
|
const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector);
|
|
|
|
if (1.0f - BGC_TWO_EPSYLON_FP32 <= square_modulus && square_modulus <= 1.0f + BGC_TWO_EPSYLON_FP32) {
|
|
return 1;
|
|
}
|
|
|
|
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
|
bgc_vector3_reset_fp32(vector);
|
|
return 0;
|
|
}
|
|
|
|
bgc_vector3_multiply_fp32(vector, sqrtf(1.0f / square_modulus), vector);
|
|
return 1;
|
|
}
|
|
|
|
inline int bgc_vector3_normalize_fp64(bgc_vector3_fp64_t* vector)
|
|
{
|
|
const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector);
|
|
|
|
if (1.0 - BGC_TWO_EPSYLON_FP64 <= square_modulus && square_modulus <= 1.0 + BGC_TWO_EPSYLON_FP64) {
|
|
return 1;
|
|
}
|
|
|
|
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
|
bgc_vector3_reset_fp64(vector);
|
|
return 0;
|
|
}
|
|
|
|
bgc_vector3_multiply_fp64(vector, sqrt(1.0 / square_modulus), vector);
|
|
return 1;
|
|
}
|
|
|
|
// =============== Set Normalized =============== //
|
|
|
|
inline int bgc_vector3_set_normalized_fp32(const bgc_vector3_fp32_t* vector, bgc_vector3_fp32_t* result)
|
|
{
|
|
bgc_vector3_copy_fp32(vector, result);
|
|
return bgc_vector3_normalize_fp32(result);
|
|
}
|
|
|
|
inline int bgc_vector3_set_normalized_fp64(const bgc_vector3_fp64_t* vector, bgc_vector3_fp64_t* result)
|
|
{
|
|
bgc_vector3_copy_fp64(vector, result);
|
|
return bgc_vector3_normalize_fp64(result);
|
|
}
|
|
|
|
// =================== Angle ==================== //
|
|
|
|
float bgc_vector3_get_angle_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2, const bgc_angle_unit_t unit);
|
|
|
|
double bgc_vector3_get_angle_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2, const bgc_angle_unit_t unit);
|
|
|
|
// =============== Square Distance ============== //
|
|
|
|
inline float bgc_vector3_get_square_distance_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2)
|
|
{
|
|
const float dx1 = (vector1->x1 - vector2->x1);
|
|
const float dx2 = (vector1->x2 - vector2->x2);
|
|
const float dx3 = (vector1->x3 - vector2->x3);
|
|
|
|
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
|
}
|
|
|
|
inline double bgc_vector3_get_square_distance_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2)
|
|
{
|
|
const double dx1 = (vector1->x1 - vector2->x1);
|
|
const double dx2 = (vector1->x2 - vector2->x2);
|
|
const double dx3 = (vector1->x3 - vector2->x3);
|
|
|
|
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
|
}
|
|
|
|
// ================== Distance ================== //
|
|
|
|
inline float bgc_vector3_get_distance_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2)
|
|
{
|
|
return sqrtf(bgc_vector3_get_square_distance_fp32(vector1, vector2));
|
|
}
|
|
|
|
inline double bgc_vector3_get_distance_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2)
|
|
{
|
|
return sqrt(bgc_vector3_get_square_distance_fp64(vector1, vector2));
|
|
}
|
|
|
|
// ================== Are Equal ================= //
|
|
|
|
inline int bgc_vector3_are_equal_fp32(const bgc_vector3_fp32_t* vector1, const bgc_vector3_fp32_t* vector2)
|
|
{
|
|
const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1);
|
|
const float square_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2);
|
|
const float square_modulus3 = bgc_vector3_get_square_distance_fp32(vector1, vector2);
|
|
|
|
// 3.0f means dimension amount
|
|
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP32) {
|
|
return square_modulus3 < (3.0f * BGC_SQUARE_EPSYLON_FP32);
|
|
}
|
|
|
|
if (square_modulus1 <= square_modulus2) {
|
|
return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus2;
|
|
}
|
|
|
|
return square_modulus3 <= (3.0f * BGC_SQUARE_EPSYLON_FP32) * square_modulus1;
|
|
}
|
|
|
|
inline int bgc_vector3_are_equal_fp64(const bgc_vector3_fp64_t* vector1, const bgc_vector3_fp64_t* vector2)
|
|
{
|
|
const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1);
|
|
const double square_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2);
|
|
const double square_modulus3 = bgc_vector3_get_square_distance_fp64(vector1, vector2);
|
|
|
|
// 3.0 means dimension amount
|
|
if (square_modulus1 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64 || square_modulus2 < BGC_EPSYLON_EFFECTIVENESS_LIMIT_FP64) {
|
|
return square_modulus3 < (3.0 * BGC_SQUARE_EPSYLON_FP64);
|
|
}
|
|
|
|
if (square_modulus1 <= square_modulus2) {
|
|
return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus2;
|
|
}
|
|
|
|
return square_modulus3 <= (3.0 * BGC_SQUARE_EPSYLON_FP64) * square_modulus1;
|
|
}
|
|
|
|
#endif
|