Переименование проектов / Renaming of projects
This commit is contained in:
parent
da61a9bf7c
commit
beb237fd4e
44 changed files with 6588 additions and 9 deletions
557
basic-geometry/angle.h
Normal file
557
basic-geometry/angle.h
Normal file
|
@ -0,0 +1,557 @@
|
|||
#ifndef _GEOMETRY_ANGLE_H_
|
||||
#define _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 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 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 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
|
||||
|
||||
typedef enum {
|
||||
BG_ANGLE_UNIT_RADIANS = 1,
|
||||
BG_ANGLE_UNIT_DEGREES = 2,
|
||||
BG_ANGLE_UNIT_TURNS = 3
|
||||
} angle_unit_t;
|
||||
|
||||
typedef enum {
|
||||
/**
|
||||
* The measure of an angle with a range of:
|
||||
* [0, 360) degrees, [0, 2xPI) radians, [0, 1) turns, [0, 400) gradians
|
||||
*/
|
||||
BG_ANGLE_RANGE_UNSIGNED = 1,
|
||||
|
||||
/**
|
||||
* The measure of an angle with a range of:
|
||||
* (-180, 180] degrees, (-PI, PI] radians, (-0.5, 0.5] turns, (-200, 200] gradians
|
||||
*/
|
||||
BG_ANGLE_RANGE_SIGNED = 2
|
||||
} angle_range_t;
|
||||
|
||||
// !================= Radians ==================! //
|
||||
|
||||
// ========= Convert radians to degrees ========= //
|
||||
|
||||
static inline float bg_fp32_radians_to_degrees(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_to_degrees(const double radians)
|
||||
{
|
||||
return radians * BG_FP64_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========== Convert radians to turns ========== //
|
||||
|
||||
static inline float bg_fp32_radians_to_turns(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_radians_to_turns(const double radians)
|
||||
{
|
||||
return radians * BG_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)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return radians * BG_FP32_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
// ============ Normalize radians ============= //
|
||||
|
||||
static inline float bg_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) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-BG_FP32_PI < radians && radians <= BG_FP32_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
float turns = radians * BG_FP32_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_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) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-BG_FP64_PI < radians && radians <= BG_FP64_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
double turns = radians * BG_FP64_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// !================= Degrees ==================! //
|
||||
|
||||
// ========= Convert degrees to radians ========= //
|
||||
|
||||
static inline float bg_fp32_degrees_to_radians(const float degrees)
|
||||
{
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_radians(const double degrees)
|
||||
{
|
||||
return degrees * BG_FP64_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert degrees to turns ========== //
|
||||
|
||||
static inline float bg_fp32_degrees_to_turns(const float radians)
|
||||
{
|
||||
return radians * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_to_turns(const double radians)
|
||||
{
|
||||
return radians * BG_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)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return degrees * BG_FP32_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
// ============ Normalize degrees ============= //
|
||||
|
||||
static inline float bg_fp32_degrees_normalize(const float degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= degrees && degrees < 360.0f) {
|
||||
return degrees;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-180.0f < degrees && degrees <= 180.0f) {
|
||||
return degrees;
|
||||
}
|
||||
}
|
||||
|
||||
float turns = degrees * BG_FP32_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_degrees_normalize(const double degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= degrees && degrees < 360.0) {
|
||||
return degrees;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-180.0 < degrees && degrees <= 180.0) {
|
||||
return degrees;
|
||||
}
|
||||
}
|
||||
|
||||
double turns = degrees * BG_FP64_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// !================== Turns ===================! //
|
||||
|
||||
// ========== Convert turns to radians ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_radians(const float turns)
|
||||
{
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_to_radians(const double turns)
|
||||
{
|
||||
return turns * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ========== Convert turns to degrees ========== //
|
||||
|
||||
static inline float bg_fp32_turns_to_degrees(const float turns)
|
||||
{
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double bg_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)
|
||||
{
|
||||
if (to_unit == BG_ANGLE_UNIT_RADIANS) {
|
||||
return turns * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (to_unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
// ============= Normalize turns ============== //
|
||||
|
||||
static inline float bg_fp32_turns_normalize(const float turns, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= turns && turns < 1.0f) {
|
||||
return turns;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-0.5f < turns && turns <= 0.5f) {
|
||||
return turns;
|
||||
}
|
||||
}
|
||||
|
||||
float rest = turns - floorf(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5f) {
|
||||
return rest - 1.0f;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_turns_normalize(const double turns, const angle_range_t range)
|
||||
{
|
||||
if (range == BG_ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= turns && turns < 1.0) {
|
||||
return turns;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-0.5 < turns && turns <= 0.5) {
|
||||
return turns;
|
||||
}
|
||||
}
|
||||
|
||||
double rest = turns - floor(turns);
|
||||
|
||||
if (range == BG_ANGLE_RANGE_SIGNED && rest > 0.5) {
|
||||
return rest - 1.0;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
// !================== Angle ===================! //
|
||||
|
||||
// ========= Convert any unit to radians ======== //
|
||||
|
||||
static inline float bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to degreess ======== //
|
||||
|
||||
static inline float bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0f;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to turns ======== //
|
||||
|
||||
static inline float bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP32_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double bg_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;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return angle * BG_FP64_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ============= Get Full Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return BG_FP32_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 360.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return BG_FP64_TWO_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
return BG_FP32_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 180.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
return BG_FP64_PI;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0f;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.25f;
|
||||
}
|
||||
|
||||
return BG_FP32_HALF_OF_PI;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return 90.0;
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
return BG_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)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp32_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp32_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_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)
|
||||
{
|
||||
if (unit == BG_ANGLE_UNIT_DEGREES) {
|
||||
return bg_fp64_degrees_normalize(angle, range);
|
||||
}
|
||||
|
||||
if (unit == BG_ANGLE_UNIT_TURNS) {
|
||||
return bg_fp64_turns_normalize(angle, range);
|
||||
}
|
||||
|
||||
return bg_fp64_radians_normalize(angle, range);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue