Equals() public method

public Equals ( object other ) : bool
other object
return bool
Exemplo n.º 1
0
        public void Vector3EqualsTest()
        {
            Vector3D <float> a = new Vector3D <float>(1.0f, 2.0f, 3.0f);
            Vector3D <float> b = new Vector3D <float>(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            object obj = b;

            bool expected = true;
            bool actual   = a.Equals(obj);

            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X      = 10.0f;
            obj      = b;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare between different types.
            obj      = new Quaternion <float>();
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare against null.
            obj      = null;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void TestEquals()
        {
            float x = 1, y = 2, z = 5;
            float x2 = 3, y2 = 4, z2 = 10;

            Vector3D v1 = new Vector3D(x, y, z);
            Vector3D v2 = new Vector3D(x, y, z);
            Vector3D v3 = new Vector3D(x2, y2, z2);

            //Test IEquatable Equals
            Assert.IsTrue(v1.Equals(v2), "Test IEquatable equals");
            Assert.IsFalse(v1.Equals(v3), "Test IEquatable equals");

            //Test object equals override
            Assert.IsTrue(v1.Equals((object)v2), "Tests object equals");
            Assert.IsFalse(v1.Equals((object)v3), "Tests object equals");

            //Test op equals
            Assert.IsTrue(v1 == v2, "Testing OpEquals");
            Assert.IsFalse(v1 == v3, "Testing OpEquals");

            //Test op not equals
            Assert.IsTrue(v1 != v3, "Testing OpNotEquals");
            Assert.IsFalse(v1 != v2, "Testing OpNotEquals");
        }
Exemplo n.º 3
0
        public void TestPushingOfInSpaceInZDirection()
        {
            // polygon which we will be moving
            Polygon3D t1 = new Polygon3D(new List <Point3D> {
                t1_1, t1_2, t1_3
            }, "t1");
            // create static polygon, we will be testing whether there is any pushing or not for this polygone
            Vector3D  shift = (-2 * uX) + (-1 * uY) + (+2 * uZ);
            Polygon3D t2    = new Polygon3D(new List <Point3D> {
                t1_1 + shift, t1_2 + shift, t1_3 + shift
            }, "t2");

            // we will be pushing one unit up (in Z coordinate) each time and testing the pusing of
            Vector3D pushingV = (0 * uX) + (0 * uY) + (1 * uZ);

            Vector3D expectedV = new Vector3D(0, 0, 0);
            Vector3D resultV   = t1.PushingOf(t2, pushingV);

            Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance

            pushingV += uZ;
            resultV   = t1.PushingOf(t2, pushingV);
            Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance

            pushingV  += uZ;
            expectedV += uZ;
            resultV    = t1.PushingOf(t2, pushingV);
            Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance

            pushingV  += uZ;
            expectedV += uZ;
            resultV    = t1.PushingOf(t2, pushingV);
            Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance
        }
Exemplo n.º 4
0
        public void TestEquals()
        {
            float x = 1, y = 2, z = 5;
            float x2 = 3, y2 = 4, z2 = 10;

            Vector3D v1 = new Vector3D(x, y, z);
            Vector3D v2 = new Vector3D(x, y, z);
            Vector3D v3 = new Vector3D(x2, y2, z2);

            //Test IEquatable Equals
            Assert.IsTrue(v1.Equals(v2), "Test IEquatable equals");
            Assert.IsFalse(v1.Equals(v3), "Test IEquatable equals");

            //Test object equals override
            Assert.IsTrue(v1.Equals((object) v2), "Tests object equals");
            Assert.IsFalse(v1.Equals((object) v3), "Tests object equals");

            //Test op equals
            Assert.IsTrue(v1 == v2, "Testing OpEquals");
            Assert.IsFalse(v1 == v3, "Testing OpEquals");

            //Test op not equals
            Assert.IsTrue(v1 != v3, "Testing OpNotEquals");
            Assert.IsFalse(v1 != v2, "Testing OpNotEquals");
        }
Exemplo n.º 5
0
            public void SetTarget(Vector3D NewTarget)
            {
                if (!target.Equals(NewTarget))
                {
                    target = NewTarget;

                    P.Echo("Set The target to: \n" + this.target.ToString());
                }
            }
Exemplo n.º 6
0
 public void Equals()
 {
     Assert.AreEqual(v1, new Vector3D(1, 2, -3));
     Assert.IsTrue(v1 == new Vector3D(1, 2, -3));
     Assert.IsTrue(v1.Equals((object)new Vector3D(1, 2, -3)));
     Assert.IsFalse(v1.Equals((object)new Vector3D(1.000001f, 2, -3)));
     Assert.AreNotEqual(v1, v2);
     Assert.AreNotEqual(v1, new Vector3D(1.000001f, 2, -3));
     Assert.IsTrue(v1 != v2);
 }
Exemplo n.º 7
0
        public void Rotate()
        {
            Vector3D Test = new Vector3D(0, 1, 0);

            Test.RotateAboutX(System.Math.PI / 2);
            Assert.IsTrue(Test.Equals(new Vector3D(0, 0, 1), 0.001f));
            Test.RotateAboutY(System.Math.PI / 2);
            Assert.IsTrue(Test.Equals(new Vector3D(1, 0, 0), 0.001f));
            Test.RotateAboutZ(System.Math.PI / 2);
            Assert.IsTrue(Test.Equals(new Vector3D(0, 1, 0), 0.001f));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Given v and v2, both are unit vectors on the sphere. This method
        /// returns the vector such that:
        /// (1) Tangent to the great circle route (the shorter one) from
        ///     v to v2.
        /// (2) Normal to v.
        /// (3) Is unit vector.
        ///
        /// It's required that v != v2.
        ///
        /// If v == -v2, the chosen path is the one that goes through the
        /// north pole, if none of v and v2 is north pole.
        /// Otherwise, the point with lat:0, lon:0.
        /// </summary>
        public static Vector3D GetW(Vector3D v, Vector3D v2)
        {
            if (v.Equals(-v2))
            {
                v2 = v.Equals(NorthPole) || v2.Equals(NorthPole) ?
                     Lat0Lon0 :
                     NorthPole;
            }

            // Now v is not parallel with v2. So their cross product is nonzero.
            var v3 = v.Cross(v2);

            // This is orthogonal to v and points to the right direction.
            return(v3.Cross(v).Normalize());
        }
Exemplo n.º 9
0
            public double StopDistance()
            {
                Vector3D myVel = rc.GetShipVelocities().LinearVelocity;

                if (Vector3D.IsZero(myVel))
                {
                    return(0);
                }

                Vector3D gravity = rc.GetNaturalGravity();
                Vector3D accel   = 2 * myVel + gravity;

                if (accel.Equals(Vector3D.Zero, 0.1))
                {
                    return(0);
                }

                Vector3D dir          = Vector3D.Normalize(accel);
                double   appliedForce = 0;

                foreach (ThrusterGroup t in thrust)
                {
                    appliedForce += t.AvailibleThrust(dir);
                }
                double appliedAccel = appliedForce / rc.CalculateShipMass().TotalMass;

                //if (appliedAccel < accel.Length())
                //    return double.PositiveInfinity;
                return(myVel.LengthSquared() / (2 * appliedAccel));
            }
Exemplo n.º 10
0
            public void ApplyAccel(Vector3D accel)
            {
                if (accel.Equals(Vector3D.Zero, 0.1))
                {
                    accel = Vector3D.Zero;
                }

                Vector3D thrust = accel * rc.CalculateShipMass().TotalMass;

                foreach (IMyThrust t in thrusters)
                {
                    if (!t.IsFunctional)
                    {
                        continue;
                    }

                    float outputThrust = (float)Vector3D.Dot(t.WorldMatrix.Forward, thrust);
                    if (outputThrust > 0)
                    {
                        float outputProportion = MathHelper.Clamp(outputThrust / t.MaxEffectiveThrust, minThrust / t.MaxThrust, 1);
                        t.ThrustOverridePercentage = outputProportion;
                        thrust -= t.WorldMatrix.Forward * outputProportion * t.MaxEffectiveThrust;
                    }
                    else
                    {
                        t.ThrustOverride = minThrust;
                    }
                }
            }
        Vector3D ApplyTarSpd(Vector3D position, Vector3D speed, Vector3D myPosition, Vector3D myVel)
        {
            double
                mySpeed = myVel.Length(),
                enSpeed = speed.Length(),
                multiplier;

            //position = Vector3D.Add(position, Vector3D.Multiply(speed,4 / 60));

            if (enSpeed > 0)
            {
                Vector3D output = GetProjectedPos(position, speed, myPosition, myVel);
                if (!output.Equals(NOTHING))
                {
                    return(output);
                }
            }

            multiplier = (mySpeed != 0 && enSpeed != 0) ? (enSpeed / mySpeed) : 0;

            Vector3D
                addition = Vector3D.Multiply(speed, multiplier);

            return(Vector3D.Add(position, addition));
        }
Exemplo n.º 12
0
        public void EqualsTest1()
        {
            var v = new Vector3D(2, -9, 3);
            var w = new Vector3D(2, -9, 3 + delta * 0.5);

            Assert.IsTrue(v.Equals(w, delta));
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        private void Look(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(
                EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

            if (_previousPosition3D.Equals(currentPosition3D))
            {
                return;
            }

            Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);

            double     angle = _rotationFactor * Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);
            Quaternion delta = new Quaternion(axis, -angle);

            // Get the current orientation from the RotateTransform3D
            AxisAngleRotation3D r = _rotation;
            Quaternion          q = new Quaternion(_rotation.Axis, _rotation.Angle);

            // Compose the delta with the previous orientation
            q *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis  = q.Axis;
            _rotation.Angle = q.Angle;

            _previousPosition3D = currentPosition3D;
        }
Exemplo n.º 14
0
        public void DifferentDimensions()
        {
            var vector3D = new Vector3D();
            var vectorN  = new VectorN(4);

            Assert.IsFalse(vector3D.Equals(vectorN));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Given different v1 and v2, which are both unit vectors on
        /// sphere, we can get a great circle path from v1 to v2 (choose the
        /// shortest great circle path). We walk the path by angle alpha from
        /// v1 towards v2. This returns the point we end up with, which is
        /// an unit vector.
        /// If v1 == v2, an exception is thrown.
        /// If v1 == -v2, the chosen path is the one that goes through
        /// the north pole, if none of v1, v2 is north pole. Otherwise,
        /// the point with lat:0, lon:0.
        /// </summary>
        public static Vector3D GetV(Vector3D v1, Vector3D v2, double alpha)
        {
            double t = v1.Dot(v2);

            if (t >= 1.0)
            {
                throw new ArgumentException();
            }
            if (t <= -1.0)
            {
                if (v1.Equals(NorthPole) || v2.Equals(NorthPole))
                {
                    return(GetV(v1, Lat0Lon0, alpha));
                }

                return(GetV(v1, NorthPole, alpha));
            }

            var    matrix = new Matrix2by2(1.0, t, t, 1.0);
            double beta   = Acos(t);

            var b = new Vector2D(Cos(alpha), Cos(beta - alpha));
            var a = matrix.Inverse().Multiply(b);

            return(v1 * a.X + v2 * a.Y);
        }
Exemplo n.º 16
0
        public void NullVector()
        {
            var            vector3D1  = new Vector3D();
            const Vector3D nullVector = null;

            Assert.IsFalse(vector3D1.Equals(nullVector));
        }
Exemplo n.º 17
0
        public void EqualsObjectTest_WhenVectorAndNullIsCompared_ThenTheNotEqual()
        {
            object first = new Vector3D(77.123, 99.456, 88.789);

            bool areEqual = first.Equals(null);

            Assert.False(areEqual);
        }
Exemplo n.º 18
0
        public void TestSubSingleVector()
        {
            Vector3D vectorA = new Vector3D(1, 1, 1);
            Vector3D actualVector = -vectorA;
            Vector3D expected = new Vector3D(-1, -1, -1);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 19
0
            public void same_components_are_equal()
            {
                var a = new Vector3D(5.0, -1.1, 99.9);
                var b = new Vector3D(5.0, -1.1, 99.9);

                Assert.True(a.Equals((object)b));
                Assert.True(b.Equals((object)a));
            }
Exemplo n.º 20
0
            public void different_components_are_not_equal()
            {
                var a = new Vector3D(5.0, -1.1, 0.0);
                var b = new Vector3D(-1.1, 5.0, 5.0);
                var c = new Vector3D(5.0, -1.1, 11.2);
                var d = new Vector3D(-1.1, -1.1, -1.1);
                var e = new Vector3D();

                Assert.False(a.Equals((object)b));
                Assert.False(b.Equals((object)a));
                Assert.False(a.Equals((object)c));
                Assert.False(c.Equals((object)a));
                Assert.False(a.Equals((object)d));
                Assert.False(d.Equals((object)a));
                Assert.False(a.Equals((object)e));
                Assert.False(e.Equals((object)a));
            }
        public bool Equals()
        {
            // ReSharper disable once EqualExpressionComparison
#pragma warning disable CS1718 // Comparison made to same variable
            return(V1.Equals(V1));

#pragma warning restore CS1718 // Comparison made to same variable
        }
Exemplo n.º 22
0
        public void Vector3EqualsTest1()
        {
            Vector3D <float> a = new Vector3D <float>(1.0f, 2.0f, 3.0f);
            Vector3D <float> b = new Vector3D <float>(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            bool expected = true;
            bool actual   = a.Equals(b);

            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X      = 10.0f;
            expected = false;
            actual   = a.Equals(b);
            Assert.Equal(expected, actual);
        }
Exemplo n.º 23
0
        public void TestCrossProduct()
        {
            Vector3D vectorA = new Vector3D(2, 2, 2);
            Vector3D actualVector = vectorA.CrossProduct(new Vector3D(2, 2, 2));
            Vector3D expected = new Vector3D(0, 0, 0);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Returns a value indicating whether this instance is equal to
 /// the specified object.
 /// </summary>
 /// <param name="obj">An object to compare to this instance.</param>
 /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="Box2D"/> and has the same values as this instance; otherwise, <see langword="false"/>.</returns>
 public override bool Equals(object obj)
 {
     if (obj is BBox3D)
     {
         BBox3D v = (BBox3D)obj;
         return((_ptMin.Equals(v._ptMin)) && (_ptMax.Equals(v._ptMax)));
     }
     return(false);
 }
Exemplo n.º 25
0
        public void EqualsObjectTest_WhenTwoDifferentVectorsAreCompared_ThenTheNotEqual()
        {
            object first  = new Vector3D(77.123, 99.456, 88.789);
            object second = new Vector3D(88.789, 77.123, 99.456);

            bool areEqual = first.Equals(second);

            Assert.False(areEqual);
        }
Exemplo n.º 26
0
        public void TestAddVectors()
        {
            Vector3D vectorA = new Vector3D(1, 2, 1);
            Vector3D vectorB = new Vector3D(1, 2, 1);
            Vector3D actualVector = vectorA + vectorB;
            Vector3D expected = new Vector3D(2, 4, 2);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 27
0
        public void TestSubVector()
        {
            Vector3D vectorA = new Vector3D(1, 2, 1);
            Vector3D vectorB = new Vector3D(1, 2, 1);
            Vector3D actualVector = vectorA - vectorB;
            Vector3D expected = new Vector3D(0, 0, 0);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 28
0
        public void Ctor_MustSetStartEndCorrectly()
        {
            URMovement movement = new URMovement(pose1, pose2);

            Assert.True(Vector3D.Equals(pose1.Position, movement.Start.Position));
            Assert.True(Vector3D.Equals(pose1.Rotation, movement.Start.Rotation));
            Assert.True(Vector3D.Equals(pose2.Position, movement.End.Position));
            Assert.True(Vector3D.Equals(pose2.Rotation, movement.End.Rotation));
        }
Exemplo n.º 29
0
        public void TestDivVectorScale()
        {
            Vector3D vectorA = new Vector3D(4, 4, 4);
            double scaleV = 2.0;
            Vector3D actualVector = vectorA / scaleV;
            Vector3D expected = new Vector3D(2, 2, 2);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 30
0
        public void TestProdScaleVector()
        {
            double scaleV = 2.0;
            Vector3D vectorA = new Vector3D(1, 1, 1);
            Vector3D actualVector = scaleV * vectorA;
            Vector3D expected = new Vector3D(2, 2, 2);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 31
0
        public void TestProdVectorScale()
        {
            Vector3D vectorA = new Vector3D(1, 1, 1);
            double scaleV = 2.0;
            Vector3D actualVector = vectorA * scaleV;
            Vector3D expected = new Vector3D(2, 2, 2);

            Assert.IsTrue(actualVector.Equals(expected));
        }
Exemplo n.º 32
0
 public void TestEquals()
 {
     Vector3D v0 = new Vector3D(678.0, 234.8, -123.987);
       Vector3D v1 = new Vector3D(678.0, 234.8, -123.987);
       Vector3D v2 = new Vector3D(67.0, 234.8, -123.987);
       Vector3D v3 = new Vector3D(678.0, 24.8, -123.987);
       Vector3D v4 = new Vector3D(678.0, 234.8, 123.987);
       Assert.IsTrue(v0.Equals(v0));
       Assert.IsTrue(v0.Equals(v1));
       Assert.IsFalse(v0.Equals(v2));
       Assert.IsFalse(v0.Equals(v3));
       Assert.IsFalse(v0.Equals(v4));
       Assert.IsFalse(v0.Equals(v0.ToString()));
 }
Exemplo n.º 33
0
        public void TestEquals()
        {
            Vector3D a = new Vector3D(1.0, 2.0, 3.0);
            Vector3D b = new Vector3D(4.0, 5.0, 6.0);
            Vector3D c = new Vector3D(1.0, 2.0, 3.0);

            Assert.IsTrue(a.Equals(c));
            Assert.IsTrue(c.Equals(a));
            Assert.IsTrue(a == c);
            Assert.IsTrue(c == a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a == b);
            Assert.IsFalse(b == a);
            Assert.IsTrue(a != b);
            Assert.IsTrue(b != a);

            object objA = a;
            object objB = b;
            object objC = c;

            Assert.IsTrue(a.Equals(objA));
            Assert.IsTrue(a.Equals(objC));
            Assert.IsFalse(a.Equals(objB));

            Assert.IsTrue(objA.Equals(objC));
            Assert.IsFalse(objA.Equals(objB));

            Assert.IsFalse(a.Equals(null));
            Assert.IsFalse(a.Equals(5));
        }
 public static bool PointIsInPlane(Vector3D point, Vector3D planeNormal, Vector3D planePosition)
 {
     const float accuracy = 0.001f;
     if (point.Equals(planePosition))
         return true;
     Vector3D pointDirection = (point - planePosition).Normalize();
     planeNormal = planeNormal.Normalize();
     if (Math.Abs(pointDirection.Dot(planeNormal)) < accuracy)
         return true;
     return false;
 }