예제 #1
0
        public void TestNotEqual()
        {
            // Define variables and constants
            const string DOG_STRING_A = "Dog";
            const string DOG_STRING_B = "Dog";
            const string CAT_STRING   = "Cat";

            // Set up context


            // Execute
            Assure.NotEqual(DOG_STRING_A, CAT_STRING);
            try {
                Assure.NotEqual(DOG_STRING_A, DOG_STRING_B);
                Assert.Fail();
            }
            catch (AssuranceFailedException) {
            }

            // Assert outcome
            Assure.NotEqual(new DateTime(400L), new DateTime(500L));
            try {
                Assure.NotEqual(new DateTime(400L), new DateTime(400L));
                Assert.Fail();
            }
            catch (AssuranceFailedException) {
            }
        }
예제 #2
0
 /// <summary>
 /// Constructs a new Transform struct.
 /// </summary>
 /// <param name="scale">The scale (sizing) to apply.</param>
 /// <param name="rotation">The rotation (orientation offset) to apply.</param>
 /// <param name="translation">The translation (displacement from the origin) to apply.</param>
 public Transform(Vector3 scale, Quaternion rotation, Vector3 translation)
 {
     Assure.NotEqual(rotation, Quaternion.ZERO);
     Scale       = scale;
     Rotation    = rotation;
     Translation = translation;
 }
        /// <summary>
        /// Calculates the orthonormalization of this vector on to <paramref name="axis"/>. The orthonormalized vector will the perpendicular
        /// component of this vector (to <paramref name="axis"/>), normalized (i.e. unit length).
        /// </summary>
        /// <param name="axis">The axis to orthogonalize against.</param>
        /// <returns>Returns a new Vector3 that is the value of this vector 'orthonormalized' against the given <paramref name="axis"/>.</returns>
        public Vector3 OrthonormalizedAgainst(Vector3 axis)
        {
            Assure.NotEqual(this, ZERO, "Can not orthonormalize ZERO vector.");
            Assure.NotEqual(axis, ZERO, "Can not orthonormalize against ZERO vector.");
            Vector3 orthogonalized = this - Dot(axis, this) * axis;

            if (orthogonalized.EqualsExactly(ZERO))
            {
                Logger.Warn("Attempt to orthonormalize two parallel vectors (" + this + " against " + axis + "): " +
                            "Returning arbitrary perpendicular value.");
                // ReSharper disable CompareOfFloatsByEqualityOperator Direct comparison desired
                if (X != 0f)
                {
                    return(new Vector3(-(Y + Z) / X, 1f, 1f));
                }
                else if (Y != 0f)
                {
                    return(new Vector3(1f, -(X + Z) / Y, 1f));
                }
                else
                {
                    return(new Vector3(1f, 1f, -(X + Y) / Z));
                }
                // ReSharper restore CompareOfFloatsByEqualityOperator
            }
            else
            {
                return(orthogonalized.ToUnit());
            }
        }
        /// <summary>
        /// Gets the angle formed between two vectors, in radians.
        /// </summary>
        /// <param name="v1">The first vector.</param>
        /// <param name="v2">The second vector.</param>
        /// <returns>Inverse cosine of: The sum of: Each component in <paramref name="v1"/> multiplied with the corresponding
        /// component in <paramref name="v2"/>.</returns>
        public static float AngleBetween(Vector4 v1, Vector4 v2)
        {
            Assure.NotEqual(v1, ZERO, "Can not find angle for zero vector.");
            Assure.NotEqual(v2, ZERO, "Can not find angle for zero vector.");
            v1 = v1.ToUnit();
            v2 = v2.ToUnit();

            return((float)Math.Acos(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.W));
        }
        public void SlaveWaitForFirstOpen()
        {
            Assure.NotEqual(Thread.CurrentThread, LosgapSystem.MasterThread);

            Monitor.Enter(barrierClosedLock);
            if (!barrierOpen && !isDisposed)
            {
                Monitor.Wait(barrierClosedLock);
            }
            Monitor.Exit(barrierClosedLock);
        }
        public void GetOrthogonals(out Vector3 outOrthogonalA, out Vector3 outOrthogonalB)
        {
            Assure.NotEqual(this, ZERO, "Can not find orthogonals to ZERO vector.");
            Vector3 rotated = (Vector3)(this * orthoMatX);

            if (this.Dot(rotated) > 0.6f)
            {
                rotated = (Vector3)(this * orthoMatY);
            }

            float length = Length;

            outOrthogonalA = (this * rotated).WithLength(length);
            outOrthogonalB = (this * outOrthogonalA).WithLength(length);
        }
        public void SlaveQueueOnMaster(PipelineMasterInvocation pmi)
        {
            Assure.NotNull(pmi);
            Assure.NotEqual(Thread.CurrentThread, LosgapSystem.MasterThread);
            Monitor.Enter(barrierOpenLock);
            masterInvocationQueue.Enqueue(pmi);
            Monitor.Pulse(barrierOpenLock);
            object externalLockObjLocal;

            lock (externalLockObjLock) {
                externalLockObjLocal = externalLockObj;
            }
            Monitor.Exit(barrierOpenLock);
            if (externalLockObjLocal != null)
            {
                Monitor.Enter(externalLockObjLocal);
                Monitor.PulseAll(externalLockObjLocal);
                Monitor.Exit(externalLockObjLocal);
            }
        }
        public void SlaveWaitForReset()
        {
            Assure.NotEqual(Thread.CurrentThread, LosgapSystem.MasterThread);

            Monitor.Enter(barrierClosedLock);
            if (isDisposed)
            {
                Monitor.Exit(barrierClosedLock);
                return;
            }
            Monitor.Enter(barrierOpenLock);
            if (--slavesRemaining == 0U)
            {
                barrierOpen = false;
                Monitor.Pulse(barrierOpenLock);
            }
            Monitor.Exit(barrierOpenLock);
            Monitor.Wait(barrierClosedLock);
            Monitor.Exit(barrierClosedLock);
        }
