Базовая версия библиотеки. Версия 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*
|
*.mod*
|
||||||
*.cmd
|
*.cmd
|
||||||
.tmp_versions/
|
.tmp_versions/
|
||||||
|
.vs
|
||||||
|
x64
|
||||||
|
x86
|
||||||
modules.order
|
modules.order
|
||||||
Module.symvers
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
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 ============== //
|
||||||
|
|
||||||