public void LookAtPoint() { var look_at = LookAt(target: vec(1, 1, 0), from: vec(1, 0, 0)); var manual = Translation(1, 0, 0) * RotationZ(Math.PI / 2); var calculated_look_at = new Vector3fd[] { look_at *vec(0, 0, 0), // [0] origin look_at *vec(1, 0, 0), // [1] forward look_at *vec(-1, 0, 0), // [2] back look_at *vec(0, 1, 0), // [3] up look_at *vec(0, -1, 0), // [4] down look_at *vec(0, 0, 1), // [5] left look_at *vec(0, 0, -1) // [6] right }; var calculated_manual = new Vector3fd[] { manual *vec(0, 0, 0), // [0] origin manual *vec(1, 0, 0), // [1] forward manual *vec(-1, 0, 0), // [2] back manual *vec(0, 1, 0), // [3] up manual *vec(0, -1, 0), // [4] down manual *vec(0, 0, 1), // [5] left manual *vec(0, 0, -1) // [6] right }; for (int i = 0; i < calculated_look_at.Length; i++) { calculated_look_at[i].Should().BeAproximatelyEquivalentTo(calculated_manual[i], TEST_EPSILON); } }
public void HaveCorrectValues() { var v = new Vector3fd(1, 2, 3); v.X.Should().BeApproximately(1, double.Epsilon); v.Y.Should().BeApproximately(2, double.Epsilon); v.Z.Should().BeApproximately(3, double.Epsilon); }
public void ConvertFromValueTupleOfFloat() { Vector3fd v = (1f, 0f, -1f); v.X.Should().Be(1); v.Y.Should().Be(0); v.Z.Should().Be(-1); }
public void ConvertFromValueTupleOfDouble() { Vector3fd v = (1, 0, -1); v.X.Should().Be(1); v.Y.Should().Be(0); v.Z.Should().Be(-1); }
public void ComputeAngularMagnitude() { var v1 = new Vector3fd(1, 0, 0); var v2 = new Vector3fd(0, 1, 0); v1.AngularMagnitude(v2).Should().BeApproximately(Math.PI / 2, double.Epsilon); v2.AngularMagnitude(v1).Should().BeApproximately(Math.PI / 2, double.Epsilon); // unsigned angle }
public void ComputeAngle() { var v1 = new Vector3fd(1, 0, 0); var v2 = new Vector3fd(0, 1, 0); v1.Angle(v2, (0, 0, 1)).Should().BeApproximately(Math.PI / 2, double.Epsilon); v2.Angle(v1, (0, 0, 1)).Should().BeApproximately(-Math.PI / 2, double.Epsilon); }
public static void BeAproximatelyEquivalentTo(this ObjectAssertions should, Vector3fd v, double tolerance = float.Epsilon) { var subject = (Vector3fd)should.Subject; subject.X.Should().BeApproximately(v.X, tolerance); subject.Y.Should().BeApproximately(v.Y, tolerance); subject.Z.Should().BeApproximately(v.Z, tolerance); }
public void ConverToSpan() { Vector3fd v = (1, 2, 3); var span = v.AsSpan(); span[0].Should().Be(1); span[1].Should().Be(2); span[2].Should().Be(3); }
public void ComputeUnit() { var normalized = new Vector3fd(0.1, 0, 0).Unit(); normalized.X .Should() .BeApproximately(1, double.Epsilon); normalized.Y .Should() .Be(0); normalized.Z .Should() .Be(0); }
public static bool IsAproximatelyEquivalentTo(this Vector3fd subject, Vector3fd v, double tolerance = float.Epsilon) => subject.X.IsAproximately(v.X, tolerance) && subject.Y.IsAproximately(v.Y, tolerance) && subject.Z.IsAproximately(v.Z, tolerance);
public static Transform Translation(Vector3fd t) => new Transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t.X, t.Y, t.Z, 1);