예제 #9
0
 /// <summary>
 /// Fills the memory at the given <paramref name="dest"/> address with <paramref name="numBytes"/> zeroes.
 /// </summary>
 /// <param name="dest">The destination address. Must not be <see cref="IntPtr.Zero"/>.</param>
 /// <param name="numBytes">The number of bytes from <paramref name="dest"/> to fill with zeroes.</param>
 public static void ZeroMem(IntPtr dest, uint numBytes)
 {
     Assure.NotEqual(dest, IntPtr.Zero, "Destination address must not be Zero.");
     RtlZeroMemory(dest, new IntPtr(numBytes));
 }
 /// <summary>
 /// Returns the projection of this vector on the given <paramref name="axis"/> vector (needs not be a primary world axis).
 /// </summary>
 /// <param name="axis">The axis to project on to.</param>
 /// <returns>A new Vector that is the the equivalent part of this vector that 'points' along the <paramref name="axis"/>
 /// vector.</returns>
 public Vector4 ProjectedOnto(Vector4 axis)
 {
     Assure.NotEqual(axis, ZERO, "Can not project on to zero vector.");
     axis = axis.ToUnit();
     return(Dot(this, axis) * axis);
 }
예제 #11
0
 /// <summary>
 /// Constructs a new plane with the given <paramref name="normal"/> vector,
 /// and shortest distance to the origin (<paramref name="distanceToOrigin"/>).
 /// </summary>
 /// <param name="normal">The normal vector to the plane (e.g. a vector that is perpendicular to the plane).
 /// Does not need to be unit length.</param>
 /// <param name="distanceToOrigin">The distance from the <see cref="CentrePoint"/> to the world origin.
 /// See: <see cref="DistanceToOrigin"/>.</param>
 public Plane(Vector3 normal, float distanceToOrigin)
 {
     Assure.NotEqual(normal, Vector3.ZERO, "Normal vector can not be zero vector.");
     Normal           = normal.ToUnit();
     DistanceToOrigin = distanceToOrigin;
 }
예제 #12
0
 /// <summary>
 /// Constructs a new plane with the given <paramref name="normal"/> vector,
 /// and a point on the plane (<paramref name="position"/>).
 /// </summary>
 /// <param name="normal">The normal vector to the plane (e.g. a vector that is perpendicular to the plane).
 /// Does not need to be unit length.</param>
 /// <param name="position">The position of a point that lies on the plane. Any point on the plane is acceptable
 /// (does not need to be the <see cref="CentrePoint"/>).</param>
 public Plane(Vector3 normal, Vector3 position)
 {
     Assure.NotEqual(normal, Vector3.ZERO, "Normal vector can not be zero vector.");
     Normal           = normal.ToUnit();
     DistanceToOrigin = Vector3.Dot(Normal, -position);
 }