Упорядочивание проекта
This commit is contained in:
parent
0dcd9c0d4d
commit
89dfd7644b
32 changed files with 1730 additions and 1719 deletions
|
|
@ -50,94 +50,6 @@ inline void bgc_vector3_set_values_fp64(const double x1, const double x2, const
|
|||
destination->x3 = x3;
|
||||
}
|
||||
|
||||
// ================= Directions ================= //
|
||||
|
||||
inline int bgc_vector3_get_direction_fp32(const int direction, BgcVector3FP32* vector)
|
||||
{
|
||||
switch (direction) {
|
||||
case BGC_DIRECTION_X1:
|
||||
vector->x1 = 1.0f;
|
||||
vector->x2 = 0.0f;
|
||||
vector->x3 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 1.0f;
|
||||
vector->x3 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X3:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
vector->x3 = 1.0f;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X1:
|
||||
vector->x1 = -1.0f;
|
||||
vector->x2 = 0.0f;
|
||||
vector->x3 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = -1.0f;
|
||||
vector->x3 = 0.0f;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X3:
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
vector->x3 = -1.0f;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_direction_fp64(const int direction, BgcVector3FP64* vector)
|
||||
{
|
||||
switch (direction) {
|
||||
case BGC_DIRECTION_X1:
|
||||
vector->x1 = 1.0;
|
||||
vector->x2 = 0.0;
|
||||
vector->x3 = 0.0;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 1.0;
|
||||
vector->x3 = 0.0;
|
||||
return 1;
|
||||
|
||||
case BGC_DIRECTION_X3:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
vector->x3 = 1.0;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X1:
|
||||
vector->x1 = -1.0;
|
||||
vector->x2 = 0.0;
|
||||
vector->x3 = 0.0;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X2:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = -1.0;
|
||||
vector->x3 = 0.0;
|
||||
return 1;
|
||||
|
||||
case -BGC_DIRECTION_X3:
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
vector->x3 = -1.0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ================== Modulus =================== //
|
||||
|
||||
inline float bgc_vector3_get_square_modulus_fp32(const BgcVector3FP32* vector)
|
||||
|
|
@ -246,114 +158,6 @@ inline void bgc_vector3_convert_fp32_to_fp64(const BgcVector3FP32* source, BgcVe
|
|||
destination->x3 = source->x3;
|
||||
}
|
||||
|
||||
// ================== Reverse =================== //
|
||||
|
||||
inline void bgc_vector3_reverse_fp32(const BgcVector3FP32* vector, BgcVector3FP32* reverse)
|
||||
{
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
reverse->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_reverse_fp64(const BgcVector3FP64* vector, BgcVector3FP64* reverse)
|
||||
{
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
reverse->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_vector3_normalize_fp32(BgcVector3FP32* vector)
|
||||
{
|
||||
const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
vector->x1 *= multiplicand;
|
||||
vector->x2 *= multiplicand;
|
||||
vector->x3 *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_normalize_fp64(BgcVector3FP64* vector)
|
||||
{
|
||||
const double square_modulus = bgc_vector3_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 multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
vector->x1 *= multiplicand;
|
||||
vector->x2 *= multiplicand;
|
||||
vector->x3 *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_normalized_fp32(const BgcVector3FP32* vector, BgcVector3FP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
normalized->x1 = vector->x1;
|
||||
normalized->x2 = vector->x2;
|
||||
normalized->x3 = vector->x3;
|
||||
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;
|
||||
normalized->x3 = vector->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_normalized_fp64(const BgcVector3FP64* vector, BgcVector3FP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
normalized->x1 = vector->x1;
|
||||
normalized->x2 = vector->x2;
|
||||
normalized->x3 = vector->x3;
|
||||
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;
|
||||
normalized->x3 = vector->x3 * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_vector3_add_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, BgcVector3FP32* sum)
|
||||
|
|
@ -372,18 +176,18 @@ inline void bgc_vector3_add_fp64(const BgcVector3FP64* vector1, const BgcVector3
|
|||
|
||||
// ================= Add scaled ================= //
|
||||
|
||||
inline void bgc_vector3_add_scaled_fp32(const BgcVector3FP32* basic_vector, const BgcVector3FP32* scalable_vector, const float scale, BgcVector3FP32* result)
|
||||
inline void bgc_vector3_add_scaled_fp32(const BgcVector3FP32* basic_vector, const BgcVector3FP32* scalable_vector, const float scale, BgcVector3FP32* sum)
|
||||
{
|
||||
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;
|
||||
sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
||||
sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
||||
sum->x3 = basic_vector->x3 + scalable_vector->x3 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_add_scaled_fp64(const BgcVector3FP64* basic_vector, const BgcVector3FP64* scalable_vector, const double scale, BgcVector3FP64* result)
|
||||
inline void bgc_vector3_add_scaled_fp64(const BgcVector3FP64* basic_vector, const BgcVector3FP64* scalable_vector, const double scale, BgcVector3FP64* sum)
|
||||
{
|
||||
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;
|
||||
sum->x1 = basic_vector->x1 + scalable_vector->x1 * scale;
|
||||
sum->x2 = basic_vector->x2 + scalable_vector->x2 * scale;
|
||||
sum->x3 = basic_vector->x3 + scalable_vector->x3 * scale;
|
||||
}
|
||||
|
||||
// ================== Subtract ================== //
|
||||
|
|
@ -402,22 +206,6 @@ inline void bgc_vector3_subtract_fp64(const BgcVector3FP64* minuend, const BgcVe
|
|||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_vector3_subtract_scaled_fp32(const BgcVector3FP32* basic_vector, const BgcVector3FP32* scalable_vector, const float scale, BgcVector3FP32* 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_subtract_scaled_fp64(const BgcVector3FP64* basic_vector, const BgcVector3FP64* scalable_vector, const double scale, BgcVector3FP64* 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;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_vector3_multiply_fp32(const BgcVector3FP32* multiplicand, const float multiplier, BgcVector3FP32* product)
|
||||
|
|
@ -448,39 +236,39 @@ inline void bgc_vector3_divide_fp64(const BgcVector3FP64* dividend, const double
|
|||
|
||||
// ================== Average2 ================== //
|
||||
|
||||
inline void bgc_vector3_get_mean_of_two_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, BgcVector3FP32* result)
|
||||
inline void bgc_vector3_get_mean_of_two_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, BgcVector3FP32* mean)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
result->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||
mean->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||
mean->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||
mean->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_get_mean_of_two_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, BgcVector3FP64* result)
|
||||
inline void bgc_vector3_get_mean_of_two_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, BgcVector3FP64* mean)
|
||||
{
|
||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
result->x3 = (vector1->x3 + vector2->x3) * 0.5;
|
||||
mean->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||
mean->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||
mean->x3 = (vector1->x3 + vector2->x3) * 0.5;
|
||||
}
|
||||
|
||||
// ================== Average3 ================== //
|
||||
|
||||
inline void bgc_vector3_get_mean_of_three_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcVector3FP32* vector3, BgcVector3FP32* result)
|
||||
inline void bgc_vector3_get_mean_of_three_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcVector3FP32* vector3, BgcVector3FP32* mean)
|
||||
{
|
||||
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;
|
||||
mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP32;
|
||||
mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP32;
|
||||
mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP32;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_get_mean_of_three_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcVector3FP64* vector3, BgcVector3FP64* result)
|
||||
inline void bgc_vector3_get_mean_of_three_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcVector3FP64* vector3, BgcVector3FP64* mean)
|
||||
{
|
||||
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;
|
||||
mean->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BGC_ONE_THIRD_FP64;
|
||||
mean->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BGC_ONE_THIRD_FP64;
|
||||
mean->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BGC_ONE_THIRD_FP64;
|
||||
}
|
||||
|
||||
// =================== Linear =================== //
|
||||
|
||||
inline void bgc_vector3_interpolate_linearly_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float phase, BgcVector3FP32* interpolation)
|
||||
inline void bgc_vector3_interpolate_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float phase, BgcVector3FP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -489,7 +277,7 @@ inline void bgc_vector3_interpolate_linearly_fp32(const BgcVector3FP32* vector1,
|
|||
interpolation->x3 = vector1->x3 * counterphase + vector2->x3 * phase;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_interpolate_linearly_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double phase, BgcVector3FP64* interpolation)
|
||||
inline void bgc_vector3_interpolate_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double phase, BgcVector3FP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -498,68 +286,114 @@ inline void bgc_vector3_interpolate_linearly_fp64(const BgcVector3FP64* vector1,
|
|||
interpolation->x3 = vector1->x3 * counterphase + vector2->x3 * phase;
|
||||
}
|
||||
|
||||
// ================== Minimal =================== //
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_vector3_minimize_fp32(const BgcVector3FP32* vector, BgcVector3FP32* minimal)
|
||||
inline void bgc_vector3_make_opposite_fp32(BgcVector3FP32* vector)
|
||||
{
|
||||
if (vector->x1 < minimal->x1) {
|
||||
minimal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 < minimal->x2) {
|
||||
minimal->x2 = vector->x2;
|
||||
}
|
||||
|
||||
if (vector->x3 < minimal->x3) {
|
||||
minimal->x3 = vector->x3;
|
||||
}
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
vector->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_minimize_fp64(const BgcVector3FP64* vector, BgcVector3FP64* minimal)
|
||||
inline void bgc_vector3_make_opposite_fp64(BgcVector3FP64* vector)
|
||||
{
|
||||
if (vector->x1 < minimal->x1) {
|
||||
minimal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 < minimal->x2) {
|
||||
minimal->x2 = vector->x2;
|
||||
}
|
||||
|
||||
if (vector->x3 < minimal->x3) {
|
||||
minimal->x3 = vector->x3;
|
||||
}
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
vector->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
// ================== Maximal =================== //
|
||||
|
||||
inline void bgc_vector3_maximize_fp32(const BgcVector3FP32* vector, BgcVector3FP32* maximal)
|
||||
inline void bgc_vector3_get_opposite_fp32(const BgcVector3FP32* vector, BgcVector3FP32* opposite)
|
||||
{
|
||||
if (vector->x1 > maximal->x1) {
|
||||
maximal->x1 = vector->x1;
|
||||
}
|
||||
|
||||
if (vector->x2 > maximal->x2) {
|
||||
maximal->x2 = vector->x2;
|
||||
}
|
||||
|
||||
if (vector->x3 > maximal->x3) {
|
||||
maximal->x3 = vector->x3;
|
||||
}
|
||||
opposite->x1 = -vector->x1;
|
||||
opposite->x2 = -vector->x2;
|
||||
opposite->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_maximize_fp64(const BgcVector3FP64* vector, BgcVector3FP64* maximal)
|
||||
inline void bgc_vector3_get_opposite_fp64(const BgcVector3FP64* vector, BgcVector3FP64* opposite)
|
||||
{
|
||||
if (vector->x1 > maximal->x1) {
|
||||
maximal->x1 = vector->x1;
|
||||
opposite->x1 = -vector->x1;
|
||||
opposite->x2 = -vector->x2;
|
||||
opposite->x3 = -vector->x3;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_vector3_normalize_fp32(BgcVector3FP32* vector)
|
||||
{
|
||||
const float square_modulus = bgc_vector3_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;
|
||||
}
|
||||
|
||||
if (vector->x3 > maximal->x3) {
|
||||
maximal->x3 = vector->x3;
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
vector->x1 *= multiplier;
|
||||
vector->x2 *= multiplier;
|
||||
vector->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_normalize_fp64(BgcVector3FP64* vector)
|
||||
{
|
||||
const double square_modulus = bgc_vector3_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;
|
||||
vector->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_normalized_fp32(const BgcVector3FP32* vector, BgcVector3FP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_vector3_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
bgc_vector3_copy_fp32(vector, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
bgc_vector3_reset_fp32(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_vector3_multiply_fp32(vector, sqrtf(1.0f / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_normalized_fp64(const BgcVector3FP64* vector, BgcVector3FP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_vector3_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
bgc_vector3_copy_fp64(vector, normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
bgc_vector3_reset_fp64(normalized);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_vector3_multiply_fp64(vector, sqrt(1.0 / square_modulus), normalized);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
|
@ -592,55 +426,55 @@ inline double bgc_vector3_get_triple_product_fp64(const BgcVector3FP64* vector1,
|
|||
|
||||
// =============== Cross Product ================ //
|
||||
|
||||
inline void bgc_vector3_get_cross_product_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, BgcVector3FP32* result)
|
||||
inline void bgc_vector3_get_cross_product_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, BgcVector3FP32* product)
|
||||
{
|
||||
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;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_get_cross_product_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, BgcVector3FP64* result)
|
||||
inline void bgc_vector3_get_cross_product_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, BgcVector3FP64* product)
|
||||
{
|
||||
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;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
// ============ Double Cross Product ============ //
|
||||
|
||||
inline void bgc_vector3_get_double_cross_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcVector3FP32* vector3, BgcVector3FP32* result)
|
||||
inline void bgc_vector3_get_double_cross_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcVector3FP32* vector3, BgcVector3FP32* product)
|
||||
{
|
||||
const float ac = bgc_vector3_get_scalar_product_fp32(vector1, vector3);
|
||||
const float ab = bgc_vector3_get_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;
|
||||
product->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||
product->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||
product->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
||||
}
|
||||
|
||||
inline void bgc_vector3_get_double_cross_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcVector3FP64* vector3, BgcVector3FP64* result)
|
||||
inline void bgc_vector3_get_double_cross_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcVector3FP64* vector3, BgcVector3FP64* product)
|
||||
{
|
||||
const double ac = bgc_vector3_get_scalar_product_fp64(vector1, vector3);
|
||||
const double ab = bgc_vector3_get_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;
|
||||
product->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||
product->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||
product->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float bgc_vector3_get_angle_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcAngleUnitEnum unit);
|
||||
float bgc_vector3_get_angle_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const BgcAngleUnitEnum angle_unit);
|
||||
|
||||
double bgc_vector3_get_angle_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcAngleUnitEnum unit);
|
||||
double bgc_vector3_get_angle_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const BgcAngleUnitEnum angle_unit);
|
||||
|
||||
// =============== Square Distance ============== //
|
||||
|
||||
|
|
@ -676,14 +510,14 @@ inline double bgc_vector3_get_distance_fp64(const BgcVector3FP64* vector1, const
|
|||
|
||||
// ============== Are Close Enough ============== //
|
||||
|
||||
inline int bgc_vector3_are_close_enough_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float distance)
|
||||
inline int bgc_vector3_are_close_enough_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2, const float distance_limit)
|
||||
{
|
||||
return bgc_vector3_get_square_distance_fp32(vector1, vector2) <= distance * distance;
|
||||
return bgc_vector3_get_square_distance_fp32(vector1, vector2) <= distance_limit * distance_limit;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_are_close_enough_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double distance)
|
||||
inline int bgc_vector3_are_close_enough_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2, const double distance_limit)
|
||||
{
|
||||
return bgc_vector3_get_square_distance_fp64(vector1, vector2) <= distance * distance;
|
||||
return bgc_vector3_get_square_distance_fp64(vector1, vector2) <= distance_limit * distance_limit;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
|
@ -711,7 +545,129 @@ inline int bgc_vector3_are_close_fp64(const BgcVector3FP64* 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_vector3_are_parallel_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1);
|
||||
const float square_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
BgcVector3FP32 product;
|
||||
|
||||
bgc_vector3_get_cross_product_fp32(vector1, vector2, &product);
|
||||
|
||||
return bgc_vector3_get_square_modulus_fp32(&product) <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_are_parallel_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1);
|
||||
const double square_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
BgcVector3FP64 product;
|
||||
|
||||
bgc_vector3_get_cross_product_fp64(vector1, vector2, &product);
|
||||
|
||||
return bgc_vector3_get_square_modulus_fp64(&product) <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
// ================= Orthogonal ================= //
|
||||
|
||||
inline int bgc_vector3_are_orthogonal_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1);
|
||||
const float square_modulus2 = bgc_vector3_get_square_modulus_fp32(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const float scalar_product = bgc_vector3_get_scalar_product_fp32(vector1, vector2);
|
||||
|
||||
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_are_orthogonal_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1);
|
||||
const double square_modulus2 = bgc_vector3_get_square_modulus_fp64(vector2);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64 || square_modulus2 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const double scalar_product = bgc_vector3_get_scalar_product_fp64(vector1, vector2);
|
||||
|
||||
return scalar_product * scalar_product <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 * square_modulus2;
|
||||
}
|
||||
|
||||
// ================== Attitude ================== //
|
||||
|
||||
inline int bgc_vector3_get_attitude_fp32(const BgcVector3FP32* vector1, const BgcVector3FP32* vector2)
|
||||
{
|
||||
const float square_modulus1 = bgc_vector3_get_square_modulus_fp32(vector1);
|
||||
const float square_modulus2 = bgc_vector3_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_vector3_get_scalar_product_fp32(vector1, vector2);
|
||||
|
||||
if (scalar_product * scalar_product <= square_limit) {
|
||||
return BGC_ATTITUDE_ORTHOGONAL;
|
||||
}
|
||||
|
||||
BgcVector3FP32 product;
|
||||
|
||||
bgc_vector3_get_cross_product_fp32(vector1, vector2, &product);
|
||||
|
||||
if (bgc_vector3_get_square_modulus_fp32(&product) > square_limit) {
|
||||
return BGC_ATTITUDE_ANY;
|
||||
}
|
||||
|
||||
return scalar_product > 0.0f ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
|
||||
}
|
||||
|
||||
inline int bgc_vector3_get_attitude_fp64(const BgcVector3FP64* vector1, const BgcVector3FP64* vector2)
|
||||
{
|
||||
const double square_modulus1 = bgc_vector3_get_square_modulus_fp64(vector1);
|
||||
const double square_modulus2 = bgc_vector3_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_vector3_get_scalar_product_fp64(vector1, vector2);
|
||||
|
||||
if (scalar_product * scalar_product <= square_limit) {
|
||||
return BGC_ATTITUDE_ORTHOGONAL;
|
||||
}
|
||||
|
||||
BgcVector3FP64 product;
|
||||
|
||||
bgc_vector3_get_cross_product_fp64(vector1, vector2, &product);
|
||||
|
||||
if (bgc_vector3_get_square_modulus_fp64(&product) > square_limit) {
|
||||
return BGC_ATTITUDE_ANY;
|
||||
}
|
||||
|
||||
return scalar_product > 0.0 ? BGC_ATTITUDE_CO_DIRECTIONAL : BGC_ATTITUDE_COUNTER_DIRECTIONAL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue