Переименование типов в соответствии со стилем POSIX, отказ от префикса bg_
This commit is contained in:
parent
d2a25823a5
commit
605afabd94
25 changed files with 1109 additions and 1035 deletions
|
|
@ -1,32 +1,32 @@
|
|||
#ifndef _GEOMETRY_ANGLE_H_
|
||||
#define _GEOMETRY_ANGLE_H_
|
||||
#ifndef _BASIC_GEOMETRY_ANGLE_H_
|
||||
#define _BASIC_GEOMETRY_ANGLE_H_
|
||||
|
||||
#include <math.h>
|
||||
#include "basis.h"
|
||||
|
||||
#define BG_FP32_PI 3.1415926536f
|
||||
#define BG_FP32_TWO_PI 6.2831853072f
|
||||
#define BG_FP32_HALF_OF_PI 1.5707963268f
|
||||
#define BG_FP32_THIRD_OF_PI 1.0471975512f
|
||||
#define BG_FP32_FOURTH_OF_PI 0.7853981634f
|
||||
#define BG_FP32_SIXTH_OF_PI 0.5235987756f
|
||||
#define FP32_PI 3.1415926536f
|
||||
#define FP32_TWO_PI 6.2831853072f
|
||||
#define FP32_HALF_OF_PI 1.5707963268f
|
||||
#define FP32_THIRD_OF_PI 1.0471975512f
|
||||
#define FP32_FOURTH_OF_PI 0.7853981634f
|
||||
#define FP32_SIXTH_OF_PI 0.5235987756f
|
||||
|
||||
#define BG_FP32_DEGREES_IN_RADIAN 57.295779513f
|
||||
#define BG_FP32_TURNS_IN_RADIAN 0.1591549431f
|
||||
#define BG_FP32_RADIANS_IN_DEGREE 1.745329252E-2f
|
||||
#define BG_FP32_TURNS_IN_DEGREE 2.7777777778E-3f
|
||||
#define FP32_DEGREES_IN_RADIAN 57.295779513f
|
||||
#define FP32_TURNS_IN_RADIAN 0.1591549431f
|
||||
#define FP32_RADIANS_IN_DEGREE 1.745329252E-2f
|
||||
#define FP32_TURNS_IN_DEGREE 2.7777777778E-3f
|
||||
|
||||
#define BG_FP64_PI 3.14159265358979324
|
||||
#define BG_FP64_TWO_PI 6.28318530717958648
|
||||
#define BG_FP64_HALF_OF_PI 1.57079632679489662
|
||||
#define BG_FP64_THIRD_OF_PI 1.04719755119659775
|
||||
#define BG_FP64_FOURTH_OF_PI 0.78539816339744831
|
||||
#define BG_FP64_SIXTH_OF_PI 0.523598775598298873
|
||||
#define FP64_PI 3.14159265358979324
|
||||
#define FP64_TWO_PI 6.28318530717958648
|
||||
#define FP64_HALF_OF_PI 1.57079632679489662
|
||||
#define FP64_THIRD_OF_PI 1.04719755119659775
|
||||
#define FP64_FOURTH_OF_PI 0.78539816339744831
|
||||
#define FP64_SIXTH_OF_PI 0.523598775598298873
|
||||
|
||||
#define BG_FP64_DEGREES_IN_RADIAN 57.2957795130823209
|
||||
#define BG_FP64_TURNS_IN_RADIAN 0.159154943091895336
|
||||
#define BG_FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2
|
||||
#define BG_FP64_TURNS_IN_DEGREE 2.77777777777777778E-3
|
||||
#define FP64_DEGREES_IN_RADIAN 57.2957795130823209
|
||||
#define FP64_TURNS_IN_RADIAN 0.159154943091895336
|
||||
#define FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2
|
||||
#define FP64_TURNS_IN_DEGREE 2.77777777777777778E-3
|
||||
|
||||
typedef enum {
|
||||
BG_ANGLE_UNIT_RADIANS = 1,
|
||||
|
|
@ -52,51 +52,51 @@ typedef enum {
|
|||
|
||||
// ========= Convert radians to degrees ========= //
|
||||
|
||||
static inline float bg_fp32_radians_to_degrees(const float radians)
|
||||
static inline float fp32_radians_to_degrees(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
return radians * FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_to_degrees(const double radians)
|
||||
static inline double fp64_radians_to_degrees(const double radians)
|
||||
{
|
||||
return radians * BG_FP64_DEGREES_IN_RADIAN;
|
||||
return radians * FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========== Convert radians to turns ========== //
|
||||
|
||||
static inline float bg_fp32_radians_to_turns(const float radians)
|
||||
static inline float fp32_radians_to_turns(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
return radians * FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_to_turns(const double radians)
|
||||
static inline double fp64_radians_to_turns(const double radians)
|
||||
{
|
||||
return radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
return radians * FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========= Convert radians to any unit ======== //
|
||||
|
||||
static inline float bg_fp32_radians_to_units(const float radians, const angle_unit_t to_unit)
|
||||
static inline float fp32_radians_to_units(const float radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
return radians * FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
return radians * FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_to_units(const double radians, const angle_unit_t to_unit)
|
||||
static inline double fp64_radians_to_units(const double radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return radians * BG_FP64_DEGREES_IN_RADIAN;
|
||||
return radians * FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
return radians * FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
|
|
@ -104,20 +104,20 @@ static inline double bg_fp64_radians_to_units(const double radians, const angle_
|
|||
|
||||
// ============ Normalize radians ============= //
|
||||
|
||||
static inline float bg_fp32_radians_normalize(const float radians, const angle_range_t range)
|
||||
static inline float fp32_radians_normalize(const float radians, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= radians && radians < BG_FP32_TWO_PI) {
|
||||
if (0.0f <= radians && radians < FP32_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-BG_FP32_PI < radians && radians <= BG_FP32_PI) {
|
||||
if (-FP32_PI < radians && radians <= FP32_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
float turns = radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
float turns = radians * FP32_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
|
|
@ -125,23 +125,23 @@ static inline float bg_fp32_radians_normalize(const float radians, const angle_r
|
|||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
return turns * FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_normalize(const double radians, const angle_range_t range)
|
||||
static inline double fp64_radians_normalize(const double radians, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= radians && radians < BG_FP64_TWO_PI) {
|
||||
if (0.0 <= radians && radians < FP64_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-BG_FP64_PI < radians && radians <= BG_FP64_PI) {
|
||||
if (-FP64_PI < radians && radians <= FP64_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
double turns = radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
double turns = radians * FP64_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
|
|
@ -149,58 +149,58 @@ static inline double bg_fp64_radians_normalize(const double radians, const angle
|
|||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
return turns * FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// !================= Degrees ==================! //
|
||||
|
||||
// ========= Convert degrees to radians ========= //
|
||||
|
||||
static inline float bg_fp32_degrees_to_radians(const float degrees)
|
||||
static inline float fp32_degrees_to_radians(const float degrees)
|
||||
{
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
return degrees * FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_radians(const double degrees)
|
||||
static inline double fp64_degrees_to_radians(const double degrees)
|
||||
{
|
||||
return degrees * BG_FP64_RADIANS_IN_DEGREE;
|
||||
return degrees * FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert degrees to turns ========== //
|
||||
|
||||
static inline float bg_fp32_degrees_to_turns(const float radians)
|
||||
static inline float fp32_degrees_to_turns(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_TURNS_IN_DEGREE;
|
||||
return radians * FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_turns(const double radians)
|
||||
static inline double fp64_degrees_to_turns(const double radians)
|
||||
{
|
||||
return radians * BG_FP64_TURNS_IN_DEGREE;
|
||||
return radians * FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========= Convert degreess to any unit ======== //
|
||||
|
||||
static inline float bg_fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit)
|
||||
static inline float fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
return degrees * FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
return degrees * FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit)
|
||||
static inline double fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return degrees * BG_FP64_RADIANS_IN_DEGREE;
|
||||
return degrees * FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
return degrees * FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
|
|
@ -208,7 +208,7 @@ static inline double bg_fp64_degrees_to_units(const double degrees, const angle_
|
|||
|
||||
// ============ Normalize degrees ============= //
|
||||
|
||||
static inline float bg_fp32_degrees_normalize(const float degrees, const angle_range_t range)
|
||||
static inline float fp32_degrees_normalize(const float degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= degrees && degrees < 360.0f) {
|
||||
|
|
@ -221,7 +221,7 @@ static inline float bg_fp32_degrees_normalize(const float degrees, const angle_r
|
|||
}
|
||||
}
|
||||
|
||||
float turns = degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
float turns = degrees * FP32_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ static inline float bg_fp32_degrees_normalize(const float degrees, const angle_r
|
|||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_normalize(const double degrees, const angle_range_t range)
|
||||
static inline double fp64_degrees_normalize(const double degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= degrees && degrees < 360.0) {
|
||||
|
|
@ -245,7 +245,7 @@ static inline double bg_fp64_degrees_normalize(const double degrees, const angle
|
|||
}
|
||||
}
|
||||
|
||||
double turns = degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
double turns = degrees * FP64_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
|
|
@ -260,34 +260,34 @@ static inline double bg_fp64_degrees_normalize(const double degrees, const angle
|
|||
|
||||
// ========== Convert turns to radians ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_radians(const float turns)
|
||||
static inline float fp32_turns_to_radians(const float turns)
|
||||
{
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
return turns * FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_radians(const double turns)
|
||||
static inline double fp64_turns_to_radians(const double turns)
|
||||
{
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
return turns * FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ========== Convert turns to degrees ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_degrees(const float turns)
|
||||
static inline float fp32_turns_to_degrees(const float turns)
|
||||
{
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_degrees(const double turns)
|
||||
static inline double fp64_turns_to_degrees(const double turns)
|
||||
{
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// ========= Convert turns to any unit ======== //
|
||||
|
||||
static inline float bg_fp32_turns_to_units(const float turns, const angle_unit_t to_unit)
|
||||
static inline float fp32_turns_to_units(const float turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
return turns * FP32_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
|
|
@ -297,10 +297,10 @@ static inline float bg_fp32_turns_to_units(const float turns, const angle_unit_t
|
|||
return turns;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_units(const double turns, const angle_unit_t to_unit)
|
||||
static inline double fp64_turns_to_units(const double turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
return turns * FP64_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
|
|
@ -312,7 +312,7 @@ static inline double bg_fp64_turns_to_units(const double turns, const angle_unit
|
|||
|
||||
// ============= Normalize turns ============== //
|
||||
|
||||
static inline float bg_fp32_turns_normalize(const float turns, const angle_range_t range)
|
||||
static inline float fp32_turns_normalize(const float turns, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= turns && turns < 1.0f) {
|
||||
|
|
@ -334,7 +334,7 @@ static inline float bg_fp32_turns_normalize(const float turns, const angle_range
|
|||
return rest;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_normalize(const double turns, const angle_range_t range)
|
||||
static inline double fp64_turns_normalize(const double turns, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= turns && turns < 1.0) {
|
||||
|
|
@ -360,27 +360,27 @@ static inline double bg_fp64_turns_normalize(const double turns, const angle_ran
|
|||
|
||||
// ========= Convert any unit to radians ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_radians(const float angle, const angle_unit_t unit)
|
||||
static inline float fp32_angle_to_radians(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP32_RADIANS_IN_DEGREE;
|
||||
return angle * FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP32_TWO_PI;
|
||||
return angle * FP32_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_to_radians(const double angle, const angle_unit_t unit)
|
||||
static inline double fp64_angle_to_radians(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP64_RADIANS_IN_DEGREE;
|
||||
return angle * FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP64_TWO_PI;
|
||||
return angle * FP64_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
|
|
@ -388,10 +388,10 @@ static inline double bg_fp64_angle_to_radians(const double angle, const angle_un
|
|||
|
||||
// ========= Convert any unit to degreess ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_degrees(const float angle, const angle_unit_t unit)
|
||||
static inline float fp32_angle_to_degrees(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP32_DEGREES_IN_RADIAN;
|
||||
return angle * FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
|
|
@ -401,10 +401,10 @@ static inline float bg_fp32_angle_to_degrees(const float angle, const angle_unit
|
|||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_to_degrees(const double angle, const angle_unit_t unit)
|
||||
static inline double fp64_angle_to_degrees(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP64_DEGREES_IN_RADIAN;
|
||||
return angle * FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
|
|
@ -416,27 +416,27 @@ static inline double bg_fp64_angle_to_degrees(const double angle, const angle_un
|
|||
|
||||
// ========= Convert any unit to turns ======== //
|
||||
|
||||
static inline float bg_fp32_angle_to_turns(const float angle, const angle_unit_t unit)
|
||||
static inline float fp32_angle_to_turns(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP32_TURNS_IN_RADIAN;
|
||||
return angle * FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP32_TURNS_IN_DEGREE;
|
||||
return angle * FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_to_turns(const double angle, const angle_unit_t unit)
|
||||
static inline double fp64_angle_to_turns(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return angle * BG_FP64_TURNS_IN_RADIAN;
|
||||
return angle * FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP64_TURNS_IN_DEGREE;
|
||||
return angle * FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
|
|
@ -444,7 +444,7 @@ static inline double bg_fp64_angle_to_turns(const double angle, const angle_unit
|
|||
|
||||
// ============= Get Full Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit)
|
||||
static inline float fp32_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0f;
|
||||
|
|
@ -454,10 +454,10 @@ static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit)
|
|||
return 1.0f;
|
||||
}
|
||||
|
||||
return BG_FP32_TWO_PI;
|
||||
return FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit)
|
||||
static inline double fp64_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0;
|
||||
|
|
@ -467,12 +467,12 @@ static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit)
|
|||
return 1.0;
|
||||
}
|
||||
|
||||
return BG_FP64_TWO_PI;
|
||||
return FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit)
|
||||
static inline float fp32_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0f;
|
||||
|
|
@ -482,10 +482,10 @@ static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit)
|
|||
return 0.5f;
|
||||
}
|
||||
|
||||
return BG_FP32_PI;
|
||||
return FP32_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit)
|
||||
static inline double fp64_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0;
|
||||
|
|
@ -495,12 +495,12 @@ static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit)
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
return BG_FP64_PI;
|
||||
return FP64_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit)
|
||||
static inline float fp32_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0f;
|
||||
|
|
@ -510,10 +510,10 @@ static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit)
|
|||
return 0.25f;
|
||||
}
|
||||
|
||||
return BG_FP32_HALF_OF_PI;
|
||||
return FP32_HALF_OF_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit)
|
||||
static inline double fp64_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0;
|
||||
|
|
@ -523,35 +523,35 @@ static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit)
|
|||
return 0.25;
|
||||
}
|
||||
|
||||
return BG_FP64_HALF_OF_PI;
|
||||
return FP64_HALF_OF_PI;
|
||||
}
|
||||
|
||||
// ================ Normalize ================= //
|
||||
|
||||
static inline float bg_fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range)
|
||||
static inline float fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp32_degrees_normalize(angle, range);
|
||||
return fp32_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp32_turns_normalize(angle, range);
|
||||
return fp32_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_fp32_radians_normalize(angle, range);
|
||||
return fp32_radians_normalize(angle, range);
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range)
|
||||
static inline double fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp64_degrees_normalize(angle, range);
|
||||
return fp64_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp64_turns_normalize(angle, range);
|
||||
return fp64_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_fp64_radians_normalize(angle, range);
|
||||
return fp64_radians_normalize(angle, range);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,56 +1,56 @@
|
|||
#ifndef __GEOMETRY__TYPES_H_
|
||||
#define __GEOMETRY__TYPES_H_
|
||||
|
||||
#define BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
|
||||
#define FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
|
||||
|
||||
#define BG_FP32_EPSYLON 5E-7f
|
||||
#define BG_FP32_TWO_EPSYLON 1E-6f
|
||||
#define BG_FP32_SQUARE_EPSYLON 2.5E-13f
|
||||
#define FP32_EPSYLON 5E-7f
|
||||
#define FP32_TWO_EPSYLON 1E-6f
|
||||
#define FP32_SQUARE_EPSYLON 2.5E-13f
|
||||
|
||||
#define BG_FP32_ONE_THIRD 0.333333333f
|
||||
#define BG_FP32_ONE_SIXTH 0.166666667f
|
||||
#define BG_FP32_ONE_NINETH 0.111111111f
|
||||
#define FP32_ONE_THIRD 0.333333333f
|
||||
#define FP32_ONE_SIXTH 0.166666667f
|
||||
#define FP32_ONE_NINETH 0.111111111f
|
||||
|
||||
#define BG_FP32_GOLDEN_RATIO_HIGH 1.618034f
|
||||
#define BG_FP32_GOLDEN_RATIO_LOW 0.618034f
|
||||
#define FP32_GOLDEN_RATIO_HIGH 1.618034f
|
||||
#define FP32_GOLDEN_RATIO_LOW 0.618034f
|
||||
|
||||
#define BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0
|
||||
#define FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0
|
||||
|
||||
#define BG_FP64_EPSYLON 5E-14
|
||||
#define BG_FP64_TWO_EPSYLON 1E-13
|
||||
#define BG_FP64_SQUARE_EPSYLON 2.5E-27
|
||||
#define FP64_EPSYLON 5E-14
|
||||
#define FP64_TWO_EPSYLON 1E-13
|
||||
#define FP64_SQUARE_EPSYLON 2.5E-27
|
||||
|
||||
#define BG_FP64_ONE_THIRD 0.333333333333333333
|
||||
#define BG_FP64_ONE_SIXTH 0.166666666666666667
|
||||
#define BG_FP64_ONE_NINETH 0.111111111111111111
|
||||
#define FP64_ONE_THIRD 0.333333333333333333
|
||||
#define FP64_ONE_SIXTH 0.166666666666666667
|
||||
#define FP64_ONE_NINETH 0.111111111111111111
|
||||
|
||||
#define BG_FP64_GOLDEN_RATIO_HIGH 1.61803398874989485
|
||||
#define BG_FP64_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
#define FP64_GOLDEN_RATIO_HIGH 1.61803398874989485
|
||||
#define FP64_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
|
||||
static inline int bg_fp32_are_equal(const float value1, const float value2)
|
||||
static inline int fp32_are_equal(const float value1, const float value2)
|
||||
{
|
||||
if (-BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -BG_FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP32_EPSYLON;
|
||||
if (-FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP32_EPSYLON;
|
||||
}
|
||||
|
||||
if (value1 < 0.0f) {
|
||||
return (1.0f + BG_FP32_EPSYLON) * value2 <= value1 && (1.0f + BG_FP32_EPSYLON) * value1 <= value2;
|
||||
return (1.0f + FP32_EPSYLON) * value2 <= value1 && (1.0f + FP32_EPSYLON) * value1 <= value2;
|
||||
}
|
||||
|
||||
return value2 <= value1 * (1.0f + BG_FP32_EPSYLON) && value1 <= value2 * (1.0f + BG_FP32_EPSYLON);
|
||||
return value2 <= value1 * (1.0f + FP32_EPSYLON) && value1 <= value2 * (1.0f + FP32_EPSYLON);
|
||||
}
|
||||
|
||||
static inline int bg_fp64_are_equal(const double value1, const double value2)
|
||||
static inline int fp64_are_equal(const double value1, const double value2)
|
||||
{
|
||||
if (-BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -BG_FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP64_EPSYLON;
|
||||
if (-FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return -FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP64_EPSYLON;
|
||||
}
|
||||
|
||||
if (value1 < 0.0) {
|
||||
return (1.0 + BG_FP64_EPSYLON) * value2 <= value1 && (1.0 + BG_FP64_EPSYLON) * value1 <= value2;
|
||||
return (1.0 + FP64_EPSYLON) * value2 <= value1 && (1.0 + FP64_EPSYLON) * value1 <= value2;
|
||||
}
|
||||
|
||||
return value2 <= value1 * (1.0 + BG_FP64_EPSYLON) && value1 <= value2 * (1.0 + BG_FP64_EPSYLON);
|
||||
return value2 <= value1 * (1.0 + FP64_EPSYLON) && value1 <= value2 * (1.0 + FP64_EPSYLON);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _GEOMETRY_MATRIX2X2_H_
|
||||
#define _GEOMETRY_MATRIX2X2_H_
|
||||
#ifndef _BASIC_GEOMETRY_MATRIX2X2_H_
|
||||
#define _BASIC_GEOMETRY_MATRIX2X2_H_
|
||||
|
||||
#include "angle.h"
|
||||
#include "vector2.h"
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_reset(BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_reset(fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -15,7 +15,7 @@ static inline void bg_fp32_matrix2x2_reset(BgFP32Matrix2x2* matrix)
|
|||
matrix->r2c2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_reset(BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_reset(fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -25,7 +25,7 @@ static inline void bg_fp64_matrix2x2_reset(BgFP64Matrix2x2* matrix)
|
|||
|
||||
// ================== Identity ================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_to_identity(BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_to_identity(fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -33,7 +33,7 @@ static inline void bg_fp32_matrix2x2_set_to_identity(BgFP32Matrix2x2* matrix)
|
|||
matrix->r2c2 = 1.0f;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_to_identity(BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_to_identity(fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -43,7 +43,7 @@ static inline void bg_fp64_matrix2x2_set_to_identity(BgFP64Matrix2x2* matrix)
|
|||
|
||||
// ================ Make Diagonal =============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_to_diagonal(const float d1, const float d2, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_to_diagonal(const float d1, const float d2, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -51,7 +51,7 @@ static inline void bg_fp32_matrix2x2_set_to_diagonal(const float d1, const float
|
|||
matrix->r2c2 = d2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_to_diagonal(const double d1, const double d2, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_to_diagonal(const double d1, const double d2, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -61,9 +61,9 @@ static inline void bg_fp64_matrix2x2_set_to_diagonal(const double d1, const doub
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_make_turn(const float angle, const angle_unit_t unit, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_make_turn(const float angle, const angle_unit_t unit, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
const float radians = bg_fp32_angle_to_radians(angle, unit);
|
||||
const float radians = fp32_angle_to_radians(angle, unit);
|
||||
const float cosine = cosf(radians);
|
||||
const float sine = sinf(radians);
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ static inline void bg_fp32_matrix2x2_make_turn(const float angle, const angle_un
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_make_turn(const double angle, const angle_unit_t unit, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_make_turn(const double angle, const angle_unit_t unit, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
const double radians = bg_fp64_angle_to_radians(angle, unit);
|
||||
const double radians = fp64_angle_to_radians(angle, unit);
|
||||
const double cosine = cos(radians);
|
||||
const double sine = sin(radians);
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ static inline void bg_fp64_matrix2x2_make_turn(const double angle, const angle_u
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_copy(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
static inline void fp32_matrix2x2_copy(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
|
@ -96,7 +96,7 @@ static inline void bg_fp32_matrix2x2_copy(const BgFP32Matrix2x2* from, BgFP32Mat
|
|||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_copy(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
static inline void fp64_matrix2x2_copy(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
|
@ -107,7 +107,7 @@ static inline void bg_fp64_matrix2x2_copy(const BgFP64Matrix2x2* from, BgFP64Mat
|
|||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_swap(BgFP32Matrix2x2* matrix1, BgFP32Matrix2x2* matrix2)
|
||||
static inline void fp32_matrix2x2_swap(fp32_matrix2x2_t* matrix1, fp32_matrix2x2_t* matrix2)
|
||||
{
|
||||
const float r1c1 = matrix2->r1c1;
|
||||
const float r1c2 = matrix2->r1c2;
|
||||
|
|
@ -128,7 +128,7 @@ static inline void bg_fp32_matrix2x2_swap(BgFP32Matrix2x2* matrix1, BgFP32Matrix
|
|||
matrix1->r2c2 = r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_swap(BgFP64Matrix2x2* matrix1, BgFP64Matrix2x2* matrix2)
|
||||
static inline void fp64_matrix2x2_swap(fp64_matrix2x2_t* matrix1, fp64_matrix2x2_t* matrix2)
|
||||
{
|
||||
const double r1c1 = matrix2->r1c1;
|
||||
const double r1c2 = matrix2->r1c2;
|
||||
|
|
@ -151,7 +151,7 @@ static inline void bg_fp64_matrix2x2_swap(BgFP64Matrix2x2* matrix1, BgFP64Matrix
|
|||
|
||||
// ============= Copy to twin type ============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_from_fp64(const BgFP64Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
static inline void fp32_matrix2x2_set_from_fp64(const fp64_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||
{
|
||||
to->r1c1 = (float)from->r1c1;
|
||||
to->r1c2 = (float)from->r1c2;
|
||||
|
|
@ -160,7 +160,7 @@ static inline void bg_fp32_matrix2x2_set_from_fp64(const BgFP64Matrix2x2* from,
|
|||
to->r2c2 = (float)from->r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_from_fp32(const BgFP32Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
static inline void fp64_matrix2x2_set_from_fp32(const fp32_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
|
@ -171,42 +171,42 @@ static inline void bg_fp64_matrix2x2_set_from_fp32(const BgFP32Matrix2x2* from,
|
|||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
static inline float bg_fp32_matrix2x2_get_determinant(const BgFP32Matrix2x2* matrix)
|
||||
static inline float fp32_matrix2x2_get_determinant(const fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_matrix2x2_get_determinant(const BgFP64Matrix2x2* matrix)
|
||||
static inline double fp64_matrix2x2_get_determinant(const fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
// ================== Singular ================== //
|
||||
|
||||
static inline int bg_fp32_matrix2x2_is_singular(const BgFP32Matrix2x2* matrix)
|
||||
static inline int fp32_matrix2x2_is_singular(const fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
||||
const float determinant = fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
||||
return -FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_matrix2x2_is_singular(const BgFP64Matrix2x2* matrix)
|
||||
static inline int fp64_matrix2x2_is_singular(const fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
||||
const double determinant = fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
||||
return -FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON;
|
||||
}
|
||||
|
||||
// =============== Transposition ================ //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_transpose(BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_transpose(fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
const float tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_transpose(fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
const double tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
|
|
@ -215,11 +215,11 @@ static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
|||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
||||
static inline int fp32_matrix2x2_invert(fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
||||
const float determinant = fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -240,11 +240,11 @@ static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
||||
static inline int fp64_matrix2x2_invert(fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
||||
const double determinant = fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
|||
|
||||
// =============== Set Transposed =============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_transposed(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
static inline void fp32_matrix2x2_set_transposed(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||
{
|
||||
float tmp = from->r1c2;
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ static inline void bg_fp32_matrix2x2_set_transposed(const BgFP32Matrix2x2* from,
|
|||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
static inline void fp64_matrix2x2_set_transposed(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||
{
|
||||
double tmp = from->r1c2;
|
||||
|
||||
|
|
@ -291,11 +291,11 @@ static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from,
|
|||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
static inline int fp32_matrix2x2_set_inverted(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||
{
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(from);
|
||||
const float determinant = fp32_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -316,11 +316,11 @@ static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, Bg
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
static inline int fp64_matrix2x2_set_inverted(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||
{
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(from);
|
||||
const double determinant = fp64_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -343,13 +343,13 @@ static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, Bg
|
|||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_row1(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_row1(const float c1, const float c2, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_row1(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_row1(const double c1, const double c2, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
|
|
@ -357,13 +357,13 @@ static inline void bg_fp64_matrix2x2_set_row1(const double c1, const double c2,
|
|||
|
||||
// ================= Set Row 2 ================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_row2(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_row2(const float c1, const float c2, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_row2(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_row2(const double c1, const double c2, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
|
|
@ -371,13 +371,13 @@ static inline void bg_fp64_matrix2x2_set_row2(const double c1, const double c2,
|
|||
|
||||
// ================ Set Column 1 ================ //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_column1(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_column1(const float r1, const float r2, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_column1(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_column1(const double r1, const double r2, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
|
|
@ -385,13 +385,13 @@ static inline void bg_fp64_matrix2x2_set_column1(const double r1, const double r
|
|||
|
||||
// ================ Set Column 2 ================ //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_set_column2(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
||||
static inline void fp32_matrix2x2_set_column2(const float r1, const float r2, fp32_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_set_column2(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
||||
static inline void fp64_matrix2x2_set_column2(const double r1, const double r2, fp64_matrix2x2_t* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
|
|
@ -399,7 +399,7 @@ static inline void bg_fp64_matrix2x2_set_column2(const double r1, const double r
|
|||
|
||||
// ================ Append scaled =============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_append_scaled(BgFP32Matrix2x2* basic_vector, const BgFP32Matrix2x2* scalable_vector, const float scale)
|
||||
static inline void fp32_matrix2x2_append_scaled(fp32_matrix2x2_t* basic_vector, const fp32_matrix2x2_t* scalable_vector, const float scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
|
@ -408,7 +408,7 @@ static inline void bg_fp32_matrix2x2_append_scaled(BgFP32Matrix2x2* basic_vector
|
|||
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_append_scaled(BgFP64Matrix2x2* basic_vector, const BgFP64Matrix2x2* scalable_vector, const double scale)
|
||||
static inline void fp64_matrix2x2_append_scaled(fp64_matrix2x2_t* basic_vector, const fp64_matrix2x2_t* scalable_vector, const double scale)
|
||||
{
|
||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||
|
|
@ -419,7 +419,7 @@ static inline void bg_fp64_matrix2x2_append_scaled(BgFP64Matrix2x2* basic_vector
|
|||
|
||||
// ================== Addition ================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_add(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x2* sum)
|
||||
static inline void fp32_matrix2x2_add(const fp32_matrix2x2_t* matrix1, const fp32_matrix2x2_t* matrix2, fp32_matrix2x2_t* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
|
@ -428,7 +428,7 @@ static inline void bg_fp32_matrix2x2_add(const BgFP32Matrix2x2* matrix1, const B
|
|||
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_add(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x2* sum)
|
||||
static inline void fp64_matrix2x2_add(const fp64_matrix2x2_t* matrix1, const fp64_matrix2x2_t* matrix2, fp64_matrix2x2_t* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
|
@ -439,7 +439,7 @@ static inline void bg_fp64_matrix2x2_add(const BgFP64Matrix2x2* matrix1, const B
|
|||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_subtract(const BgFP32Matrix2x2* minuend, const BgFP32Matrix2x2* subtrahend, BgFP32Matrix2x2* difference)
|
||||
static inline void fp32_matrix2x2_subtract(const fp32_matrix2x2_t* minuend, const fp32_matrix2x2_t* subtrahend, fp32_matrix2x2_t* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
|
@ -448,7 +448,7 @@ static inline void bg_fp32_matrix2x2_subtract(const BgFP32Matrix2x2* minuend, co
|
|||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_subtract(const BgFP64Matrix2x2* minuend, const BgFP64Matrix2x2* subtrahend, BgFP64Matrix2x2* difference)
|
||||
static inline void fp64_matrix2x2_subtract(const fp64_matrix2x2_t* minuend, const fp64_matrix2x2_t* subtrahend, fp64_matrix2x2_t* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
|
@ -459,7 +459,7 @@ static inline void bg_fp64_matrix2x2_subtract(const BgFP64Matrix2x2* minuend, co
|
|||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_multiply(const BgFP32Matrix2x2* multiplicand, const float multiplier, BgFP32Matrix2x2* product)
|
||||
static inline void fp32_matrix2x2_multiply(const fp32_matrix2x2_t* multiplicand, const float multiplier, fp32_matrix2x2_t* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
|
@ -468,7 +468,7 @@ static inline void bg_fp32_matrix2x2_multiply(const BgFP32Matrix2x2* multiplican
|
|||
product->r2c2 = multiplicand->r2c2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplicand, const double multiplier, BgFP64Matrix2x2* product)
|
||||
static inline void fp64_matrix2x2_multiply(const fp64_matrix2x2_t* multiplicand, const double multiplier, fp64_matrix2x2_t* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
|
@ -479,19 +479,19 @@ static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplican
|
|||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_divide(const BgFP32Matrix2x2* dividend, const float divisor, BgFP32Matrix2x2* quotient)
|
||||
static inline void fp32_matrix2x2_divide(const fp32_matrix2x2_t* dividend, const float divisor, fp32_matrix2x2_t* quotient)
|
||||
{
|
||||
bg_fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||
fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_divide(const BgFP64Matrix2x2* dividend, const double divisor, BgFP64Matrix2x2* quotient)
|
||||
static inline void fp64_matrix2x2_divide(const fp64_matrix2x2_t* dividend, const double divisor, fp64_matrix2x2_t* quotient)
|
||||
{
|
||||
bg_fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||
fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix2x2* matrix, BgFP32Vector2* result)
|
||||
static inline void fp32_matrix2x2_left_product(const fp32_vector2_t* vector, const fp32_matrix2x2_t* matrix, fp32_vector2_t* result)
|
||||
{
|
||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
|
@ -500,7 +500,7 @@ static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, c
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix2x2* matrix, BgFP64Vector2* result)
|
||||
static inline void fp64_matrix2x2_left_product(const fp64_vector2_t* vector, const fp64_matrix2x2_t* matrix, fp64_vector2_t* result)
|
||||
{
|
||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
|
@ -511,7 +511,7 @@ static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, c
|
|||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
||||
static inline void fp32_matrix2x2_right_product(const fp32_matrix2x2_t* matrix, const fp32_vector2_t* vector, fp32_vector2_t* result)
|
||||
{
|
||||
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
|
@ -520,7 +520,7 @@ static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix
|
|||
result->x2 = x2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_right_product(const BgFP64Matrix2x2* matrix, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
||||
static inline void fp64_matrix2x2_right_product(const fp64_matrix2x2_t* matrix, const fp64_vector2_t* vector, fp64_vector2_t* result)
|
||||
{
|
||||
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _GEOMETRY_MATRIX2X3_H_
|
||||
#define _GEOMETRY_MATRIX2X3_H_
|
||||
#ifndef _BASIC_GEOMETRY_MATRIX2X3_H_
|
||||
#define _BASIC_GEOMETRY_MATRIX2X3_H_
|
||||
|
||||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x3_reset(BgFP32Matrix2x3* matrix)
|
||||
static inline void fp32_matrix2x3_reset(fp32_matrix2x3_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -19,7 +19,7 @@ static inline void bg_fp32_matrix2x3_reset(BgFP32Matrix2x3* matrix)
|
|||
matrix->r3c2 = 0.0f;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x3_reset(BgFP64Matrix2x3* matrix)
|
||||
static inline void fp64_matrix2x3_reset(fp64_matrix2x3_t* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -33,7 +33,7 @@ static inline void bg_fp64_matrix2x3_reset(BgFP64Matrix2x3* matrix)
|
|||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
static inline void bg_fp32_matrix2x3_copy(const BgFP32Matrix2x3* from, BgFP32Matrix2x3* to)
|
||||
static inline void fp32_matrix2x3_copy(const fp32_matrix2x3_t* from, fp32_matrix2x3_t* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r1c2;
|
||||
|
|
@ -45,7 +45,7 @@ static inline void bg_fp32_matrix2x3_copy(const BgFP32Matrix2x3* from, BgFP32Mat
|
|||
to->r3c2 = from->r3c2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x3_copy(const BgFP64Matrix2x3* from, BgFP64Matrix2x3* to)
|
||||