-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab73fd3
commit 139933b
Showing
10 changed files
with
112 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,114 @@ | ||
namespace Hypercube.Mathematics; | ||
using JetBrains.Annotations; | ||
|
||
namespace Hypercube.Mathematics; | ||
|
||
[PublicAPI] | ||
public static class HyperMath | ||
{ | ||
/// <summary> | ||
/// Represents the ratio of the circumference of a circle to its diameter, | ||
/// specified by the constant, π. | ||
/// </summary> | ||
public const double PI = Math.PI; | ||
|
||
/// <summary> | ||
/// Represents the ratio of the circumference of a circle to its diameter, | ||
/// specified by the constant, π. | ||
/// </summary> | ||
public const float PIf = MathF.PI; | ||
|
||
public const double PIOver2 = PI / 2; | ||
public const double PIOver4 = PI / 4; | ||
public const double PIOver6 = PI / 6; | ||
|
||
public const double TwoPI = 2 * PI; | ||
public const double ThreePiOver2 = 3 * PI / 2; | ||
|
||
public const double TwoPI = PI * 2; | ||
public const double ThreePiOver2 = PI / 2 * 3; | ||
|
||
public const double RadiansToDegrees = 180 / PI; | ||
public const double DegreesToRadians = PI / 180; | ||
|
||
public const float PIOver2F = PIf / 2; | ||
public const float PIOver4F = PIf / 4; | ||
public const float PIOver6F = PIf / 6; | ||
public const float TwoPIf = PIf * 2; | ||
public const float ThreePiOver2F = PIf / 2 * 3; | ||
|
||
public const float RadiansToDegreesF = 180 / PIf; | ||
public const float DegreesToRadiansF = PIf / 180; | ||
|
||
public static byte MoveTowards(byte current, byte target, byte distance) | ||
{ | ||
return current < target ? | ||
(byte)Math.Min(current + distance, target) : | ||
(byte)Math.Max(current - distance, target); | ||
} | ||
|
||
public static sbyte MoveTowards(sbyte current,sbyte target, sbyte distance) | ||
{ | ||
return current < target ? | ||
(sbyte)Math.Min(current + distance, target) : | ||
(sbyte)Math.Max(current - distance, target); | ||
} | ||
|
||
public static short MoveTowards(short current, short target, short distance) | ||
{ | ||
return current < target ? | ||
(short)Math.Min(current + distance, target) : | ||
(short)Math.Max(current - distance, target); | ||
} | ||
|
||
public static ushort MoveTowards(ushort current, ushort target, ushort distance) | ||
{ | ||
return current < target ? | ||
(ushort)Math.Min(current + distance, target) : | ||
(ushort)Math.Max(current - distance, target); | ||
} | ||
|
||
public static int MoveTowards(int current, int target, int distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
|
||
public static nint MoveTowards(nint current, nint target, nint distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
|
||
public static long MoveTowards(long current, long target, long distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
|
||
public static ulong MoveTowards(ulong current, ulong target, ulong distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
|
||
public static uint MoveTowards(uint current, uint target, uint distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
|
||
public static float MoveTowards(float current, float target, float distance) | ||
{ | ||
return current < target ? | ||
MathF.Min(current + distance, target) : | ||
MathF.Max(current - distance, target); | ||
} | ||
|
||
public static double MoveTowards(double current, double target, double distance) | ||
{ | ||
return current < target ? | ||
Math.Min(current + distance, target) : | ||
Math.Max(current - distance, target); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters