Переименование типов в соответствии со стилем POSIX, отказ от префикса bg_

This commit is contained in:
Andrey Pokidov 2025-01-13 21:31:26 +07:00
parent d2a25823a5
commit 605afabd94
25 changed files with 1109 additions and 1035 deletions

View file

@ -1,5 +1,5 @@
#ifndef _GEOMETRY_TANGENT_H_
#define _GEOMETRY_TANGENT_H_
#ifndef _BASIC_GEOMETRY_TANGENT_H_
#define _BASIC_GEOMETRY_TANGENT_H_
#include <math.h>
@ -13,12 +13,12 @@
typedef struct
{
const float cos, sin;
} BgFP32Tangent;
} fp32_tangent_t;
typedef struct
{
const double cos, sin;
} BgFP64Tangent;
} fp64_tangent_t;
// ================= Dark Twins ================= //
@ -32,12 +32,12 @@ typedef struct {
// ================= Constants ================== //
extern const BgFP32Tangent BG_FP32_IDLE_TANGENT;
extern const BgFP64Tangent BG_FP64_IDLE_TANGENT;
extern const fp32_tangent_t FP32_IDLE_TANGENT;
extern const fp64_tangent_t FP64_IDLE_TANGENT;
// =================== Reset ==================== //
static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
static inline void fp32_tangent_reset(fp32_tangent_t* tangent)
{
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
@ -45,7 +45,7 @@ static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
twin->sin = 0.0f;
}
static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
static inline void fp64_tangent_reset(fp64_tangent_t* tangent)
{
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
@ -55,7 +55,7 @@ static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
// ==================== Set ===================== //
static inline void bg_fp32_tangent_set_values(const float x1, const float x2, BgFP32Tangent* tangent)
static inline void fp32_tangent_set_values(const float x1, const float x2, fp32_tangent_t* tangent)
{
const float square_module = x1 * x1 + x2 * x2;
@ -64,11 +64,11 @@ static inline void bg_fp32_tangent_set_values(const float x1, const float x2, Bg
twin->cos = x1;
twin->sin = x2;
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
if (1.0f - FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + FP32_TWO_EPSYLON) {
return;
}
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
if (square_module <= FP32_SQUARE_EPSYLON) {
twin->cos = 1.0f;
twin->sin = 0.0f;
return;
@ -80,7 +80,7 @@ static inline void bg_fp32_tangent_set_values(const float x1, const float x2, Bg
twin->sin = x2 * multiplier;
}
static inline void bg_fp64_tangent_set_values(const double x1, const double x2, BgFP64Tangent* tangent)
static inline void fp64_tangent_set_values(const double x1, const double x2, fp64_tangent_t* tangent)
{
const double square_module = x1 * x1 + x2 * x2;
@ -89,11 +89,11 @@ static inline void bg_fp64_tangent_set_values(const double x1, const double x2,
twin->cos = x1;
twin->sin = x2;
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
if (1.0 - FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + FP64_TWO_EPSYLON) {
return;
}
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
if (square_module <= FP64_SQUARE_EPSYLON) {
twin->cos = 1.0;
twin->sin = 0.0;
return;
@ -107,7 +107,7 @@ static inline void bg_fp64_tangent_set_values(const double x1, const double x2,
// ==================== Copy ==================== //
static inline void bg_fp32_tangent_copy(const BgFP32Tangent* from, BgFP32Tangent* to)
static inline void fp32_tangent_copy(const fp32_tangent_t* from, fp32_tangent_t* to)
{
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)to;
@ -115,7 +115,7 @@ static inline void bg_fp32_tangent_copy(const BgFP32Tangent* from, BgFP32Tangent
twin->sin = from->sin;
}
static inline void bg_fp64_tangent_copy(const BgFP64Tangent* from, BgFP64Tangent* to)
static inline void fp64_tangent_copy(const fp64_tangent_t* from, fp64_tangent_t* to)
{
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)to;
@ -125,7 +125,7 @@ static inline void bg_fp64_tangent_copy(const BgFP64Tangent* from, BgFP64Tangent
// ==================== Swap ==================== //
static inline void bg_fp32_tangent_swap(BgFP32Tangent* tangent1, BgFP32Tangent* tangent2)
static inline void fp32_tangent_swap(fp32_tangent_t* tangent1, fp32_tangent_t* tangent2)
{
const float cos = tangent1->cos;
const float sin = tangent1->sin;
@ -141,7 +141,7 @@ static inline void bg_fp32_tangent_swap(BgFP32Tangent* tangent1, BgFP32Tangent*
twin2->sin = sin;
}
static inline void bg_fp64_tangent_swap(BgFP64Tangent* tangent1, BgFP64Tangent* tangent2)
static inline void fp64_tangent_swap(fp64_tangent_t* tangent1, fp64_tangent_t* tangent2)
{
const double cos = tangent1->cos;
const double sin = tangent1->sin;
@ -159,9 +159,9 @@ static inline void bg_fp64_tangent_swap(BgFP64Tangent* tangent1, BgFP64Tangent*
// ================== Set Turn ================== //
static inline void bg_fp32_tangent_set_turn(const float angle, const angle_unit_t unit, BgFP32Tangent* tangent)
static inline void fp32_tangent_set_turn(const float angle, const angle_unit_t unit, fp32_tangent_t* tangent)
{
const float radians = bg_fp32_angle_to_radians(angle, unit);
const float radians = fp32_angle_to_radians(angle, unit);
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
@ -169,9 +169,9 @@ static inline void bg_fp32_tangent_set_turn(const float angle, const angle_unit_
twin->sin = sinf(radians);
}
static inline void bg_fp64_tangent_set_turn(const double angle, const angle_unit_t unit, BgFP64Tangent* tangent)
static inline void fp64_tangent_set_turn(const double angle, const angle_unit_t unit, fp64_tangent_t* tangent)
{
const double radians = bg_fp64_angle_to_radians(angle, unit);
const double radians = fp64_angle_to_radians(angle, unit);
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
@ -181,31 +181,31 @@ static inline void bg_fp64_tangent_set_turn(const double angle, const angle_unit
// ============= Copy to twin type ============== //
static inline void bg_fp32_tangent_set_from_fp64(const BgFP64Tangent* from, BgFP32Tangent* to)
static inline void fp32_tangent_set_from_fp64(const fp64_tangent_t* from, fp32_tangent_t* to)
{
bg_fp32_tangent_set_values((float)from->cos, (float)from->sin, to);
fp32_tangent_set_values((float)from->cos, (float)from->sin, to);
}
static inline void bg_fp64_tangent_set_from_fp32(const BgFP32Tangent* from, BgFP64Tangent* to)
static inline void fp64_tangent_set_from_fp32(const fp32_tangent_t* from, fp64_tangent_t* to)
{
bg_fp64_tangent_set_values((double)from->cos, (double)from->sin, to);
fp64_tangent_set_values((double)from->cos, (double)from->sin, to);
}
// ================= Inversion ================== //
static inline void bg_fp32_tangent_invert(BgFP32Tangent* tangent)
static inline void fp32_tangent_invert(fp32_tangent_t* tangent)
{
((__BgFP32DarkTwinTangent*)tangent)->sin = -tangent->sin;
}
static inline void bg_fp64_tangent_invert(BgFP64Tangent* tangent)
static inline void fp64_tangent_invert(fp64_tangent_t* tangent)
{
((__BgFP64DarkTwinTangent*)tangent)->sin = -tangent->sin;
}
// ================ Set Inverted ================ //
static inline void bg_fp32_tangent_set_inverted(const BgFP32Tangent* tangent, BgFP32Tangent* result)
static inline void fp32_tangent_set_inverted(const fp32_tangent_t* tangent, fp32_tangent_t* result)
{
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)result;
@ -213,7 +213,7 @@ static inline void bg_fp32_tangent_set_inverted(const BgFP32Tangent* tangent, Bg
twin->sin = -tangent->sin;
}
static inline void bg_fp64_tangent_set_inverted(const BgFP64Tangent* tangent, BgFP64Tangent* result)
static inline void fp64_tangent_set_inverted(const fp64_tangent_t* tangent, fp64_tangent_t* result)
{
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)result;
@ -223,7 +223,7 @@ static inline void bg_fp64_tangent_set_inverted(const BgFP64Tangent* tangent, Bg
// ============== Rotation Matrix =============== //
static inline void bg_fp32_tangent_make_rotation_matrix(const BgFP32Tangent* tangent, BgFP32Matrix2x2* matrix)
static inline void fp32_tangent_make_rotation_matrix(const fp32_tangent_t* tangent, fp32_matrix2x2_t* matrix)
{
matrix->r1c1 = tangent->cos;
matrix->r1c2 = -tangent->sin;
@ -231,7 +231,7 @@ static inline void bg_fp32_tangent_make_rotation_matrix(const BgFP32Tangent* tan
matrix->r2c2 = tangent->cos;
}
static inline void bg_fp64_tangent_make_rotation_matrix(const BgFP64Tangent* tangent, BgFP64Matrix2x2* matrix)
static inline void fp64_tangent_make_rotation_matrix(const fp64_tangent_t* tangent, fp64_matrix2x2_t* matrix)
{
matrix->r1c1 = tangent->cos;
matrix->r1c2 = -tangent->sin;
@ -241,7 +241,7 @@ static inline void bg_fp64_tangent_make_rotation_matrix(const BgFP64Tangent* tan
// ============== Reverse Matrix ================ //
static inline void bg_fp32_tangent_make_reverse_matrix(const BgFP32Tangent* tangent, BgFP32Matrix2x2* matrix)
static inline void fp32_tangent_make_reverse_matrix(const fp32_tangent_t* tangent, fp32_matrix2x2_t* matrix)
{
matrix->r1c1 = tangent->cos;
matrix->r1c2 = tangent->sin;
@ -249,7 +249,7 @@ static inline void bg_fp32_tangent_make_reverse_matrix(const BgFP32Tangent* tang
matrix->r2c2 = tangent->cos;
}
static inline void bg_fp64_tangent_make_reverse_matrix(const BgFP64Tangent* tangent, BgFP64Matrix2x2* matrix)
static inline void fp64_tangent_make_reverse_matrix(const fp64_tangent_t* tangent, fp64_matrix2x2_t* matrix)
{
matrix->r1c1 = tangent->cos;
matrix->r1c2 = tangent->sin;
@ -259,62 +259,62 @@ static inline void bg_fp64_tangent_make_reverse_matrix(const BgFP64Tangent* tang
// =================== Angle =================== //
static inline float bg_fp32_tangent_get_angle(const BgFP32Tangent* tangent, const angle_unit_t unit)
static inline float fp32_tangent_get_angle(const fp32_tangent_t* tangent, const angle_unit_t unit)
{
if (tangent->cos >= 1.0f - BG_FP32_TWO_EPSYLON) {
if (tangent->cos >= 1.0f - FP32_TWO_EPSYLON) {
return 0.0f;
}
if (tangent->cos <= -1.0f + BG_FP32_TWO_EPSYLON) {
return bg_fp32_angle_get_half_circle(unit);
if (tangent->cos <= -1.0f + FP32_TWO_EPSYLON) {
return fp32_angle_get_half_circle(unit);
}
if (tangent->sin >= 1.0f - BG_FP32_TWO_EPSYLON) {
return bg_fp32_angle_get_quater_circle(unit);
if (tangent->sin >= 1.0f - FP32_TWO_EPSYLON) {
return fp32_angle_get_quater_circle(unit);
}
if (tangent->sin <= -1.0f + BG_FP32_TWO_EPSYLON) {
return 0.75f * bg_fp32_angle_get_full_circle(unit);
if (tangent->sin <= -1.0f + FP32_TWO_EPSYLON) {
return 0.75f * fp32_angle_get_full_circle(unit);
}
return bg_fp32_radians_to_units(atan2f(tangent->cos, tangent->sin), unit);
return fp32_radians_to_units(atan2f(tangent->cos, tangent->sin), unit);
}
static inline double bg_fp64_tangent_get_angle(const BgFP64Tangent* tangent, const angle_unit_t unit)
static inline double fp64_tangent_get_angle(const fp64_tangent_t* tangent, const angle_unit_t unit)
{
if (tangent->cos >= 1.0 - BG_FP64_TWO_EPSYLON) {
if (tangent->cos >= 1.0 - FP64_TWO_EPSYLON) {
return 0.0;
}
if (tangent->cos <= -1.0 + BG_FP64_TWO_EPSYLON) {
return bg_fp64_angle_get_half_circle(unit);
if (tangent->cos <= -1.0 + FP64_TWO_EPSYLON) {
return fp64_angle_get_half_circle(unit);
}
if (tangent->sin >= 1.0 - BG_FP64_TWO_EPSYLON) {
return bg_fp64_angle_get_quater_circle(unit);
if (tangent->sin >= 1.0 - FP64_TWO_EPSYLON) {
return fp64_angle_get_quater_circle(unit);
}
if (tangent->sin <= -1.0 + BG_FP64_TWO_EPSYLON) {
return 0.75 * bg_fp64_angle_get_full_circle(unit);
if (tangent->sin <= -1.0 + FP64_TWO_EPSYLON) {
return 0.75 * fp64_angle_get_full_circle(unit);
}
return bg_fp64_radians_to_units(atan2(tangent->cos, tangent->sin), unit);
return fp64_radians_to_units(atan2(tangent->cos, tangent->sin), unit);
}
// ================ Combination ================= //
static inline void bg_fp32_tangent_combine(const BgFP32Tangent* tangent1, const BgFP32Tangent* tangent2, BgFP32Tangent* result)
static inline void fp32_tangent_combine(const fp32_tangent_t* tangent1, const fp32_tangent_t* tangent2, fp32_tangent_t* result)
{
bg_fp32_tangent_set_values(
fp32_tangent_set_values(
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
result
);
}
static inline void bg_fp64_tangent_combine(const BgFP64Tangent* tangent1, const BgFP64Tangent* tangent2, BgFP64Tangent* result)
static inline void fp64_tangent_combine(const fp64_tangent_t* tangent1, const fp64_tangent_t* tangent2, fp64_tangent_t* result)
{
bg_fp64_tangent_set_values(
fp64_tangent_set_values(
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
result
@ -323,7 +323,7 @@ static inline void bg_fp64_tangent_combine(const BgFP64Tangent* tangent1, const
// ================ Turn Vector ================= //
static inline void bg_fp32_tangent_turn(const BgFP32Tangent* tangent, const BgFP32Vector2* vector, BgFP32Vector2* result)
static inline void fp32_tangent_turn(const fp32_tangent_t* tangent, const fp32_vector2_t* vector, fp32_vector2_t* 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 @@ static inline void bg_fp32_tangent_turn(const BgFP32Tangent* tangent, const BgFP
result->x2 = x2;
}
static inline void bg_fp64_tangent_turn(const BgFP64Tangent* tangent, const BgFP64Vector2* vector, BgFP64Vector2* result)
static inline void fp64_tangent_turn(const fp64_tangent_t* tangent, const fp64_vector2_t* vector, fp64_vector2_t* 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 @@ static inline void bg_fp64_tangent_turn(const BgFP64Tangent* tangent, const BgFP
// ============ Turn Vector Backward ============ //
static inline void bg_fp32_tangent_turn_back(const BgFP32Tangent* tangent, const BgFP32Vector2* vector, BgFP32Vector2* result)
static inline void fp32_tangent_turn_back(const fp32_tangent_t* tangent, const fp32_vector2_t* vector, fp32_vector2_t* 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 @@ static inline void bg_fp32_tangent_turn_back(const BgFP32Tangent* tangent, const
result->x2 = x2;
}
static inline void bg_fp64_tangent_turn_back(const BgFP64Tangent* tangent, const BgFP64Vector2* vector, BgFP64Vector2* result)
static inline void fp64_tangent_turn_back(const fp64_tangent_t* tangent, const fp64_vector2_t* vector, fp64_vector2_t* result)
{
const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;