Базовая версия библиотеки. Версия 0.2.0-dev
This commit is contained in:
parent
b086af7f66
commit
6a56e85052
39 changed files with 6200 additions and 1 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -47,8 +47,14 @@
|
|||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
.vs
|
||||
x64
|
||||
x86
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
bin
|
||||
obj
|
||||
dev
|
||||
logs
|
||||
|
|
|
|||
12
Geometry.workspace
Normal file
12
Geometry.workspace
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_workspace_file>
|
||||
<Workspace title="Workspace">
|
||||
<Project filename="src/geometry.cbp" />
|
||||
<Project filename="dev/geometry-dev.cbp">
|
||||
<Depends filename="src/geometry.cbp" />
|
||||
</Project>
|
||||
<Project filename="test/geometry-test.cbp">
|
||||
<Depends filename="src/geometry.cbp" />
|
||||
</Project>
|
||||
</Workspace>
|
||||
</CodeBlocks_workspace_file>
|
||||
5
Geometry.workspace.layout
Normal file
5
Geometry.workspace.layout
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_workspace_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveProject path="dev/geometry-dev.cbp" />
|
||||
</CodeBlocks_workspace_layout_file>
|
||||
51
GeometryC.sln
Normal file
51
GeometryC.sln
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32421.90
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "geometry", "src\geometry.vcxproj", "{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "geometry-test", "test\geometry-test.vcxproj", "{48DAE315-715F-4044-ADF5-0308483B887C}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "geometry-dev", "dev\geometry-dev.vcxproj", "{46DE6C8F-3179-4652-95CF-28D44AC4774A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Debug|x64.Build.0 = Debug|x64
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Release|x64.ActiveCfg = Release|x64
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Release|x64.Build.0 = Release|x64
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{48DAE315-715F-4044-ADF5-0308483B887C}.Release|x86.Build.0 = Release|Win32
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Debug|x64.Build.0 = Debug|x64
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Debug|x86.Build.0 = Debug|Win32
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Release|x64.ActiveCfg = Release|x64
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Release|x64.Build.0 = Release|x64
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Release|x86.ActiveCfg = Release|Win32
|
||||
{40CA6FB4-135F-4D54-A8D9-7338BA56E6A7}.Release|x86.Build.0 = Release|Win32
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Debug|x64.Build.0 = Debug|x64
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Debug|x86.Build.0 = Debug|Win32
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Release|x64.ActiveCfg = Release|x64
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Release|x64.Build.0 = Release|x64
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Release|x86.ActiveCfg = Release|Win32
|
||||
{46DE6C8F-3179-4652-95CF-28D44AC4774A}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {482D2212-4373-4231-88E5-34BD6B8CFF46}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
3
src/angle.c
Normal file
3
src/angle.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include "basis.h"
|
||||
#include "angle.h"
|
||||
|
||||
549
src/angle.h
Normal file
549
src/angle.h
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
#ifndef _GEOMETRY_ANGLE_H_
|
||||
#define _GEOMETRY_ANGLE_H_
|
||||
|
||||
#include <math.h>
|
||||
#include "basis.h"
|
||||
|
||||
#define SP_PI 3.1415926536f
|
||||
#define SP_TWO_PI 6.2831853072f
|
||||
#define SP_HALF_OF_PI 1.5707963268f
|
||||
#define SP_THIRD_OF_PI 1.0471975512f
|
||||
#define SP_FOURTH_OF_PI 0.7853981634f
|
||||
#define SP_SIXTH_OF_PI 0.5235987756f
|
||||
|
||||
#define SP_DEGREES_IN_RADIAN 57.295779513f
|
||||
#define SP_TURNS_IN_RADIAN 0.1591549431f
|
||||
#define SP_RADIANS_IN_DEGREE 1.745329252E-2f
|
||||
#define SP_TURNS_IN_DEGREE 2.7777777778E-3f
|
||||
|
||||
#define DP_PI 3.14159265358979324
|
||||
#define DP_TWO_PI 6.28318530717958648
|
||||
#define DP_HALF_OF_PI 1.57079632679489662
|
||||
#define DP_THIRD_OF_PI 1.04719755119659775
|
||||
#define DP_FOURTH_OF_PI 0.78539816339744831
|
||||
#define DP_SIXTH_OF_PI 0.523598775598298873
|
||||
|
||||
#define DP_DEGREES_IN_RADIAN 57.2957795130823209
|
||||
#define DP_TURNS_IN_RADIAN 0.159154943091895336
|
||||
#define DP_RADIANS_IN_DEGREE 1.74532925199432958E-2
|
||||
#define DP_TURNS_IN_DEGREE 2.77777777777777778E-3
|
||||
|
||||
typedef enum {
|
||||
ANGLE_UNIT_RADIANS = 1,
|
||||
ANGLE_UNIT_DEGREES = 2,
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
ANGLE_RANGE_SIGNED = 2
|
||||
} angle_range_t;
|
||||
|
||||
// ========= Convert radians to degrees ========= //
|
||||
|
||||
static inline float sp_radians_to_degrees(const float radians)
|
||||
{
|
||||
return radians * SP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double dp_radians_to_degrees(const double radians)
|
||||
{
|
||||
return radians * DP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========== Convert radians to turns ========== //
|
||||
|
||||
static inline float sp_radians_to_turns(const float radians)
|
||||
{
|
||||
return radians * SP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
static inline double dp_radians_to_turns(const double radians)
|
||||
{
|
||||
return radians * DP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
// ========= Convert degrees to radians ========= //
|
||||
|
||||
static inline float sp_degrees_to_radians(const float degrees)
|
||||
{
|
||||
return degrees * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double dp_degrees_to_radians(const double degrees)
|
||||
{
|
||||
return degrees * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert degrees to turns ========== //
|
||||
|
||||
static inline float sp_degrees_to_turns(const float radians)
|
||||
{
|
||||
return radians * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
static inline double dp_degrees_to_turns(const double radians)
|
||||
{
|
||||
return radians * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
// ========== Convert turns to radians ========== //
|
||||
|
||||
static inline float sp_turns_to_radians(const float turns)
|
||||
{
|
||||
return turns * SP_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double dp_turns_to_radians(const double turns)
|
||||
{
|
||||
return turns * DP_TWO_PI;
|
||||
}
|
||||
|
||||
// ========== Convert turns to degrees ========== //
|
||||
|
||||
static inline float sp_turns_to_degrees(const float turns)
|
||||
{
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double dp_turns_to_degrees(const double turns)
|
||||
{
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// ========= Convert radians to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_radians(const float radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return radians * SP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return radians * SP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_radians(const double radians, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return radians * DP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return radians * DP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
return radians;
|
||||
}
|
||||
|
||||
// ========= Convert degreess to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_degrees(const float degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return degrees * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return degrees * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_degrees(const double degrees, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return degrees * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_TURNS) {
|
||||
return degrees * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
// ========= Convert turns to any unit ======== //
|
||||
|
||||
static inline float sp_convert_from_turns(const float turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return turns * SP_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
static inline double dp_convert_from_turns(const double turns, const angle_unit_t to_unit)
|
||||
{
|
||||
if (to_unit == ANGLE_UNIT_RADIANS) {
|
||||
return turns * DP_TWO_PI;
|
||||
}
|
||||
|
||||
if (to_unit == ANGLE_UNIT_DEGREES) {
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
return turns;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to radians ======== //
|
||||
|
||||
static inline float sp_convert_to_radians(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * SP_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_radians(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * DP_RADIANS_IN_DEGREE;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * DP_TWO_PI;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to degreess ======== //
|
||||
|
||||
static inline float sp_convert_to_degrees(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0f;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_degrees(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * DP_DEGREES_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return angle * 360.0;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ========= Convert any unit to turns ======== //
|
||||
|
||||
static inline float sp_convert_to_turns(const float angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * SP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * SP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline double dp_convert_to_turns(const double angle, const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return angle * DP_TURNS_IN_RADIAN;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return angle * DP_TURNS_IN_DEGREE;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// ============= Get Full Circle ============== //
|
||||
|
||||
static inline float sp_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_TWO_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 360.0f;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
static inline double dp_get_full_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_TWO_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 360.0;
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float sp_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 180.0f;
|
||||
}
|
||||
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
static inline double dp_get_half_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 180.0;
|
||||
}
|
||||
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
// ============= Get Half Circle ============== //
|
||||
|
||||
static inline float sp_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return SP_HALF_OF_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 90.0f;
|
||||
}
|
||||
|
||||
return 0.25f;
|
||||
}
|
||||
|
||||
static inline double dp_get_quater_circle(const angle_unit_t unit)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_RADIANS) {
|
||||
return DP_HALF_OF_PI;
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return 90.0;
|
||||
}
|
||||
|
||||
return 0.25;
|
||||
}
|
||||
|
||||
// ============ Normalize radians ============= //
|
||||
|
||||
static inline float sp_normalize_radians(const float radians, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0f <= radians && radians < SP_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-SP_PI < radians && radians <= SP_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
float turns = radians * SP_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * SP_TWO_PI;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_radians(const double radians, const angle_range_t range)
|
||||
{
|
||||
if (range == ANGLE_RANGE_UNSIGNED) {
|
||||
if (0.0 <= radians && radians < DP_TWO_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-DP_PI < radians && radians <= DP_PI) {
|
||||
return radians;
|
||||
}
|
||||
}
|
||||
|
||||
double turns = radians * DP_TURNS_IN_RADIAN;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * DP_TWO_PI;
|
||||
}
|
||||
|
||||
// ============ Normalize degrees ============= //
|
||||
|
||||
static inline float sp_normalize_degrees(const float degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == 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 * SP_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floorf(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5f) {
|
||||
turns -= 1.0f;
|
||||
}
|
||||
|
||||
return turns * 360.0f;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_degrees(const double degrees, const angle_range_t range)
|
||||
{
|
||||
if (range == 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 * DP_TURNS_IN_DEGREE;
|
||||
|
||||
turns -= floor(turns);
|
||||
|
||||
if (range == ANGLE_RANGE_SIGNED && turns > 0.5) {
|
||||
turns -= 1.0;
|
||||
}
|
||||
|
||||
return turns * 360.0;
|
||||
}
|
||||
|
||||
// ============= Normalize turns ============== //
|
||||
|
||||
static inline float sp_normalize_turns(const float turns, const angle_range_t range)
|
||||
{
|
||||
if (range == 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 == ANGLE_RANGE_SIGNED && rest > 0.5f) {
|
||||
return rest - 1.0f;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
static inline double dp_normalize_turns(const double turns, const angle_range_t range)
|
||||
{
|
||||
if (range == 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 == ANGLE_RANGE_SIGNED && rest > 0.5) {
|
||||
return rest - 1.0;
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
// ================ Normalize ================= //
|
||||
|
||||
static inline float sp_normalize_angle(const float angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return sp_normalize_degrees(angle, range);
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return sp_normalize_turns(angle, range);
|
||||
}
|
||||
|
||||
return sp_normalize_radians(angle, range);
|
||||
}
|
||||
|
||||
static inline double dp_normalize_angle(const double angle, const angle_unit_t unit, const angle_range_t range)
|
||||
{
|
||||
if (unit == ANGLE_UNIT_DEGREES) {
|
||||
return dp_normalize_degrees(angle, range);
|
||||
}
|
||||
|
||||
if (unit == ANGLE_UNIT_TURNS) {
|
||||
return dp_normalize_turns(angle, range);
|
||||
}
|
||||
|
||||
return dp_normalize_radians(angle, range);
|
||||
}
|
||||
|
||||
#endif
|
||||
2
src/basis.c
Normal file
2
src/basis.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#include "basis.h"
|
||||
|
||||
56
src/basis.h
Normal file
56
src/basis.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef __GEOMETRY__TYPES_H_
|
||||
#define __GEOMETRY__TYPES_H_
|
||||
|
||||
#define SP_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
|
||||
|
||||
#define SP_EPSYLON 5E-7f
|
||||
#define SP_TWO_EPSYLON 1E-6f
|
||||
#define SP_SQUARE_EPSYLON 2.5E-13f
|
||||
|
||||
#define SP_ONE_THIRD 0.333333333f
|
||||
#define SP_ONE_SIXTH 0.166666667f
|
||||
#define SP_ONE_NINETH 0.111111111f
|
||||
|
||||
#define SP_GOLDEN_RATIO_HIGH 1.618034f
|
||||
#define SP_GOLDEN_RATIO_LOW 0.618034f
|
||||
|
||||
#define DP_EPSYLON_EFFECTIVENESS_LIMIT 10.0
|
||||
|
||||
#define DP_EPSYLON 5E-14
|
||||
#define DP_TWO_EPSYLON 1E-13
|
||||
#define DP_SQUARE_EPSYLON 2.5E-27
|
||||
|
||||
#define DP_ONE_THIRD 0.333333333333333333
|
||||
#define DP_ONE_SIXTH 0.166666666666666667
|
||||
#define DP_ONE_NINETH 0.111111111111111111
|
||||
|
||||
#define DP_GOLDEN_RATIO_HIGH 1.61803398874989485
|
||||
#define DP_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
|
||||
static inline int sp_are_equal(const float value1, const float value2)
|
||||
{
|
||||
if (-SP_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < SP_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||