Ejemplo n.º 1
0
        public void VectorAdditionAndSubtraction()
        {
            IVector <DoubleComponent> Point1 = MatrixFactory <DoubleComponent> .CreateVector3D(1, 1, 1);   //new Vector3D();

            //Point1.Set(1, 1, 1);

            IVector <DoubleComponent> Point2 = MatrixFactory <DoubleComponent> .CreateVector3D(2, 2, 2);

            //Point2.Set(2, 2, 2);

            IVector <DoubleComponent> Point3;;

            Point3 = Point1.Add(Point2);

            Assert.IsTrue(Point3.Equals(MatrixFactory <DoubleComponent> .CreateVector3D(3, 3, 3)));

            Point3 = Point1.Subtract(Point2);
            Assert.IsTrue(Point3.Equals(MatrixFactory <DoubleComponent> .CreateVector3D(-1, -1, -1)));

            Point3.AddEquals(Point1);

            Assert.IsTrue(Point3.Equals(MatrixFactory <DoubleComponent> .CreateVector3D(0, 0, 0)));

            Point3.AddEquals(Point2);
            Assert.IsTrue(Point3.Equals(MatrixFactory <DoubleComponent> .CreateVector3D(2, 2, 2)));

            Point3.SetFrom(MatrixFactory <DoubleComponent> .CreateVector3D(3, -4, 5));
            Assert.IsTrue(Point3.GetMagnitude().GreaterThan(7.07) && Point3.GetMagnitude().LessThan(7.08));

            IVector <DoubleComponent> InlineOpLeftSide = MatrixFactory <DoubleComponent> .CreateVector3D(5.0f, -3.0f, .0f);

            IVector <DoubleComponent> InlineOpRightSide = MatrixFactory <DoubleComponent> .CreateVector3D(-5.0f, 4.0f, 1.0f);

            Assert.IsTrue(
                InlineOpLeftSide.Add(InlineOpRightSide)
                .Equals(
                    MatrixFactory <DoubleComponent> .CreateVector3D(.0f, 1.0f, 1.0f)
                    ));

            Assert.IsTrue(
                InlineOpLeftSide.Subtract(InlineOpRightSide)
                .Equals(
                    MatrixFactory <DoubleComponent> .CreateVector3D(10.0f, -7.0f, -1.0f))
                );
        }