Fixed a bunch of errors I caused :)
This commit is contained in:
parent
809660d58e
commit
35f52f494c
@ -20,6 +20,9 @@ public static class EquationExtension
|
|||||||
public static Equation Absolute(this Equation equ) => x => Mathf.Absolute(equ(x));
|
public static Equation Absolute(this Equation equ) => x => Mathf.Absolute(equ(x));
|
||||||
public static Equation AbsoluteMod(this Equation equ, float mod) => x => Mathf.AbsoluteMod(equ(x), mod);
|
public static Equation AbsoluteMod(this Equation equ, float mod) => x => Mathf.AbsoluteMod(equ(x), mod);
|
||||||
|
|
||||||
|
public static Equation Add(this Equation equ, float offset) => x => equ(x) + offset;
|
||||||
|
public static Equation Add(this Equation equ, Equation offset) => x => equ(x) + offset(x);
|
||||||
|
|
||||||
public static Equation ArcCos(this Equation equ) => x => Mathf.ArcCos(equ(x)).Radians;
|
public static Equation ArcCos(this Equation equ) => x => Mathf.ArcCos(equ(x)).Radians;
|
||||||
public static Equation ArcCot(this Equation equ) => x => Mathf.ArcCot(equ(x)).Radians;
|
public static Equation ArcCot(this Equation equ) => x => Mathf.ArcCot(equ(x)).Radians;
|
||||||
public static Equation ArcCsc(this Equation equ) => x => Mathf.ArcCsc(equ(x)).Radians;
|
public static Equation ArcCsc(this Equation equ) => x => Mathf.ArcCsc(equ(x)).Radians;
|
||||||
@ -65,7 +68,8 @@ public static class EquationExtension
|
|||||||
public static Equation Coth(this Equation equ) => x => Mathf.Coth(equ(x));
|
public static Equation Coth(this Equation equ) => x => Mathf.Coth(equ(x));
|
||||||
public static Equation Csch(this Equation equ) => x => Mathf.Csch(equ(x));
|
public static Equation Csch(this Equation equ) => x => Mathf.Csch(equ(x));
|
||||||
|
|
||||||
// todo: add divide, multiply, add, subtract
|
public static Equation Divide(this Equation equ, float factor) => x => equ(x) / factor;
|
||||||
|
public static Equation Divide(this Equation equ, Equation factor) => x => equ(x) / factor(x);
|
||||||
|
|
||||||
public static Equation Factorial(this Equation equ) => x => Mathf.Factorial((int)equ(x));
|
public static Equation Factorial(this Equation equ) => x => Mathf.Factorial((int)equ(x));
|
||||||
|
|
||||||
@ -100,6 +104,9 @@ public static class EquationExtension
|
|||||||
public static float Min(this Equation equ, float min, float max, float step = Calculus.DefaultStep) =>
|
public static float Min(this Equation equ, float min, float max, float step = Calculus.DefaultStep) =>
|
||||||
Mathf.Min(equ, min, max, step);
|
Mathf.Min(equ, min, max, step);
|
||||||
|
|
||||||
|
public static Equation Multiply(this Equation equ, float factor) => x => equ(x) * factor;
|
||||||
|
public static Equation Multiply(this Equation equ, Equation factor) => x => equ(x) * factor(x);
|
||||||
|
|
||||||
public static Equation Permutations(this Equation equ, int size) =>
|
public static Equation Permutations(this Equation equ, int size) =>
|
||||||
x => Mathf.Permutations(size, (int)equ(x));
|
x => Mathf.Permutations(size, (int)equ(x));
|
||||||
public static Equation Permutations(this Equation equ, Equation size) =>
|
public static Equation Permutations(this Equation equ, Equation size) =>
|
||||||
@ -108,6 +115,9 @@ public static class EquationExtension
|
|||||||
public static Equation Power(this Equation equ, float pow) => x => Mathf.Power(equ(x), pow);
|
public static Equation Power(this Equation equ, float pow) => x => Mathf.Power(equ(x), pow);
|
||||||
public static Equation Power(this Equation equ, Equation pow) => x => Mathf.Power(equ(x), pow(x));
|
public static Equation Power(this Equation equ, Equation pow) => x => Mathf.Power(equ(x), pow(x));
|
||||||
|
|
||||||
|
public static float Product(this Equation equ, float lower, float upper, float step = 1) =>
|
||||||
|
Mathf.Product(equ, lower, upper, step);
|
||||||
|
|
||||||
public static Equation Root(this Equation equ, float index) => x => Mathf.Root(equ(x), index);
|
public static Equation Root(this Equation equ, float index) => x => Mathf.Root(equ(x), index);
|
||||||
public static Equation Root(this Equation equ, Equation index) => x => Mathf.Root(equ(x), index(x));
|
public static Equation Root(this Equation equ, Equation index) => x => Mathf.Root(equ(x), index(x));
|
||||||
|
|
||||||
@ -131,6 +141,12 @@ public static class EquationExtension
|
|||||||
|
|
||||||
public static Equation Sqrt(this Equation equ) => x => Mathf.Sqrt(equ(x));
|
public static Equation Sqrt(this Equation equ) => x => Mathf.Sqrt(equ(x));
|
||||||
|
|
||||||
|
public static Equation Subtract(this Equation equ, float offset) => x => equ(x) - offset;
|
||||||
|
public static Equation Subtract(this Equation equ, Equation offset) => x => equ(x) - offset(x);
|
||||||
|
|
||||||
|
public static float Sum(this Equation equ, float lower, float upper, float step = 1) =>
|
||||||
|
Mathf.Sum(equ, lower, upper, step);
|
||||||
|
|
||||||
public static Equation Tan(this Equation equ) => x => Mathf.Tan(equ(x));
|
public static Equation Tan(this Equation equ) => x => Mathf.Tan(equ(x));
|
||||||
|
|
||||||
public static Equation Tanh(this Equation equ) => x => Mathf.Tanh(equ(x));
|
public static Equation Tanh(this Equation equ) => x => Mathf.Tanh(equ(x));
|
||||||
|
|||||||
@ -169,7 +169,12 @@ public class Matrix2x2 : ICloneable, IStaticMatrix<Matrix2x2>
|
|||||||
|
|
||||||
public static Matrix2x2 Absolute(Matrix2x2 val) => new(Mathf.Absolute(val.r1c1), Mathf.Absolute(val.r1c2),
|
public static Matrix2x2 Absolute(Matrix2x2 val) => new(Mathf.Absolute(val.r1c1), Mathf.Absolute(val.r1c2),
|
||||||
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2));
|
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2));
|
||||||
public static Matrix2x2 Average(params Matrix2x2[] vals) => Sum(vals) / vals.Length;
|
public static Matrix2x2 Average(params Matrix2x2[] vals)
|
||||||
|
{
|
||||||
|
Matrix2x2 sum = Zero;
|
||||||
|
foreach (Matrix2x2 m in vals) sum += m;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Matrix2x2 Ceiling(Matrix2x2 val) => new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2),
|
public static Matrix2x2 Ceiling(Matrix2x2 val) => new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2),
|
||||||
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2));
|
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2));
|
||||||
public static Matrix2x2 Clamp(Matrix2x2 val, Matrix2x2 min, Matrix2x2 max) =>
|
public static Matrix2x2 Clamp(Matrix2x2 val, Matrix2x2 min, Matrix2x2 max) =>
|
||||||
|
|||||||
@ -257,7 +257,12 @@ public class Matrix3x3 : ICloneable, IStaticMatrix<Matrix3x3>
|
|||||||
new(Mathf.Absolute(val.r1c1), Mathf.Absolute(val.r1c2), Mathf.Absolute(val.r1c3),
|
new(Mathf.Absolute(val.r1c1), Mathf.Absolute(val.r1c2), Mathf.Absolute(val.r1c3),
|
||||||
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2), Mathf.Absolute(val.r2c3),
|
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2), Mathf.Absolute(val.r2c3),
|
||||||
Mathf.Absolute(val.r3c1), Mathf.Absolute(val.r3c2), Mathf.Absolute(val.r3c3));
|
Mathf.Absolute(val.r3c1), Mathf.Absolute(val.r3c2), Mathf.Absolute(val.r3c3));
|
||||||
public static Matrix3x3 Average(params Matrix3x3[] vals) => Sum(vals) / vals.Length;
|
public static Matrix3x3 Average(params Matrix3x3[] vals)
|
||||||
|
{
|
||||||
|
Matrix3x3 sum = Zero;
|
||||||
|
foreach (Matrix3x3 m in vals) sum += m;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Matrix3x3 Ceiling(Matrix3x3 val) =>
|
public static Matrix3x3 Ceiling(Matrix3x3 val) =>
|
||||||
new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2), Mathf.Ceiling(val.r1c3),
|
new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2), Mathf.Ceiling(val.r1c3),
|
||||||
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2), Mathf.Ceiling(val.r2c3),
|
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2), Mathf.Ceiling(val.r2c3),
|
||||||
|
|||||||
@ -303,7 +303,12 @@ public class Matrix4x4 : ICloneable, IStaticMatrix<Matrix4x4>
|
|||||||
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2), Mathf.Absolute(val.r2c3), Mathf.Absolute(val.r2c4),
|
Mathf.Absolute(val.r2c1), Mathf.Absolute(val.r2c2), Mathf.Absolute(val.r2c3), Mathf.Absolute(val.r2c4),
|
||||||
Mathf.Absolute(val.r3c1), Mathf.Absolute(val.r3c2), Mathf.Absolute(val.r3c3), Mathf.Absolute(val.r3c4),
|
Mathf.Absolute(val.r3c1), Mathf.Absolute(val.r3c2), Mathf.Absolute(val.r3c3), Mathf.Absolute(val.r3c4),
|
||||||
Mathf.Absolute(val.r4c1), Mathf.Absolute(val.r4c2), Mathf.Absolute(val.r4c3), Mathf.Absolute(val.r4c4));
|
Mathf.Absolute(val.r4c1), Mathf.Absolute(val.r4c2), Mathf.Absolute(val.r4c3), Mathf.Absolute(val.r4c4));
|
||||||
public static Matrix4x4 Average(params Matrix4x4[] vals) => Sum(vals) / vals.Length;
|
public static Matrix4x4 Average(params Matrix4x4[] vals)
|
||||||
|
{
|
||||||
|
Matrix4x4 sum = Zero;
|
||||||
|
foreach (Matrix4x4 m in vals) sum += m;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Matrix4x4 Ceiling(Matrix4x4 val) =>
|
public static Matrix4x4 Ceiling(Matrix4x4 val) =>
|
||||||
new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2), Mathf.Ceiling(val.r1c3), Mathf.Ceiling(val.r1c4),
|
new(Mathf.Ceiling(val.r1c1), Mathf.Ceiling(val.r1c2), Mathf.Ceiling(val.r1c3), Mathf.Ceiling(val.r1c4),
|
||||||
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2), Mathf.Ceiling(val.r2c3), Mathf.Ceiling(val.r2c4),
|
Mathf.Ceiling(val.r2c1), Mathf.Ceiling(val.r2c2), Mathf.Ceiling(val.r2c3), Mathf.Ceiling(val.r2c4),
|
||||||
|
|||||||
@ -4,8 +4,7 @@ public record struct Vector2d : IAbsolute<Vector2d>, IAverage<Vector2d>,
|
|||||||
IClampMagnitude<Vector2d, float>, IComparable<Vector2d>, ICross<Vector2d, Vector3d>,
|
IClampMagnitude<Vector2d, float>, IComparable<Vector2d>, ICross<Vector2d, Vector3d>,
|
||||||
IDot<Vector2d, float>, IEquatable<Vector2d>, IFromTuple<Vector2d, (Angle angle, float mag)>,
|
IDot<Vector2d, float>, IEquatable<Vector2d>, IFromTuple<Vector2d, (Angle angle, float mag)>,
|
||||||
ILerp<Vector2d, float>, IMax<Vector2d>, IMagnitude<float>, IMedian<Vector2d>, IMin<Vector2d>,
|
ILerp<Vector2d, float>, IMax<Vector2d>, IMagnitude<float>, IMedian<Vector2d>, IMin<Vector2d>,
|
||||||
IPresets2d<Vector2d>, ISplittable<Vector2d, (Angle[] rots, float[] mags)>, ISubtract<Vector2d>,
|
IPresets2d<Vector2d>, ISplittable<Vector2d, (Angle[] rots, float[] mags)>
|
||||||
ISum<Vector2d>
|
|
||||||
{
|
{
|
||||||
public static Vector2d Down => new(Angle.Down);
|
public static Vector2d Down => new(Angle.Down);
|
||||||
public static Vector2d Left => new(Angle.Left);
|
public static Vector2d Left => new(Angle.Left);
|
||||||
@ -84,18 +83,6 @@ public record struct Vector2d : IAbsolute<Vector2d>, IAverage<Vector2d>,
|
|||||||
}
|
}
|
||||||
public static Vector2d Round(Vector2d val, Angle.Type angleRound = Angle.Type.Degrees) =>
|
public static Vector2d Round(Vector2d val, Angle.Type angleRound = Angle.Type.Degrees) =>
|
||||||
new(Angle.Round(val.theta, angleRound), Mathf.Round(val.magnitude));
|
new(Angle.Round(val.theta, angleRound), Mathf.Round(val.magnitude));
|
||||||
public static Vector2d Subtract(Vector2d num, params Vector2d[] vals)
|
|
||||||
{
|
|
||||||
foreach (Vector2d v in vals) num -= v;
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
public static Vector2d Sum(params Vector2d[] vals)
|
|
||||||
{
|
|
||||||
if (vals.Length < 1) return Zero;
|
|
||||||
Vector2d val = One;
|
|
||||||
foreach (Vector2d v in vals) val += v;
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (Angle[] rots, float[] mags) SplitArray(params Vector2d[] vals)
|
public static (Angle[] rots, float[] mags) SplitArray(params Vector2d[] vals)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@ public record struct Vector3d : IAbsolute<Vector3d>, IAverage<Vector3d>, IClampM
|
|||||||
IComparable<Vector3d>, ICross<Vector3d>, IDot<Vector3d, float>, IEquatable<Vector3d>,
|
IComparable<Vector3d>, ICross<Vector3d>, IDot<Vector3d, float>, IEquatable<Vector3d>,
|
||||||
IFromTuple<Vector3d, (Angle yaw, Angle pitch, float mag)>, IIndexAll<Angle>, IIndexRangeAll<Angle>,
|
IFromTuple<Vector3d, (Angle yaw, Angle pitch, float mag)>, IIndexAll<Angle>, IIndexRangeAll<Angle>,
|
||||||
ILerp<Vector3d, float>, IMagnitude<float>, IMax<Vector3d>, IMedian<Vector3d>, IMin<Vector3d>,
|
ILerp<Vector3d, float>, IMagnitude<float>, IMax<Vector3d>, IMedian<Vector3d>, IMin<Vector3d>,
|
||||||
IPresets3d<Vector3d>, ISubtract<Vector3d>, ISum<Vector3d>
|
IPresets3d<Vector3d>
|
||||||
{
|
{
|
||||||
public static Vector3d Back => new(Angle.Zero, Angle.Up);
|
public static Vector3d Back => new(Angle.Zero, Angle.Up);
|
||||||
public static Vector3d Down => new(Angle.Down, Angle.Zero);
|
public static Vector3d Down => new(Angle.Down, Angle.Zero);
|
||||||
@ -142,18 +142,6 @@ public record struct Vector3d : IAbsolute<Vector3d>, IAverage<Vector3d>, IClampM
|
|||||||
}
|
}
|
||||||
public static Vector3d Round(Vector3d val, Angle.Type angleRound = Angle.Type.Degrees) =>
|
public static Vector3d Round(Vector3d val, Angle.Type angleRound = Angle.Type.Degrees) =>
|
||||||
new(Angle.Round(val.yaw, angleRound), Angle.Round(val.pitch, angleRound), Mathf.Round(val.magnitude));
|
new(Angle.Round(val.yaw, angleRound), Angle.Round(val.pitch, angleRound), Mathf.Round(val.magnitude));
|
||||||
public static Vector3d Subtract(Vector3d num, params Vector3d[] vals)
|
|
||||||
{
|
|
||||||
foreach (Vector3d v in vals) num -= v;
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
public static Vector3d Sum(params Vector3d[] vals)
|
|
||||||
{
|
|
||||||
if (vals.Length < 1) return Zero;
|
|
||||||
Vector3d val = One;
|
|
||||||
foreach (Vector3d v in vals) val += v;
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (Angle[] yaws, Angle[] pitches, float[] mags) SplitArray(params Vector3d[] vals)
|
public static (Angle[] yaws, Angle[] pitches, float[] mags) SplitArray(params Vector3d[] vals)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -79,7 +79,12 @@ public record struct Float2 : IAbsolute<Float2>, IAverage<Float2>, ICeiling<Floa
|
|||||||
|
|
||||||
public static Float2 Absolute(Float2 val) =>
|
public static Float2 Absolute(Float2 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y));
|
||||||
public static Float2 Average(params Float2[] vals) => Sum(vals) / vals.Length;
|
public static Float2 Average(params Float2[] vals)
|
||||||
|
{
|
||||||
|
Float2 sum = Zero;
|
||||||
|
foreach (Float2 f in vals) sum += f;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int2 Ceiling(Float2 val) =>
|
public static Int2 Ceiling(Float2 val) =>
|
||||||
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y));
|
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y));
|
||||||
public static Float2 Clamp(Float2 val, Float2 min, Float2 max) =>
|
public static Float2 Clamp(Float2 val, Float2 min, Float2 max) =>
|
||||||
|
|||||||
@ -119,7 +119,12 @@ public record struct Float3 : IAbsolute<Float3>, IAverage<Float3>,
|
|||||||
|
|
||||||
public static Float3 Absolute(Float3 val) =>
|
public static Float3 Absolute(Float3 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z));
|
||||||
public static Float3 Average(params Float3[] vals) => Sum(vals) / vals.Length;
|
public static Float3 Average(params Float3[] vals)
|
||||||
|
{
|
||||||
|
Float3 sum = Zero;
|
||||||
|
foreach (Float3 f in vals) sum += f;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int3 Ceiling(Float3 val) =>
|
public static Int3 Ceiling(Float3 val) =>
|
||||||
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y), Mathf.Ceiling(val.z));
|
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y), Mathf.Ceiling(val.z));
|
||||||
public static Float3 Clamp(Float3 val, Float3 min, Float3 max) =>
|
public static Float3 Clamp(Float3 val, Float3 min, Float3 max) =>
|
||||||
|
|||||||
@ -194,7 +194,12 @@ public record struct Float4 : IAbsolute<Float4>,
|
|||||||
|
|
||||||
public static Float4 Absolute(Float4 val) =>
|
public static Float4 Absolute(Float4 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z), Mathf.Absolute(val.w));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z), Mathf.Absolute(val.w));
|
||||||
public static Float4 Average(params Float4[] vals) => Sum(vals) / vals.Length;
|
public static Float4 Average(params Float4[] vals)
|
||||||
|
{
|
||||||
|
Float4 sum = Zero;
|
||||||
|
foreach (Float4 f in vals) sum += f;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int4 Ceiling(Float4 val) =>
|
public static Int4 Ceiling(Float4 val) =>
|
||||||
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y), Mathf.Ceiling(val.z), Mathf.Ceiling(val.w));
|
new(Mathf.Ceiling(val.x), Mathf.Ceiling(val.y), Mathf.Ceiling(val.z), Mathf.Ceiling(val.w));
|
||||||
public static Float4 Clamp(Float4 val, Float4 min, Float4 max) =>
|
public static Float4 Clamp(Float4 val, Float4 min, Float4 max) =>
|
||||||
|
|||||||
@ -77,7 +77,12 @@ public record struct Int2 : IAbsolute<Int2>, IAverage<Int2>, IClamp<Int2>, IClam
|
|||||||
|
|
||||||
public static Int2 Absolute(Int2 val) =>
|
public static Int2 Absolute(Int2 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y));
|
||||||
public static Int2 Average(params Int2[] vals) => Sum(vals) / vals.Length;
|
public static Int2 Average(params Int2[] vals)
|
||||||
|
{
|
||||||
|
Int2 sum = Zero;
|
||||||
|
foreach (Int2 i in vals) sum += i;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int2 Clamp(Int2 val, Int2 min, Int2 max) =>
|
public static Int2 Clamp(Int2 val, Int2 min, Int2 max) =>
|
||||||
new(Mathf.Clamp(val.x, min.x, max.x),
|
new(Mathf.Clamp(val.x, min.x, max.x),
|
||||||
Mathf.Clamp(val.y, min.y, max.y));
|
Mathf.Clamp(val.y, min.y, max.y));
|
||||||
|
|||||||
@ -116,7 +116,12 @@ public record struct Int3 : IAbsolute<Int3>, IAverage<Int3>, IClamp<Int3>, IClam
|
|||||||
|
|
||||||
public static Int3 Absolute(Int3 val) =>
|
public static Int3 Absolute(Int3 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z));
|
||||||
public static Int3 Average(params Int3[] vals) => Sum(vals) / vals.Length;
|
public static Int3 Average(params Int3[] vals)
|
||||||
|
{
|
||||||
|
Int3 sum = Zero;
|
||||||
|
foreach (Int3 i in vals) sum += i;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int3 Clamp(Int3 val, Int3 min, Int3 max) =>
|
public static Int3 Clamp(Int3 val, Int3 min, Int3 max) =>
|
||||||
new(Mathf.Clamp(val.x, min.x, max.x),
|
new(Mathf.Clamp(val.x, min.x, max.x),
|
||||||
Mathf.Clamp(val.y, min.y, max.y),
|
Mathf.Clamp(val.y, min.y, max.y),
|
||||||
|
|||||||
@ -191,7 +191,12 @@ public record struct Int4 : IAbsolute<Int4>, IAverage<Int4>, IClamp<Int4>, IClam
|
|||||||
|
|
||||||
public static Int4 Absolute(Int4 val) =>
|
public static Int4 Absolute(Int4 val) =>
|
||||||
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z), Mathf.Absolute(val.w));
|
new(Mathf.Absolute(val.x), Mathf.Absolute(val.y), Mathf.Absolute(val.z), Mathf.Absolute(val.w));
|
||||||
public static Int4 Average(params Int4[] vals) => Sum(vals) / vals.Length;
|
public static Int4 Average(params Int4[] vals)
|
||||||
|
{
|
||||||
|
Int4 sum = Zero;
|
||||||
|
foreach (Int4 i in vals) sum += i;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
public static Int4 Clamp(Int4 val, Int4 min, Int4 max) =>
|
public static Int4 Clamp(Int4 val, Int4 min, Int4 max) =>
|
||||||
new(Mathf.Clamp(val.x, min.x, max.x),
|
new(Mathf.Clamp(val.x, min.x, max.x),
|
||||||
Mathf.Clamp(val.y, min.y, max.y),
|
Mathf.Clamp(val.y, min.y, max.y),
|
||||||
|
|||||||
@ -47,8 +47,18 @@ public static class Mathf
|
|||||||
for (float x = min; x <= max; x += step) vals.Add(equ(x));
|
for (float x = min; x <= max; x += step) vals.Add(equ(x));
|
||||||
return Average(vals.ToArray());
|
return Average(vals.ToArray());
|
||||||
}
|
}
|
||||||
public static float Average(params float[] vals) => Sum(vals) / vals.Length;
|
public static float Average(params float[] vals)
|
||||||
public static int Average(params int[] vals) => Sum(vals) / vals.Length;
|
{
|
||||||
|
float sum = 0;
|
||||||
|
foreach (float f in vals) sum += f;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
|
public static int Average(params int[] vals)
|
||||||
|
{
|
||||||
|
int sum = 0;
|
||||||
|
foreach (int i in vals) sum += i;
|
||||||
|
return sum / vals.Length;
|
||||||
|
}
|
||||||
|
|
||||||
public static float Binomial(int n, int total, float successRate) =>
|
public static float Binomial(int n, int total, float successRate) =>
|
||||||
Combinations(total, n) * Power(successRate, n) * Power(1 - successRate, total - n);
|
Combinations(total, n) * Power(successRate, n) * Power(1 - successRate, total - n);
|
||||||
@ -98,20 +108,20 @@ public static class Mathf
|
|||||||
public static float Dot(float[] a, float[] b)
|
public static float Dot(float[] a, float[] b)
|
||||||
{
|
{
|
||||||
if (a.Length != b.Length) throw new InvalidSizeException("Both arrays must have the same length");
|
if (a.Length != b.Length) throw new InvalidSizeException("Both arrays must have the same length");
|
||||||
float[] vals = new float[a.Length];
|
float sum = 0;
|
||||||
for (int i = 0; i < a.Length; i++) vals[i] = a[i] * b[i];
|
for (int i = 0; i < a.Length; i++) sum += a[i] * b[i];
|
||||||
return Sum(vals);
|
return sum;
|
||||||
}
|
}
|
||||||
public static float Dot(params float[][] vals)
|
public static float Dot(params float[][] vals)
|
||||||
{
|
{
|
||||||
float[] res = new float[vals[0].Length];
|
float sum = 0;
|
||||||
for (int i = 0; i < res.Length; i++)
|
for (int i = 0; i < vals[0].Length; i++)
|
||||||
{
|
{
|
||||||
float m = 1;
|
float m = 1;
|
||||||
for (int j = 0; j < vals.Length; j++) m *= vals[j][i];
|
for (int j = 0; j < vals.Length; j++) m *= vals[j][i];
|
||||||
res[i] = m;
|
sum += m;
|
||||||
}
|
}
|
||||||
return Sum(res);
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Factorial(int amount)
|
public static int Factorial(int amount)
|
||||||
@ -162,7 +172,12 @@ public static class Mathf
|
|||||||
_ => throw new ArgumentException("Unknown prime check method.", nameof(method))
|
_ => throw new ArgumentException("Unknown prime check method.", nameof(method))
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int LeastCommonMultiple(params int[] vals) => Product(vals) / GreatestCommonFactor(vals);
|
public static int LeastCommonMultiple(params int[] vals)
|
||||||
|
{
|
||||||
|
int product = 1;
|
||||||
|
foreach (int i in vals) product *= i;
|
||||||
|
return product / GreatestCommonFactor(vals);
|
||||||
|
}
|
||||||
|
|
||||||
public static float Lerp(float a, float b, float t, bool clamp = true)
|
public static float Lerp(float a, float b, float t, bool clamp = true)
|
||||||
{
|
{
|
||||||
@ -376,6 +391,13 @@ public static class Mathf
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float Product(Equation equ, float lower, float upper, float step = 1)
|
||||||
|
{
|
||||||
|
float result = 0;
|
||||||
|
for (float f = lower; f < upper; f += step) result *= equ(f);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static float Root(float value, float index) => (float)Math.Exp(Math.Log(value) / index);
|
public static float Root(float value, float index) => (float)Math.Exp(Math.Log(value) / index);
|
||||||
|
|
||||||
public static float Round(float num) => num % 1 >= 0.5 ? Ceiling(num) : Floor(num);
|
public static float Round(float num) => num % 1 >= 0.5 ? Ceiling(num) : Floor(num);
|
||||||
@ -491,11 +513,16 @@ public static class Mathf
|
|||||||
|
|
||||||
public static float Sqrt(float value) => SolveNewton(x => x * x - value, 1);
|
public static float Sqrt(float value) => SolveNewton(x => x * x - value, 1);
|
||||||
|
|
||||||
// TODO: include equation product and sum
|
|
||||||
|
|
||||||
// Known as stdev
|
// Known as stdev
|
||||||
public static float StandardDeviation(params float[] vals) => Sqrt(Variance(vals));
|
public static float StandardDeviation(params float[] vals) => Sqrt(Variance(vals));
|
||||||
|
|
||||||
|
public static float Sum(Equation equ, float lower, float upper, float step = 1)
|
||||||
|
{
|
||||||
|
float result = 0;
|
||||||
|
for (float f = lower; f < upper; f += step) result += equ(f);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static float Tan(Angle angle) => Tan(angle.Radians);
|
public static float Tan(Angle angle) => Tan(angle.Radians);
|
||||||
public static float Tan(float radians) => Sin(radians) / Cos(radians);
|
public static float Tan(float radians) => Sin(radians) / Cos(radians);
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ public record struct Quaternion(float u, float i, float j, float k) : IAbsolute<
|
|||||||
IDot<Quaternion, float>, IEquatable<Quaternion>, IFloor<Quaternion>, IGroup<float>,
|
IDot<Quaternion, float>, IEquatable<Quaternion>, IFloor<Quaternion>, IGroup<float>,
|
||||||
IIndexAll<float>, IIndexRangeAll<float>, ILerp<Quaternion, float>, IMax<Quaternion>, IMedian<Quaternion>,
|
IIndexAll<float>, IIndexRangeAll<float>, ILerp<Quaternion, float>, IMax<Quaternion>, IMedian<Quaternion>,
|
||||||
IMin<Quaternion>, IPresets4d<Quaternion>, IRound<Quaternion>,
|
IMin<Quaternion>, IPresets4d<Quaternion>, IRound<Quaternion>,
|
||||||
ISplittable<Quaternion, (float[] Us, float[] Is, float[] Js, float[] Ks)>,
|
ISplittable<Quaternion, (float[] Us, float[] Is, float[] Js, float[] Ks)>
|
||||||
{
|
{
|
||||||
public static Quaternion Back => new(0, 0, -1, 0);
|
public static Quaternion Back => new(0, 0, -1, 0);
|
||||||
public static Quaternion Down => new(0, -1, 0, 0);
|
public static Quaternion Down => new(0, -1, 0, 0);
|
||||||
|
|||||||
@ -79,7 +79,24 @@ public readonly record struct Rational : IAbsolute<Rational>, IAverage<Rational>
|
|||||||
|
|
||||||
public static Rational Absolute(Rational value) =>
|
public static Rational Absolute(Rational value) =>
|
||||||
new(Mathf.Absolute(value.numerator), value.denominator);
|
new(Mathf.Absolute(value.numerator), value.denominator);
|
||||||
public static Rational Average(params Rational[] vals) => Sum(vals) / (float)vals.Length;
|
public static Rational Average(params Rational[] vals)
|
||||||
|
{
|
||||||
|
// TODO: this doesn't work.
|
||||||
|
|
||||||
|
int[] denominators = new int[vals.Length];
|
||||||
|
for (int i = 0; i < vals.Length; i++) denominators[i] = vals[i].denominator;
|
||||||
|
|
||||||
|
int lcm = Mathf.LeastCommonMultiple(denominators);
|
||||||
|
int sumNum = 0, sumDen = lcm * vals.Length;
|
||||||
|
|
||||||
|
foreach (Rational r in vals)
|
||||||
|
{
|
||||||
|
int scale = lcm / r.denominator;
|
||||||
|
sumNum += r.numerator * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new(sumNum / vals.Length, sumDen);
|
||||||
|
}
|
||||||
public static int Ceiling(Rational r)
|
public static int Ceiling(Rational r)
|
||||||
{
|
{
|
||||||
int mod = r.numerator % r.denominator;
|
int mod = r.numerator % r.denominator;
|
||||||
|
|||||||
@ -38,21 +38,32 @@ public class NDArray<T> : IEnumerable<T>, IEquatable<NDArray<T>>
|
|||||||
sizes = new int[dimensions];
|
sizes = new int[dimensions];
|
||||||
Array.Fill(sizes, allLengths);
|
Array.Fill(sizes, allLengths);
|
||||||
|
|
||||||
arr = new T[Mathf.Product(sizes)];
|
long allSizes = 1;
|
||||||
|
foreach (int i in sizes) allSizes *= i;
|
||||||
|
|
||||||
|
arr = new T[allSizes];
|
||||||
}
|
}
|
||||||
public NDArray(int[] lengths)
|
public NDArray(int[] lengths)
|
||||||
{
|
{
|
||||||
arr = new T[Mathf.Product(lengths)];
|
|
||||||
dimensions = lengths.Length;
|
dimensions = lengths.Length;
|
||||||
sizes = lengths;
|
sizes = lengths;
|
||||||
|
|
||||||
|
long allSizes = 1;
|
||||||
|
foreach (int i in sizes) allSizes *= i;
|
||||||
|
|
||||||
|
arr = new T[allSizes];
|
||||||
}
|
}
|
||||||
public NDArray(int dimensions, int[] lengths)
|
public NDArray(int dimensions, int[] lengths)
|
||||||
{
|
{
|
||||||
if (dimensions != lengths.Length) throw new InvalidSizeException("Dimension count doesn't match length count.");
|
if (dimensions != lengths.Length) throw new InvalidSizeException("Dimension count doesn't match length count.");
|
||||||
|
|
||||||
arr = new T[Mathf.Product(lengths)];
|
|
||||||
this.dimensions = lengths.Length;
|
this.dimensions = lengths.Length;
|
||||||
sizes = lengths;
|
sizes = lengths;
|
||||||
|
|
||||||
|
long allSizes = 1;
|
||||||
|
foreach (int i in sizes) allSizes *= i;
|
||||||
|
|
||||||
|
arr = new T[allSizes];
|
||||||
}
|
}
|
||||||
public NDArray(T[] items, int[] lengths)
|
public NDArray(T[] items, int[] lengths)
|
||||||
{
|
{
|
||||||
@ -60,17 +71,30 @@ public class NDArray<T> : IEnumerable<T>, IEquatable<NDArray<T>>
|
|||||||
dimensions = lengths.Length;
|
dimensions = lengths.Length;
|
||||||
sizes = lengths;
|
sizes = lengths;
|
||||||
|
|
||||||
if (arr.Length != Mathf.Product(lengths)) throw new InvalidSizeException("Too many or too few items were provided.");
|
long allSizes = 1;
|
||||||
|
foreach (int i in sizes) allSizes *= i;
|
||||||
|
|
||||||
|
arr = new T[allSizes];
|
||||||
|
|
||||||
|
if (arr.Length != allSizes)
|
||||||
|
throw new InvalidSizeException("Too many or too few items were provided.");
|
||||||
}
|
}
|
||||||
public NDArray(T[] items, int dimensions, int[] lengths)
|
public NDArray(T[] items, int dimensions, int[] lengths)
|
||||||
{
|
{
|
||||||
if (dimensions != lengths.Length) throw new InvalidSizeException("Dimension count doesn't match length count.");
|
if (dimensions != lengths.Length)
|
||||||
|
throw new InvalidSizeException("Dimension count doesn't match length count.");
|
||||||
|
|
||||||
arr = items;
|
arr = items;
|
||||||
this.dimensions = lengths.Length;
|
this.dimensions = lengths.Length;
|
||||||
sizes = lengths;
|
sizes = lengths;
|
||||||
|
|
||||||
if (arr.Length != Mathf.Product(lengths)) throw new InvalidSizeException("Too many or too few items were provided.");
|
long allSizes = 1;
|
||||||
|
foreach (int i in sizes) allSizes *= i;
|
||||||
|
|
||||||
|
arr = new T[allSizes];
|
||||||
|
|
||||||
|
if (arr.Length != allSizes)
|
||||||
|
throw new InvalidSizeException("Too many or too few items were provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public T this[params int[] indexes]
|
public T this[params int[] indexes]
|
||||||
@ -81,7 +105,8 @@ public class NDArray<T> : IEnumerable<T>, IEquatable<NDArray<T>>
|
|||||||
|
|
||||||
private int FlattenIndex(params int[] indexes)
|
private int FlattenIndex(params int[] indexes)
|
||||||
{
|
{
|
||||||
if (indexes.Length != sizes.Length) throw new InvalidSizeException("Too many or too few indexes were provided.");
|
if (indexes.Length != sizes.Length)
|
||||||
|
throw new InvalidSizeException("Too many or too few indexes were provided.");
|
||||||
|
|
||||||
int ind = indexes[^1];
|
int ind = indexes[^1];
|
||||||
Console.WriteLine($"Start at {ind}");
|
Console.WriteLine($"Start at {ind}");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user