Skip to content

Commit a9ce347

Browse files
committed
Adjusted Namespaces & Added Mathematical Constants
1 parent 97f930f commit a9ce347

24 files changed

+183
-70
lines changed

Runtime/Angle.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Unity.Mathematics;
22
using UnityEngine;
33

4-
namespace UME {
5-
public static partial class UnityMathematicsExtensions {
4+
namespace Plugins.Mathematics_Extensions.Runtime
5+
{
6+
public static partial class UME
7+
{
68
//translated from UnityEngine
79
/// Returns the signed angle between two vectors in radians
810
public static float angle (float3 from, float3 to)
@@ -22,9 +24,9 @@ public static float angle (float2 from, float2 to) {
2224
return num < 1.00000000362749E-15f ? 0 : (math.dot (from, to) / num).npsaturate ().acos (); // * 57.29578f;
2325
}
2426

25-
public static float fastangle (float4 from, float4 to) => (math.dot (from, to) / (from.lengthsq () * to.lengthsq ()).fastsqrt ()).npsaturate ().acos ();
26-
public static float fastangle (float3 from, float3 to) => (math.dot (from, to) / (from.lengthsq () * to.lengthsq ()).fastsqrt ()).npsaturate ().acos ();
27-
public static float fastangle (float2 from, float2 to) => (math.dot (from, to) / (from.lengthsq () * to.lengthsq ()).fastsqrt ()).npsaturate ().acos ();
27+
public static float fastangle (float4 from, float4 to) => (math.dot(from, to) / (from.lengthsq() * to.lengthsq()).fastsqrt()).npsaturate().acos();
28+
public static float fastangle (float3 from, float3 to) => (math.dot(from, to) / (from.lengthsq() * to.lengthsq()).fastsqrt()).npsaturate().acos();
29+
public static float fastangle (float2 from, float2 to) => (math.dot(from, to) / (from.lengthsq() * to.lengthsq()).fastsqrt()).npsaturate().acos();
2830

2931
// another way of computing angles
3032
//public static float otherangle(float2 v1, float2 v2) => math.atan2(v1.x * v2.y - v2.x * v1.y, (v1 * v2).sum()) * (180 / math.PI);
@@ -37,34 +39,34 @@ public static float angle (float2 from, float2 to) {
3739
public static double straightsignedangle (double3 f1, double3 f2, double3 n) => math.atan2 (math.dot (n, math.cross (f1, f2)), math.dot (f1, f2));
3840

3941
public static float preciseangle (float3 v1, float3 v2) {
40-
var v3 = v1.normalized ();
41-
var v4 = v2.normalized ();
42+
var v3 = v1.normalized();
43+
var v4 = v2.normalized();
4244
return math.dot (v1, v2) < 0 ?
43-
math.PI - 2 * ((-v3 - v4).length () / 2).asin () :
44-
2 * ((v3 - v4).length () / 2).asin ();
45+
math.PI - 2 * ((-v3 - v4).length() / 2).asin() :
46+
2 * ((v3 - v4).length() / 2).asin();
4547
}
4648
public static float preciseangle (float2 v1, float2 v2) {
47-
var v3 = v1.normalized ();
48-
var v4 = v2.normalized ();
49+
var v3 = v1.normalized();
50+
var v4 = v2.normalized();
4951
return math.dot (v3, v4) < 0 ?
50-
math.PI - 2 * ((-v3 - v4).length () / 2).asin () :
51-
2 * ((v3 - v4).length () / 2).asin ();
52+
math.PI - 2 * ((-v3 - v4).length() / 2).asin() :
53+
2 * ((v3 - v4).length() / 2).asin();
5254
}
5355

5456
/// Returns the signed angle between two vectors in radians using an axis of rotation
55-
public static float signedangle (float4 from, float4 to, float4 axis) => angle (from, to) * ((from.yzwx * to.zwxy - from.zwxy * to.yzwx) * axis).sum ().sign ();
57+
public static float signedangle (float4 from, float4 to, float4 axis) => angle (from, to) * ((from.yzwx * to.zwxy - from.zwxy * to.yzwx) * axis).sum().sign();
5658
/// Returns the signed angle between two vectors in radians using an axis of rotation
57-
public static float signedangle (float3 from, float3 to, float3 axis) => angle (from, to) * ((from.yzx * to.zxy - from.zxy * to.yzx) * axis).sum ().sign ();
59+
public static float signedangle (float3 from, float3 to, float3 axis) => angle (from, to) * ((from.yzx * to.zxy - from.zxy * to.yzx) * axis).sum().sign();
5860
/// Returns the signed angle between two vectors in radians;
59-
public static float signedangle (Vector2 from, Vector2 to) => angle (from, to) * (from.x * to.y - from.y * to.x).sign ();
61+
public static float signedangle (Vector2 from, Vector2 to) => angle (from, to) * (from.x * to.y - from.y * to.x).sign();
6062

6163
//https://gist.github.com/voidqk/fc5a58b7d9fc020ecf7f2f5fc907dfa5
6264
// Computes atan2(y,x), fast --> max err: 0.071115
6365
public static float fastatan2 (float y, float x) {
6466
const float c1 = math.PI / 4;
6567
const float c2 = math.PI * 0.75f;
6668
if (y == 0 && x == 0) return 0;
67-
var abs_y = y.abs ();
69+
var abs_y = y.abs();
6870
float angle;
6971
if (x >= 0) angle = c1 - c1 * ((x - abs_y) / (x + abs_y));
7072
else angle = c2 - c1 * ((x + abs_y) / (abs_y - x));

Runtime/Arithemetics.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System.Runtime.CompilerServices;
2-
using Unity.Mathematics;
1+
using Unity.Mathematics;
32
using UnityEngine;
43

5-
namespace UME
4+
namespace Plugins.Mathematics_Extensions.Runtime
65
{
7-
public static partial class UnityMathematicsExtensions
6+
public static partial class UME
87
{
98
// Sign
109
public static float4 sign(this float4 f) => math.sign(f);

Runtime/Comparison.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Unity.Mathematics;
22
using UnityEngine;
33

4-
namespace UME
4+
namespace Plugins.Mathematics_Extensions.Runtime
55
{
6-
public static partial class UnityMathematicsExtensions
6+
public static partial class UME
77
{
88
// Component-wise comparison --------------------------------------------------------------
99

Runtime/Constants.cs

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,96 @@
1-
namespace UME
1+
namespace Plugins.Mathematics_Extensions.Runtime
22
{
3-
public static partial class UnityMathematicsExtensions
3+
public static partial class UME
44
{
55
public const double HPI_DBL = 1.57079632679489661923;
66
public const float HPI = 1.570796326795f;
7-
7+
88
public const double PI_DBL = 3.14159265358979323846;
99
public const float PI = 3.14159265359f;
10-
10+
1111
public const double TAU_DBL = 6.283185307179586477;
1212
public const float TAU = 6.28318530718f;
1313
public const double PHI_DBL = 1.6180339887498948482;
14-
public const float PHI = 1.61803398875f;
15-
14+
public const float PHI = 1.61803398875f;
15+
1616
public const float PINFINITY = float.PositiveInfinity;
1717
public const float NINFINITY = float.NegativeInfinity;
1818
public const double PINFINITY_DBL = double.PositiveInfinity;
1919
public const double NINFINITY_DBL = double.NegativeInfinity;
20+
21+
22+
// Translated from https://github.com/JJ/p6-math-constants/blob/master/lib/Math/Constants.pm6
23+
// Update physical constants from https://nist.gov/cuu/Constants -- CODATA 2018 recommendations
24+
25+
// Physical Constants
26+
public const float plancks_h = 6.626_070_015e-34f;
27+
public const float plancks_reduced_h = 1.054_571_817e-34f;
28+
public const float speed_of_light_vacuum = 299792458f;
29+
public const float standard_acceleration_gravity = 9.80665f;
30+
public const float gravitation = 6.67430e-11f;
31+
public const float gas = 8.314462618f;
32+
public const float faraday = 96485.33212f;
33+
public const float electron_mass = 9.1093837015e-31f;
34+
public const float proton_mass = 1.67262192369e-27f;
35+
public const float neutron_mass = 1.67492749804e-27f;
36+
public const float alpha_particle_mass = 6.6446573357e-27f;
37+
public const float quantum_ratio = 2.417989242e14f;
38+
public const float planck_mass = 2.176434e-8f;
39+
public const float planck_time = 5.391247e-44f;
40+
public const float planck_length = 1.616255e-35f;
41+
public const float planck_temperature = 1.416784e+32f;
42+
public const float kg_amu = 6.02214076e23f;
43+
public const float coulomb = 8.9875517887e9f;
44+
public const float fine_structure = 0.0072973525693f;
45+
public const float elementary_charge = 1.602176634e-19f;
46+
public const float vacuum_permittivity = 8.8541878128e-12f;
47+
public const float magnetic_permeability = 12.5663706212e-7f;
48+
public const float boltzmann = 1.380649e-23f; // was in eV, now in J K^-1
49+
public const float electron_volt = 1.602176634e-19f;
50+
public const float vacuum_permeability = 12.5663706212e-7f;
51+
52+
// # Mathematical constants
53+
// # REF: https://en.wikipedia.org/wiki/Mathematical_constant
54+
55+
public const float phi = 1.61803398874989e0f;
56+
public const float alpha_feigenbaum = 2.502907875095892822283e0f;
57+
public const float delta_feigenbaum = 4.669201609102990e0f;
58+
public const float apery = 1.2020569031595942853997381e0f;
59+
public const float conway = 1.303577269034e0f;
60+
public const float khinchin = 2.6854520010e0f;
61+
public const float glaisher_kinkelin = 1.2824271291e0f;
62+
public const float golomb_dickman = 0.62432998854355e0f;
63+
public const float catalan = 0.915965594177219015054603514e0f;
64+
public const float mill = 1.3063778838630806904686144e0f;
65+
public const float gauss = 0.8346268e0f;
66+
public const float euler_mascheroni_gamma = 0.57721566490153286060e0f;
67+
public const float sierpinski_gamma = 2.5849817595e0f;
68+
69+
// Standard short names when available
70+
71+
public const float A = glaisher_kinkelin;
72+
public const float c = speed_of_light_vacuum;
73+
public const float eV = electron_volt;
74+
public const float F = faraday;
75+
public const float G = gravitation;
76+
public const float g = standard_acceleration_gravity;
77+
public const float = plancks_h;
78+
public const float = plancks_reduced_h;
79+
public const float K0 = coulomb;
80+
public const float k0 = khinchin;
81+
public const float k = sierpinski_gamma;
82+
public const float L = kg_amu;
83+
public const float lp = planck_length;
84+
public const float mp = planck_mass;
85+
public const float q = elementary_charge;
86+
public const float Tp = planck_temperature;
87+
public const float tp = planck_time;
88+
public const float α = fine_structure;
89+
public const float γ = euler_mascheroni_gamma;
90+
public const float δ = delta_feigenbaum;
91+
public const float ε0 = vacuum_permittivity;
92+
public const float λ = conway;
93+
public const float μ0 = vacuum_permeability;
94+
public const float φ = phi;
2095
}
2196
}

Runtime/Easing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Translation to C# from https://easings.net/
22
// by LTMX - https://github.com/LTMX
33

4-
namespace UME
4+
namespace Plugins.Mathematics_Extensions.Runtime
55
{
6-
public static partial class UnityMathematicsExtensions
6+
public static partial class UME
77
{
88
public static float easeInSine(this float x) => 1 - cos((x * PI) / 2);
99
public static float easeOutSine(this float x) => sin(x * PI / 2);

Runtime/Easing.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Exponents And Logarithms.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using UnityEngine;
33
using static Unity.Mathematics.math;
44

5-
namespace UME
5+
namespace Plugins.Mathematics_Extensions.Runtime
66
{
7-
public static partial class UnityMathematicsExtensions
7+
public static partial class UME
88
{
99
// Exponents ------------------------------------------
1010

Runtime/Factorial Gamma.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
using System.Numerics;
2-
using Unity.Mathematics;
3-
using Vector2 = UnityEngine.Vector2;
4-
using Vector3 = UnityEngine.Vector3;
5-
using Vector4 = UnityEngine.Vector4;
6-
7-
namespace UME
1+
namespace Plugins.Mathematics_Extensions.Runtime
82
{
93

104
// Not exactly working as expected
11-
public static partial class UnityMathematicsExtensions
5+
public static partial class UME
126
{
137
// See : https://rosettacode.org/wiki/Gamma_function#C.23
148
// Factorial Gamma Function - Lanczos Interpolated -------------------------------------------------

Runtime/FastFunctions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using Unity.Mathematics;
44
using UnityEngine;
55

6-
namespace UME
6+
namespace Plugins.Mathematics_Extensions.Runtime
77
{
8-
public static partial class UnityMathematicsExtensions
8+
public static partial class UME
99
{
1010
// https://gist.github.com/SaffronCR/b0802d102dd7f262118ac853cd5b4901#file-mathutil-cs-L24
1111

Runtime/FastTrigonometry.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
//Refactored and optimized by LTMX - from - https://web.archive.org/web/20180616003313/http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
3-
namespace UME
3+
4+
namespace Plugins.Mathematics_Extensions.Runtime
45
{
5-
public static partial class UnityMathematicsExtensions
6+
public static partial class UME
67
{
78
private const float t1 = 1.27323954f;
89
private const float t2 = 0.405284735f;

0 commit comments

Comments
 (0)