public void IsWithinArc_NormalCaseOutsideTolerance_ReturnsTrue()
        {
            Vector2 diagonalUpRight = new Vector2(1.0f, 1.0f);
            Vector2 diagonalUpLeft  = new Vector2(-1.0f, 1.0f);

            Assert.False(diagonalUpLeft.IsDirectionWithinArc(diagonalUpRight, 179.0f), "DiagonalUpRight and DiagonalUpLeft should be not be within 179 degrees.");
        }
        public void IsWithinArc_ZeroArcDirection_ReturnsFalse()
        {
            Vector2 unit       = Vector2.up;
            Vector2 zeroTarget = Vector2.zero;

            Assert.False(unit.IsDirectionWithinArc(zeroTarget, 180.0f), "Zero target vector should never be within degrees.");
        }
        public void IsWithinArc_ZeroSourceVector_ReturnsFalse()
        {
            Vector2 zero     = Vector2.zero;
            Vector2 upTarget = Vector2.up;

            Assert.False(zero.IsDirectionWithinArc(upTarget, 180.0f), "Zero source vector should never be within degrees.");
        }
Beispiel #4
0
        /// <summary>
        /// If the supplied vector is within the supplied angle of a cardinal direction, this will
        /// return the cardinal direction. Otherwise it will just return the same angle.
        /// </summary>
        /// <returns>The cardinal direction within the specified bias.</returns>
        /// <param name="vectorToBias">Vector to bias.</param>
        /// <param name="biasAngle">Bias angle.</param>
        public static Vector2 BiasToCardinals(this Vector2 vectorToBias, float biasAngle)
        {
            if (biasAngle > 90.0f)
            {
                // When biasing by greater than quadrant, bias to nearest 90, not by first vector we test against.
                biasAngle = 90.0f;
            }
            // Can't bias by negative degrees
            if (biasAngle < 0.0f)
            {
                return(vectorToBias);
            }
            Vector2 biasedVector = vectorToBias;
            float   assistAngle  = biasAngle;

            Vector2[] cardinals = new Vector2[]
            {
                Vector2.right,
                Vector2.up,
                -Vector2.right,
                -Vector2.up
            };
            foreach (Vector2 direction in cardinals)
            {
                if (vectorToBias.IsDirectionWithinArc(direction, assistAngle))
                {
                    biasedVector = direction;

                    // Restore magnitude of original vector
                    biasedVector *= vectorToBias.magnitude;
                    break;
                }
            }

            return(biasedVector);
        }
        public void IsWithinArc_NormalCaseOutsideTolerance_ReturnsTrue()
        {
            Vector2 diagonalUpRight = new Vector2(1.0f, 1.0f);
            Vector2 diagonalUpLeft = new Vector2(-1.0f, 1.0f);

            Assert.False(diagonalUpLeft.IsDirectionWithinArc(diagonalUpRight, 179.0f), "DiagonalUpRight and DiagonalUpLeft should be not be within 179 degrees.");
        }
        public void IsWithinArc_NormalCaseInTolerance_ReturnsTrue()
        {
            Vector2 diagonalUpLeft = new Vector2(-1.0f, 1.0f);

            Assert.True(diagonalUpLeft.IsDirectionWithinArc(Vector2.up, 90.0f), "DiagonalUpLeft should be inside the 90 degree up arc.");
        }
        public void IsWithinArc_NormalCaseInTolerance_ReturnsTrue()
        {
            Vector2 diagonalUpLeft = new Vector2(-1.0f, 1.0f);

            Assert.True(diagonalUpLeft.IsDirectionWithinArc(Vector2.up, 90.0f), "DiagonalUpLeft should be inside the 90 degree up arc.");
        }