Переименование типов на на общепринятый формат, отказ от суффикса _t, так как он зарезервирован POSIX
This commit is contained in:
parent
3805354611
commit
0027924f86
26 changed files with 574 additions and 571 deletions
|
@ -13,41 +13,41 @@
|
|||
typedef struct
|
||||
{
|
||||
const float cos, sin;
|
||||
} bgc_tangent_fp32_t;
|
||||
} BgcTangentFP32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const double cos, sin;
|
||||
} bgc_tangent_fp64_t;
|
||||
} BgcTangentFP64;
|
||||
|
||||
// ================= Dark Twins ================= //
|
||||
|
||||
typedef struct {
|
||||
float cos, sin;
|
||||
} _bgc_dark_twin_tangent_fp32_t;
|
||||
} _BgcDarkTwinTangentFP32;
|
||||
|
||||
typedef struct {
|
||||
double cos, sin;
|
||||
} _bgc_dark_twin_tangent_fp64_t;
|
||||
} _BgcDarkTwinTangentFP64;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const bgc_tangent_fp32_t BGC_IDLE_TANGENT_FP32;
|
||||
extern const bgc_tangent_fp64_t BGC_IDLE_TANGENT_FP64;
|
||||
extern const BgcTangentFP32 BGC_IDLE_TANGENT_FP32;
|
||||
extern const BgcTangentFP64 BGC_IDLE_TANGENT_FP64;
|
||||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_tangent_reset_fp32(bgc_tangent_fp32_t* tangent)
|
||||
inline void bgc_tangent_reset_fp32(BgcTangentFP32* tangent)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent;
|
||||
_BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent;
|
||||
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_reset_fp64(bgc_tangent_fp64_t* tangent)
|
||||
inline void bgc_tangent_reset_fp64(BgcTangentFP64* tangent)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent;
|
||||
_BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent;
|
||||
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
|
@ -55,11 +55,11 @@ inline void bgc_tangent_reset_fp64(bgc_tangent_fp64_t* tangent)
|
|||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
inline void bgc_tangent_set_values_fp32(const float x1, const float x2, bgc_tangent_fp32_t* tangent)
|
||||
inline void bgc_tangent_set_values_fp32(const float x1, const float x2, BgcTangentFP32* tangent)
|
||||
{
|
||||
const float square_module = x1 * x1 + x2 * x2;
|
||||
|
||||
_bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent;
|
||||
_BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
@ -80,11 +80,11 @@ inline void bgc_tangent_set_values_fp32(const float x1, const float x2, bgc_tang
|
|||
twin->sin = x2 * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_set_values_fp64(const double x1, const double x2, bgc_tangent_fp64_t* tangent)
|
||||
inline void bgc_tangent_set_values_fp64(const double x1, const double x2, BgcTangentFP64* tangent)
|
||||
{
|
||||
const double square_module = x1 * x1 + x2 * x2;
|
||||
|
||||
_bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent;
|
||||
_BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
@ -107,17 +107,17 @@ inline void bgc_tangent_set_values_fp64(const double x1, const double x2, bgc_ta
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_tangent_copy_fp32(const bgc_tangent_fp32_t* from, bgc_tangent_fp32_t* to)
|
||||
inline void bgc_tangent_copy_fp32(const BgcTangentFP32* from, BgcTangentFP32* to)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)to;
|
||||
_BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)to;
|
||||
|
||||
twin->cos = from->cos;
|
||||
twin->sin = from->sin;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_copy_fp64(const bgc_tangent_fp64_t* from, bgc_tangent_fp64_t* to)
|
||||
inline void bgc_tangent_copy_fp64(const BgcTangentFP64* from, BgcTangentFP64* to)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)to;
|
||||
_BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)to;
|
||||
|
||||
twin->cos = from->cos;
|
||||
twin->sin = from->sin;
|
||||
|
@ -125,33 +125,33 @@ inline void bgc_tangent_copy_fp64(const bgc_tangent_fp64_t* from, bgc_tangent_fp
|
|||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_tangent_swap_fp32(bgc_tangent_fp32_t* tangent1, bgc_tangent_fp32_t* tangent2)
|
||||
inline void bgc_tangent_swap_fp32(BgcTangentFP32* tangent1, BgcTangentFP32* tangent2)
|
||||
{
|
||||
const float cos = tangent1->cos;
|
||||
const float sin = tangent1->sin;
|
||||
|
||||
_bgc_dark_twin_tangent_fp32_t* twin1 = (_bgc_dark_twin_tangent_fp32_t*)tangent1;
|
||||
_BgcDarkTwinTangentFP32* twin1 = (_BgcDarkTwinTangentFP32*)tangent1;
|
||||
|
||||
twin1->cos = tangent2->cos;
|
||||
twin1->sin = tangent2->sin;
|
||||
|
||||
_bgc_dark_twin_tangent_fp32_t* twin2 = (_bgc_dark_twin_tangent_fp32_t*)tangent2;
|
||||
_BgcDarkTwinTangentFP32* twin2 = (_BgcDarkTwinTangentFP32*)tangent2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_swap_fp64(bgc_tangent_fp64_t* tangent1, bgc_tangent_fp64_t* tangent2)
|
||||
inline void bgc_tangent_swap_fp64(BgcTangentFP64* tangent1, BgcTangentFP64* tangent2)
|
||||
{
|
||||
const double cos = tangent1->cos;
|
||||
const double sin = tangent1->sin;
|
||||
|
||||
_bgc_dark_twin_tangent_fp64_t* twin1 = (_bgc_dark_twin_tangent_fp64_t*)tangent1;
|
||||
_BgcDarkTwinTangentFP64* twin1 = (_BgcDarkTwinTangentFP64*)tangent1;
|
||||
|
||||
twin1->cos = tangent2->cos;
|
||||
twin1->sin = tangent2->sin;
|
||||
|
||||
_bgc_dark_twin_tangent_fp64_t* twin2 = (_bgc_dark_twin_tangent_fp64_t*)tangent2;
|
||||
_BgcDarkTwinTangentFP64* twin2 = (_BgcDarkTwinTangentFP64*)tangent2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
|
@ -159,21 +159,21 @@ inline void bgc_tangent_swap_fp64(bgc_tangent_fp64_t* tangent1, bgc_tangent_fp64
|
|||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline void bgc_tangent_set_turn_fp32(const float angle, const bgc_angle_unit_t unit, bgc_tangent_fp32_t* tangent)
|
||||
inline void bgc_tangent_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentFP32* tangent)
|
||||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
|
||||
_bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)tangent;
|
||||
_BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)tangent;
|
||||
|
||||
twin->cos = cosf(radians);
|
||||
twin->sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_set_turn_fp64(const double angle, const bgc_angle_unit_t unit, bgc_tangent_fp64_t* tangent)
|
||||
inline void bgc_tangent_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentFP64* tangent)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
|
||||
_bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)tangent;
|
||||
_BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)tangent;
|
||||
|
||||
twin->cos = cos(radians);
|
||||
twin->sin = sin(radians);
|
||||
|
@ -181,41 +181,41 @@ inline void bgc_tangent_set_turn_fp64(const double angle, const bgc_angle_unit_t
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
inline void bgc_tangent_convert_fp64_to_fp32(const bgc_tangent_fp64_t* from, bgc_tangent_fp32_t* to)
|
||||
inline void bgc_tangent_convert_fp64_to_fp32(const BgcTangentFP64* from, BgcTangentFP32* to)
|
||||
{
|
||||
bgc_tangent_set_values_fp32((float)from->cos, (float)from->sin, to);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_convert_fp32_to_fp64(const bgc_tangent_fp32_t* from, bgc_tangent_fp64_t* to)
|
||||
inline void bgc_tangent_convert_fp32_to_fp64(const BgcTangentFP32* from, BgcTangentFP64* to)
|
||||
{
|
||||
bgc_tangent_set_values_fp64((double)from->cos, (double)from->sin, to);
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
inline void bgc_tangent_invert_fp32(bgc_tangent_fp32_t* tangent)
|
||||
inline void bgc_tangent_invert_fp32(BgcTangentFP32* tangent)
|
||||
{
|
||||
((_bgc_dark_twin_tangent_fp32_t*)tangent)->sin = -tangent->sin;
|
||||
((_BgcDarkTwinTangentFP32*)tangent)->sin = -tangent->sin;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_invert_fp64(bgc_tangent_fp64_t* tangent)
|
||||
inline void bgc_tangent_invert_fp64(BgcTangentFP64* tangent)
|
||||
{
|
||||
((_bgc_dark_twin_tangent_fp64_t*)tangent)->sin = -tangent->sin;
|
||||
((_BgcDarkTwinTangentFP64*)tangent)->sin = -tangent->sin;
|
||||
}
|
||||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
inline void bgc_tangent_set_inverted_fp32(const bgc_tangent_fp32_t* tangent, bgc_tangent_fp32_t* result)
|
||||
inline void bgc_tangent_set_inverted_fp32(const BgcTangentFP32* tangent, BgcTangentFP32* result)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp32_t* twin = (_bgc_dark_twin_tangent_fp32_t*)result;
|
||||
_BgcDarkTwinTangentFP32* twin = (_BgcDarkTwinTangentFP32*)result;
|
||||
|
||||
twin->cos = tangent->cos;
|
||||
twin->sin = -tangent->sin;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_set_inverted_fp64(const bgc_tangent_fp64_t* tangent, bgc_tangent_fp64_t* result)
|
||||
inline void bgc_tangent_set_inverted_fp64(const BgcTangentFP64* tangent, BgcTangentFP64* result)
|
||||
{
|
||||
_bgc_dark_twin_tangent_fp64_t* twin = (_bgc_dark_twin_tangent_fp64_t*)result;
|
||||
_BgcDarkTwinTangentFP64* twin = (_BgcDarkTwinTangentFP64*)result;
|
||||
|
||||
twin->cos = tangent->cos;
|
||||
twin->sin = -tangent->sin;
|
||||
|
@ -223,7 +223,7 @@ inline void bgc_tangent_set_inverted_fp64(const bgc_tangent_fp64_t* tangent, bgc
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_tangent_make_rotation_matrix_fp32(const bgc_tangent_fp32_t* tangent, bgc_matrix2x2_fp32_t* matrix)
|
||||
inline void bgc_tangent_make_rotation_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
matrix->r1c1 = tangent->cos;
|
||||
matrix->r1c2 = -tangent->sin;
|
||||
|
@ -231,7 +231,7 @@ inline void bgc_tangent_make_rotation_matrix_fp32(const bgc_tangent_fp32_t* tang
|
|||
matrix->r2c2 = tangent->cos;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_make_rotation_matrix_fp64(const bgc_tangent_fp64_t* tangent, bgc_matrix2x2_fp64_t* matrix)
|
||||
inline void bgc_tangent_make_rotation_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
matrix->r1c1 = tangent->cos;
|
||||
matrix->r1c2 = -tangent->sin;
|
||||
|
@ -241,7 +241,7 @@ inline void bgc_tangent_make_rotation_matrix_fp64(const bgc_tangent_fp64_t* tang
|
|||
|
||||
// ============== Reverse Matrix ================ //
|
||||
|
||||
inline void bgc_tangent_make_reverse_matrix_fp32(const bgc_tangent_fp32_t* tangent, bgc_matrix2x2_fp32_t* matrix)
|
||||
inline void bgc_tangent_make_reverse_matrix_fp32(const BgcTangentFP32* tangent, BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
matrix->r1c1 = tangent->cos;
|
||||
matrix->r1c2 = tangent->sin;
|
||||
|
@ -249,7 +249,7 @@ inline void bgc_tangent_make_reverse_matrix_fp32(const bgc_tangent_fp32_t* tange
|
|||
matrix->r2c2 = tangent->cos;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_make_reverse_matrix_fp64(const bgc_tangent_fp64_t* tangent, bgc_matrix2x2_fp64_t* matrix)
|
||||
inline void bgc_tangent_make_reverse_matrix_fp64(const BgcTangentFP64* tangent, BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
matrix->r1c1 = tangent->cos;
|
||||
matrix->r1c2 = tangent->sin;
|
||||
|
@ -259,7 +259,7 @@ inline void bgc_tangent_make_reverse_matrix_fp64(const bgc_tangent_fp64_t* tange
|
|||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_tangent_get_angle_fp32(const bgc_tangent_fp32_t* tangent, const bgc_angle_unit_t unit)
|
||||
inline float bgc_tangent_get_angle_fp32(const BgcTangentFP32* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0f - BGC_TWO_EPSYLON_FP32) {
|
||||
return 0.0f;
|
||||
|
@ -280,7 +280,7 @@ inline float bgc_tangent_get_angle_fp32(const bgc_tangent_fp32_t* tangent, const
|
|||
return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit);
|
||||
}
|
||||
|
||||
inline double bgc_tangent_get_angle_fp64(const bgc_tangent_fp64_t* tangent, const bgc_angle_unit_t unit)
|
||||
inline double bgc_tangent_get_angle_fp64(const BgcTangentFP64* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0 - BGC_TWO_EPSYLON_FP64) {
|
||||
return 0.0;
|
||||
|
@ -303,7 +303,7 @@ inline double bgc_tangent_get_angle_fp64(const bgc_tangent_fp64_t* tangent, cons
|
|||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_tangent_combine_fp32(const bgc_tangent_fp32_t* tangent1, const bgc_tangent_fp32_t* tangent2, bgc_tangent_fp32_t* result)
|
||||
inline void bgc_tangent_combine_fp32(const BgcTangentFP32* tangent1, const BgcTangentFP32* tangent2, BgcTangentFP32* result)
|
||||
{
|
||||
bgc_tangent_set_values_fp32(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
|
@ -312,7 +312,7 @@ inline void bgc_tangent_combine_fp32(const bgc_tangent_fp32_t* tangent1, const b
|
|||
);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_combine_fp64(const bgc_tangent_fp64_t* tangent1, const bgc_tangent_fp64_t* tangent2, bgc_tangent_fp64_t* result)
|
||||
inline void bgc_tangent_combine_fp64(const BgcTangentFP64* tangent1, const BgcTangentFP64* tangent2, BgcTangentFP64* result)
|
||||
{
|
||||
bgc_tangent_set_values_fp64(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
|
@ -323,7 +323,7 @@ inline void bgc_tangent_combine_fp64(const bgc_tangent_fp64_t* tangent1, const b
|
|||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_tangent_turn_vector_fp32(const bgc_tangent_fp32_t* tangent, const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result)
|
||||
inline void bgc_tangent_turn_vector_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
{
|
||||
const float x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
||||
const float x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
||||
|
@ -332,7 +332,7 @@ inline void bgc_tangent_turn_vector_fp32(const bgc_tangent_fp32_t* tangent, cons
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_turn_vector_fp64(const bgc_tangent_fp64_t* tangent, const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result)
|
||||
inline void bgc_tangent_turn_vector_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result)
|
||||
{
|
||||
const double x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
||||
const double x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
||||
|
@ -343,7 +343,7 @@ inline void bgc_tangent_turn_vector_fp64(const bgc_tangent_fp64_t* tangent, cons
|
|||
|
||||
// ============ Turn Vector Backward ============ //
|
||||
|
||||
inline void bgc_tangent_turn_vector_back_fp32(const bgc_tangent_fp32_t* tangent, const bgc_vector2_fp32_t* vector, bgc_vector2_fp32_t* result)
|
||||
inline void bgc_tangent_turn_vector_back_fp32(const BgcTangentFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
{
|
||||
const float x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
||||
const float x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
||||
|
@ -352,7 +352,7 @@ inline void bgc_tangent_turn_vector_back_fp32(const bgc_tangent_fp32_t* tangent,
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_turn_vector_back_fp64(const bgc_tangent_fp64_t* tangent, const bgc_vector2_fp64_t* vector, bgc_vector2_fp64_t* result)
|
||||
inline void bgc_tangent_turn_vector_back_fp64(const BgcTangentFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result)
|
||||
{
|
||||
const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
||||
const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue