// Copies data from an unmanaged memory pointer to a managed // Fixed32-precision fixed-point number array. internal static void Copy( IntPtr source, Fixed32[] destination, Int32 startIndex, Int32 length) { throw new NotImplementedException(); }
public void TestToDouble () { double[] values = { 0.0, 1.0, 1.0 / 3, -1, -1.0 / 3 }; foreach (double value in values) { Fixed32 f = new Fixed32 (value); double d = f.ToDouble (); double error = System.Math.Abs (d - value); Assert.That (error < 0.001); } }
public static F32Vec3 operator *(F32Vec3 a, F32Vec3 b) { return(new F32Vec3(Fixed32.Mul(a.RawX, b.RawX), Fixed32.Mul(a.RawY, b.RawY), Fixed32.Mul(a.RawZ, b.RawZ))); }
public static F32Vec2 FromFloat(float x, float y) { return(new F32Vec2(Fixed32.FromFloat(x), Fixed32.FromFloat(y))); }
public override string ToString() { return("(" + Fixed32.ToString(RawX) + ", " + Fixed32.ToString(RawY) + ")"); }
public static F32Vec2 Max(F32Vec2 a, F32Vec2 b) { return(new F32Vec2(Fixed32.Max(a.RawX, b.RawX), Fixed32.Max(a.RawY, b.RawY))); }
public unsafe void Test_StructLayout_ii () { for( Int32 i = 0; i < 100; ++ i) { Matrix44 mat = GetNextRandomMatrix44(); GCHandle h_vec = GCHandle.Alloc(mat, GCHandleType.Pinned); IntPtr vecAddress = h_vec.AddrOfPinnedObject(); Fixed32[] data = new Fixed32[16]; // nb: when Fixed32 and Half are moved back into the main // dev branch there will be need for an extension method for // Marshal that will perform the copy for those types. MarshalHelper.Copy(vecAddress, data, 0, 16); Assert.That(data[0], Is.EqualTo(mat.R0C0)); Assert.That(data[1], Is.EqualTo(mat.R0C1)); Assert.That(data[2], Is.EqualTo(mat.R0C2)); Assert.That(data[3], Is.EqualTo(mat.R0C3)); Assert.That(data[4], Is.EqualTo(mat.R1C0)); Assert.That(data[5], Is.EqualTo(mat.R1C1)); Assert.That(data[6], Is.EqualTo(mat.R1C2)); Assert.That(data[7], Is.EqualTo(mat.R1C3)); Assert.That(data[8], Is.EqualTo(mat.R2C0)); Assert.That(data[9], Is.EqualTo(mat.R2C1)); Assert.That(data[10], Is.EqualTo(mat.R2C2)); Assert.That(data[11], Is.EqualTo(mat.R2C3)); Assert.That(data[12], Is.EqualTo(mat.R3C0)); Assert.That(data[13], Is.EqualTo(mat.R3C1)); Assert.That(data[14], Is.EqualTo(mat.R3C2)); Assert.That(data[15], Is.EqualTo(mat.R3C3)); h_vec.Free(); } }
public void TestStaticFn_Hermite_ii () { var a = GetNextRandomVector4(); var b = GetNextRandomVector4(); var c = GetNextRandomVector4(); var d = GetNextRandomVector4(); Vector4 an; Vector4.Normalise(ref c, out an); Vector4 bn; Vector4.Normalise(ref d, out bn); Fixed32 half; Maths.Half(out half); var tests = new Fixed32[] { 2, half + 1, -half, -1 }; for (Int32 idx = 0; idx < tests.Length; ++idx) { Vector4 result; Assert.Throws( typeof(ArgumentOutOfRangeException), () => Vector4.Hermite ( ref a, ref an, ref b, ref bn, ref tests[idx], out result) ); } }
public static F32Vec2 operator /(F32Vec2 a, F32 b) { return(new F32Vec2(Fixed32.DivPrecise(a.RawX, b.Raw), Fixed32.DivPrecise(a.RawY, b.Raw))); }
public static F32Vec2 operator *(F32Vec2 a, F32 b) { return(new F32Vec2(Fixed32.Mul(a.RawX, b.Raw), Fixed32.Mul(a.RawY, b.Raw))); }
public static F32Vec4 Max(F32Vec4 a, F32Vec4 b) { return(new F32Vec4(Fixed32.Max(a.RawX, b.RawX), Fixed32.Max(a.RawY, b.RawY), Fixed32.Max(a.RawZ, b.RawZ), Fixed32.Max(a.RawW, b.RawW))); }
public static F32 Dot(F32Vec4 a, F32Vec4 b) { return(F32.FromRaw(Fixed32.Mul(a.RawX, b.RawX) + Fixed32.Mul(a.RawY, b.RawY) + Fixed32.Mul(a.RawZ, b.RawZ) + Fixed32.Mul(a.RawW, b.RawW))); }
public static F32Vec4 Normalize(F32Vec4 a) { F32 ooLen = F32.FromRaw(Fixed32.RSqrt(Fixed32.Mul(a.RawX, a.RawX) + Fixed32.Mul(a.RawY, a.RawY) + Fixed32.Mul(a.RawZ, a.RawZ) + Fixed32.Mul(a.RawW, a.RawW))); return(ooLen * a); }
public static F32 LengthFastest(F32Vec4 a) { return(F32.FromRaw(Fixed32.SqrtFastest(Fixed32.Mul(a.RawX, a.RawX) + Fixed32.Mul(a.RawY, a.RawY) + Fixed32.Mul(a.RawZ, a.RawZ) + Fixed32.Mul(a.RawW, a.RawW)))); }
public static F32Vec4 PowFastest(F32Vec4 a, F32Vec4 b) { return(new F32Vec4(Fixed32.PowFastest(a.RawX, b.RawX), Fixed32.PowFastest(a.RawY, b.RawY), Fixed32.PowFastest(a.RawZ, b.RawZ), Fixed32.PowFastest(a.RawW, b.RawW))); }
public void Test_Operators_Division () { const long numerator = 1; const long denominator = 10; Fixed32 f = new Fixed32 (numerator); Fixed32 g = new Fixed32 (denominator); Fixed32 h = new Fixed32 (((double)numerator) / denominator); Assert.That (f / g, Is.EqualTo (h)); }
/// <summary> /// Provides the constant TestTolerance. /// </summary> public static void TestTolerance (out Fixed32 value) { value = Fixed32.Parse("0.0001"); }
public static F32Vec2 DivFastest(F32Vec2 a, F32 b) { int oob = Fixed32.RcpFastest(b.Raw); return(new F32Vec2(Fixed32.Mul(a.RawX, oob), Fixed32.Mul(a.RawY, oob))); }
public static F32Vec2 SqrtPrecise(F32Vec2 a) { return(new F32Vec2(Fixed32.SqrtPrecise(a.RawX), Fixed32.SqrtPrecise(a.RawY))); }
public static F32Vec2 RSqrtFast(F32Vec2 a) { return(new F32Vec2(Fixed32.RSqrtFast(a.RawX), Fixed32.RSqrtFast(a.RawY))); }
public static F32Vec4 Pow(F32 a, F32Vec4 b) { return(new F32Vec4(Fixed32.Pow(a.Raw, b.RawX), Fixed32.Pow(a.Raw, b.RawY), Fixed32.Pow(a.Raw, b.RawZ), Fixed32.Pow(a.Raw, b.RawW))); }
public static F32Vec2 Exp(F32Vec2 a) { return(new F32Vec2(Fixed32.Exp(a.RawX), Fixed32.Exp(a.RawY))); }
public static F32Vec2 Clamp(F32Vec2 a, F32Vec2 min, F32Vec2 max) { return(new F32Vec2( Fixed32.Clamp(a.RawX, min.RawX, max.RawX), Fixed32.Clamp(a.RawY, min.RawY, max.RawY))); }
public static F32Vec2 Log2(F32Vec2 a) { return(new F32Vec2(Fixed32.Log2(a.RawX), Fixed32.Log2(a.RawY))); }
public static F32Vec2 FromInt(int x, int y) { return(new F32Vec2(Fixed32.FromInt(x), Fixed32.FromInt(y))); }
public static F32Vec2 SinFast(F32Vec2 a) { return(new F32Vec2(Fixed32.SinFast(a.RawX), Fixed32.SinFast(a.RawY))); }
public static F32Vec2 FromDouble(double x, double y) { return(new F32Vec2(Fixed32.FromDouble(x), Fixed32.FromDouble(y))); }
public static F32Vec2 CosFastest(F32Vec2 a) { return(new F32Vec2(Fixed32.CosFastest(a.RawX), Fixed32.CosFastest(a.RawY))); }
public static F32Vec3 operator /(F32Vec3 a, F32Vec3 b) { return(new F32Vec3(Fixed32.DivPrecise(a.RawX, b.RawX), Fixed32.DivPrecise(a.RawY, b.RawY), Fixed32.DivPrecise(a.RawZ, b.RawZ))); }
public static F32Vec2 Pow(F32Vec2 a, F32 b) { return(new F32Vec2(Fixed32.Pow(a.RawX, b.Raw), Fixed32.Pow(a.RawY, b.Raw))); }
public void Test_Operators_Multiplication_iii () { double[] values = { 0.9, 0.5, 0.1, 0.01, 0.001, -0.001, -0.01, -0.1, -0.5, -0.9 }; foreach (double value in values) { Fixed32 f = new Fixed32 (value); Fixed32 fsq = f * f; // Actually we tolerate a slight rounding error here. We shouldn't have to, but it's not crucial to fix it. long diff = System.Math.Abs (new Fixed32 (value * value).RawValue - fsq.RawValue); Assert.That (diff < 2); } }
public static F32Vec2 Pow(F32 a, F32Vec2 b) { return(new F32Vec2(Fixed32.Pow(a.Raw, b.RawX), Fixed32.Pow(a.Raw, b.RawY))); }
public void Test_Operators_LessThan () { Fixed32 f = new Fixed32 (419); int i = 1000; Assert.That (f < i); }
public static F32Vec2 PowFastest(F32Vec2 a, F32Vec2 b) { return(new F32Vec2(Fixed32.PowFastest(a.RawX, b.RawX), Fixed32.PowFastest(a.RawY, b.RawY))); }
public void TestStaticFn_CatmullRom_iii () { var a = GetNextRandomVector4(); var b = GetNextRandomVector4(); var c = GetNextRandomVector4(); var d = GetNextRandomVector4(); Fixed32 half; Maths.Half(out half); var tests = new Fixed32[] { 2, half + 1, -half, -1 }; for (Int32 idx = 0; idx < tests.Length; ++idx) { Vector4 result; Assert.Throws( typeof(ArgumentOutOfRangeException), () => Vector4.CatmullRom ( ref a, ref b, ref c, ref d, ref tests[idx], out result) ); } }
public static F32 LengthSqr(F32Vec2 a) { return(F32.FromRaw(Fixed32.Mul(a.RawX, a.RawX) + Fixed32.Mul(a.RawY, a.RawY))); }
public unsafe void Test_StructLayout_ii () { for( Int32 i = 0; i < 100; ++ i) { Quaternion quat = GetNextRandomQuaternion(); GCHandle h_quat = GCHandle.Alloc(quat, GCHandleType.Pinned); IntPtr quatAddress = h_quat.AddrOfPinnedObject(); Fixed32[] data = new Fixed32[4]; // nb: when Fixed32 and Half are moved back into the main // dev branch there will be need for an extension method for // Marshal that will perform the copy for those types. MarshalHelper.Copy(quatAddress, data, 0, 4); Assert.That(data[0], Is.EqualTo(quat.I)); Assert.That(data[1], Is.EqualTo(quat.J)); Assert.That(data[2], Is.EqualTo(quat.K)); Assert.That(data[3], Is.EqualTo(quat.U)); h_quat.Free(); } }
public static F32Vec2 NormalizeFastest(F32Vec2 a) { F32 ooLen = F32.FromRaw(Fixed32.RSqrtFastest(Fixed32.Mul(a.RawX, a.RawX) + Fixed32.Mul(a.RawY, a.RawY))); return(ooLen * a); }
public unsafe void Test_StructLayout_ii () { for( Int32 i = 0; i < 100; ++ i) { Vector2 vec = GetNextRandomVector2(); GCHandle h_vec = GCHandle.Alloc(vec, GCHandleType.Pinned); IntPtr vecAddress = h_vec.AddrOfPinnedObject(); Fixed32[] data = new Fixed32[2]; // nb: when Fixed32 and Half are moved back into the main // dev branch there will be need for an extension method for // Marshal that will perform the copy for those types. MarshalHelper.Copy(vecAddress, data, 0, 2); Assert.That(data[0], Is.EqualTo(vec.X)); Assert.That(data[1], Is.EqualTo(vec.Y)); h_vec.Free(); } }
public static F32 Dot(F32Vec2 a, F32Vec2 b) { return(F32.FromRaw(Fixed32.Mul(a.RawX, b.RawX) + Fixed32.Mul(a.RawY, b.RawY))); }
public void TestStaticFn_Lerp_ii () { Matrix44 a = GetNextRandomMatrix44(); Matrix44 b = GetNextRandomMatrix44(); Fixed32 half; Maths.Half(out half); var tests = new Fixed32[] { 2, half + 1, -half, -1 }; for( Int32 i = 0; i < tests.Length; ++i ) { Matrix44 result; Assert.Throws( typeof(ArgumentOutOfRangeException), () => Matrix44.Lerp ( ref a, ref b, ref tests[i], out result) ); } }
public static F32Vec4 Pow(F32Vec4 a, F32 b) { return(new F32Vec4(Fixed32.Pow(a.RawX, b.Raw), Fixed32.Pow(a.RawY, b.Raw), Fixed32.Pow(a.RawZ, b.Raw), Fixed32.Pow(a.RawW, b.Raw))); }