コード例 #1
0
        public void Normalized()
        {
            Assert.IsTrue(NearlyEqual(Random4(0).Normalized.Magnitude, 1));

            Vector4d v = Random4(0);

            v.Normalize();

            Assert.IsTrue(NearlyEqual(v.Magnitude, 1));
        }
コード例 #2
0
ファイル: Normalize.cs プロジェクト: yanmayuekong/MathSharp
        public static IEnumerable <object[]> Data(VectorDimensions dimension)
        {
            var objs = new[]
            {
                new object[] { Vector256.Create(0d), default(Vector4d) },
                new object[] { Vector256.Create(1d), default(Vector4d) },
                new object[] { Vector256.Create(-1d), default(Vector4d) },
                new object[] { Vector256.Create(-1d), default(Vector4d) },
                new object[] { Vector256.Create(1d, 2d, 3d, 4d), default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), default(Vector4d) },
                new object[] { Vector256.Create(double.NaN), default(Vector4d) },
                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), default(Vector4d) },
            };

            foreach (object[] set in objs)
            {
                switch (dimension)
                {
                case VectorDimensions.V2D:
                {
                    Vector2d v1 = TestHelpers.ByValToSlowVector2d(((Vector256 <double>)set[0]));
                    set[1] = Vector2d.Normalize(v1);
                    break;
                }

                case VectorDimensions.V3D:
                {
                    Vector3d v1 = TestHelpers.ByValToSlowVector3d(((Vector256 <double>)set[0]));
                    set[1] = Vector3d.Normalize(v1);
                    break;
                }

                case VectorDimensions.V4D:
                {
                    Vector4d v1 = TestHelpers.ByValToSlowVector4d(((Vector256 <double>)set[0]));
                    set[1] = Vector4d.Normalize(v1);
                    break;
                }

                default:
                    throw new ArgumentException(nameof(dimension));
                }
            }

            return(objs);
        }
コード例 #3
0
ファイル: Vector4dNUnit.cs プロジェクト: zhuanGH2020/Mathd
    public void Normalize2()
    {
        for (int i = 0; i < count; i++)
        {
            float ax, ay, az, aw;

            ax = UnityEngine.Random.Range(-10F, 10F);
            ay = UnityEngine.Random.Range(-10F, 10F);
            az = UnityEngine.Random.Range(-10F, 10F);
            aw = UnityEngine.Random.Range(-10F, 10F);

            Vector4 a = new Vector4(ax, ay, az, aw);

            Vector4d ad = new Vector4d(ax, ay, az, aw);

            a.Normalize();
            ad.Normalize();

            Assert.True(Approximate(a, ad));
        }
    }
コード例 #4
0
ファイル: Vector4dNUnit.cs プロジェクト: zhuanGH2020/Mathd
    public void Normalize1()
    {
        for (int i = 0; i < count; i++)
        {
            float ax, ay, az, aw;

            ax = UnityEngine.Random.Range(-10F, 10F);
            ay = UnityEngine.Random.Range(-10F, 10F);
            az = UnityEngine.Random.Range(-10F, 10F);
            aw = UnityEngine.Random.Range(-10F, 10F);

            Vector4 a = new Vector4(ax, ay, az, aw);

            Vector4d ad = new Vector4d(ax, ay, az, aw);

            Vector4  value  = Vector4.Normalize(a);
            Vector4d valued = Vector4d.Normalize(ad);

            Assert.True(Approximate(value, valued));
        }
    }