mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 03:15:30 +00:00
Added Bezier Curves. Added Factorial and BinomialCoefficient to Functions.cs. Added Vector2d?.Perpendicular
This commit is contained in:
parent
532594c1b2
commit
c946bc6fb8
BIN
Source/OpenTK/Math/BezierCurve.cs
Normal file
BIN
Source/OpenTK/Math/BezierCurve.cs
Normal file
Binary file not shown.
BIN
Source/OpenTK/Math/BezierCurveCubic.cs
Normal file
BIN
Source/OpenTK/Math/BezierCurveCubic.cs
Normal file
Binary file not shown.
BIN
Source/OpenTK/Math/BezierCurveQuadric.cs
Normal file
BIN
Source/OpenTK/Math/BezierCurveQuadric.cs
Normal file
Binary file not shown.
|
@ -1,8 +1,10 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
/* Licensed under the MIT/X11 license.
|
||||||
* See license.txt for license info
|
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||||
|
* This notice may not be removed from any source distribution.
|
||||||
|
* See license.txt for licensing detailed licensing details.
|
||||||
*
|
*
|
||||||
* Contributions by Andy Gill.
|
* Contributions by Andy Gill, James Talton and Georg Wächter.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -17,6 +19,32 @@ namespace OpenTK.Math
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Functions
|
public static class Functions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the factorial of a given natural number.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The number.</param>
|
||||||
|
/// <returns>n!</returns>
|
||||||
|
public static long Factorial(int n)
|
||||||
|
{
|
||||||
|
long result = 1;
|
||||||
|
|
||||||
|
for (; n > 1; n--)
|
||||||
|
result *= n;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The n.</param>
|
||||||
|
/// <param name="k">The k.</param>
|
||||||
|
/// <returns>n! / (k! * (n - k)!)</returns>
|
||||||
|
public static long BinomialCoefficient(int n, int k)
|
||||||
|
{
|
||||||
|
return Factorial(n) / (Factorial(k) * Factorial(n - k));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an approximation of the inverse square root of left number.
|
/// Returns an approximation of the inverse square root of left number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -43,6 +71,9 @@ namespace OpenTK.Math
|
||||||
|
|
||||||
public static double InverseSqrtFast(double x)
|
public static double InverseSqrtFast(double x)
|
||||||
{
|
{
|
||||||
|
return InverseSqrtFast((float)x);
|
||||||
|
// TODO: The following code is wrong. Fix it, to improve precision.
|
||||||
|
#if false
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
double xhalf = 0.5f * x;
|
double xhalf = 0.5f * x;
|
||||||
|
@ -52,6 +83,7 @@ namespace OpenTK.Math
|
||||||
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
|
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||||
* See license.txt for license info
|
* See license.txt for license info
|
||||||
*
|
*
|
||||||
* Contributions by Andy Gill.
|
* Contributions by Andy Gill, Georg Wächter.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -145,6 +145,21 @@ namespace OpenTK.Math
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public Vector2 Perpendicular
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the perpendicular vector.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2 Perpendicular
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Vector2(Y, -X);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public void Normalize()
|
#region public void Normalize()
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue