Example #1
0
        /// <summary>
        ///     Determines whether two <see cref="IVector" /> instances are parallel to each other, or not.
        /// </summary>
        /// <param name="first">The first <see cref="IVector" />.</param>
        /// <param name="second">The second <see cref="IVector" />.</param>
        /// <returns><c>true</c> if the <see cref="IVector" /> instances are parallel to each other, otherwise <c>false</c>.</returns>
        public static bool CheckForParallelism <T>(this T first, T second) where T : IVector
        {
            if (first.IsZero || second.IsZero)
            {
                return(false);
            }

            double firstResult = 0;

            for (uint i = 0; i < first.Dimension; ++i)
            {
                if (i == 0)
                {
                    firstResult = second[i] / first[i];
                }
                else
                {
                    if (!FloatingNumber.AreApproximatelyEqual(second[i] / first[i], firstResult))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #2
0
    public void Play(string text, FloatingNumber.Type type)
    {
        if (!_isLock)
        {
            _isLock = true;
            Debug.Log("dequeue");
            FloatingNumber floatingNumber = _poolQueue.Dequeue();
            floatingNumber.Play(text, type, transform.position);

            Timer unlockTimer = new Timer(CycleTime, () => //顯示下一個數字
            {
                _isLock = false;
                if (_dataQueue.Count > 0)
                {
                    Data data = _dataQueue.Dequeue();
                    Play(data.Text, data.Type);
                }
            });

            Timer recycleTimer = new Timer(Duration, () => //當前的數字消失
            {
                Debug.Log("enqueue");
                _poolQueue.Enqueue(floatingNumber);
            });
        }
        else
        {
            Data data = new Data(text, type);
            _dataQueue.Enqueue(data);
        }
    }
Example #3
0
        public void CanRotateTwoDimensionalVector()
        {
            var firstVector   = new Vector2(0, 1);
            var rotatedVector = Matrix3x3.Rotation(MathHelper.DegreesToRadians(180)) * firstVector;

            Assert.IsTrue(FloatingNumber.AreApproximatelyEqual(firstVector.X, 0));
            Assert.AreEqual(-1, rotatedVector.Y);
        }
Example #4
0
    private void OnTakeDamage(int damageAmnt)
    {
        FloatingNumber floatingNum = Instantiate(floatingNumPrefab, numberPanel).GetComponent <FloatingNumber>();

        floatingNum.number   = damageAmnt;
        floatingNum.lifetime = lifetime;
        floatingNum.speed    = speed;
    }
    public GameObject CreateFloatingNumber(Color startCol, Color endCol, float duration, float velocity, string text)
    {
        GameObject     floaty = Instantiate(FloatingNumber);
        FloatingNumber num    = floaty.GetComponent <FloatingNumber> ();

        num.duration      = duration; num.upVelocity = velocity; num.text = text;
        num.startingColor = startCol; num.endColor = endCol;
        return(floaty);
    }
Example #6
0
        public void CanCalculateArea()
        {
            var    firstVector  = new Vector3(3, 4, 4);
            var    secondVector = new Vector3(1, -2, 3);
            double area         = Vector3.Area(firstVector, secondVector);

            Assert.AreEqual(Math.Sqrt(525), area);

            var    thirdVector  = new Vector2(2, 4);
            var    fourthVector = new Vector2(3, 1);
            double secondArea   = Vector2.Area(thirdVector, fourthVector);

            Assert.IsTrue(FloatingNumber.AreApproximatelyEqual(10, secondArea));
        }
Example #7
0
        void addNumber(PointF pos, Color color, int value, Entity entity, bool combo = false)
        {
            FloatingNumber n;

            if (color == hpHealC || color == hpDamC)
            {
                n = new FloatingNumber(pos, color, Config.formatHpDam(value))
                {
                    value = value, entity = entity
                };
            }
            else if (color == postHealC || color == postDamC)
            {
                n = new FloatingNumber(pos, color, Config.formatPostDam(value))
                {
                    value = value, entity = entity
                };
            }
            else if (color == poisonDamC)
            {
                n = new FloatingNumber(pos, color, Config.formatPoisonDam(value))
                {
                    value = value, entity = entity
                };
            }
            else
            {
                n = new FloatingNumber(pos, color, Config.formatFireDam(value))
                {
                    value = value, entity = entity
                };
            }
            if (combo)  //TODO wtf it should be separate for each number
            {
                n.big = 5;
            }
            foreach (var e in numbers.ToArray())
            {
                if (e.color == n.color && e.counter <= Config.comboTime && e.entity == n.entity)    //merge two close numbers
                {
                    Console.WriteLine(numbers.Count);
                    numbers.Remove(e);
                    Console.WriteLine(numbers.Count);
                    addNumber(pos, color, value + e.value, entity, false);
                    return;
                }
            }
            numbers.Add(n);
        }
Example #8
0
        /// <summary>
        ///     Determines whether the specified <see cref="Point3D" /> is on the <see cref="Line3D" />, or not.
        /// </summary>
        /// <param name="point">The <see cref="Point3D" />.</param>
        /// <returns><c>true</c>, if the <see cref="Point3D" /> is on the <see cref="Line3D" />; otherwise <c>false</c>.</returns>
        public bool IsPointOnLine(Point3D point)
        {
            double lambda = 0;

            for (uint i = 0; i < 3; ++i)
            {
                double value = (point[i] - Point[i]) / Direction[i];
                if (i != 0 && !FloatingNumber.AreApproximatelyEqual(value, lambda))
                {
                    return(false);
                }
                lambda = value;
            }

            return(true);
        }
Example #9
0
        public void CanCalculateArea()
        {
            var square =
                new Polygon(new Point2D(0, 0), new Point2D(2, 0), new Point2D(2, 2), new Point2D(0, 2));

            Assert.IsTrue(FloatingNumber.AreApproximatelyEqual(4, square.Area));

            var triangle =
                new Polygon(new Point2D(0, 0), new Point2D(2, 0), new Point2D(1, 2));

            Assert.AreEqual(2, triangle.Area);

            var polygon = new Polygon(new Point2D(-2, -2), new Point2D(2, -2), new Point2D(4, 1), new Point2D(0, 2),
                                      new Point2D(-4, 1));

            Assert.AreEqual(22, polygon.Area);
        }
Example #10
0
        //public static T GetInverse<T>(this ISquareMatrix matrix) where T : ISquareMatrix, new()
        //{
        //    if (matrix.Determinant.IsApproximatelyEqualTo(0))
        //        throw new InvalidOperationException("The specified matrix does not have an inverse.");
        //    return GaussJordan(matrix, GetIdentity())
        //}

        /// <summary>
        ///     Determines whether the <see cref="ISquareMatrix" /> is a diagonal <see cref="ISquareMatrix" />, or not.
        /// </summary>
        /// <param name="matrix">The <see cref="ISquareMatrix" />.</param>
        /// <returns>
        ///     <c>true</c>, if the <see cref="ISquareMatrix" /> is a diagonal <see cref="ISquareMatrix" />, otherwise
        ///     <c>false</c>.
        /// </returns>
        public static bool GetIsDiagonal(this ISquareMatrix matrix)
        {
            if (matrix.Dimension == 1)
            {
                return(false);
            }

            for (uint y = 0; y < matrix.RowCount; ++y)
            {
                for (uint x = 0; x < matrix.ColumnCount; ++x)
                {
                    if (y == x && FloatingNumber.AreApproximatelyEqual(matrix[y, x], 0) ||
                        y != x && !FloatingNumber.AreApproximatelyEqual(matrix[y, x], 0))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #11
0
        // https://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan
        private int ContainsPointInternal(Point2D q, Point2D p1, Point2D p2)
        {
            if (FloatingNumber.AreApproximatelyEqual(q.Y, p1.Y) &&
                FloatingNumber.AreApproximatelyEqual(q.Y, p2.Y))
            {
                if (p1.X <= q.X && q.X <= p2.X ||
                    p2.X <= q.X && q.X <= p1.X)
                {
                    return(0);
                }
                return(1);
            }

            if (p1.Y > p2.Y)
            {
                var currentP1 = p1;
                p1 = p2;
                p2 = currentP1;
            }

            if (FloatingNumber.AreApproximatelyEqual(q.Y, p1.Y) &&
                FloatingNumber.AreApproximatelyEqual(q.X, p1.X))
            {
                return(0);
            }

            if (q.Y <= p1.Y || q.Y > p2.Y)
            {
                return(1);
            }

            var delta = (p1.X - q.X) * (p2.Y - q.Y) - (p1.Y - q.Y) * (p2.X - q.X);

            if (delta > 0)
            {
                return(-1);
            }
            return(delta < 0 ? 1 : 0);
        }
Example #12
0
    private void Play(Data data)
    {
        _isLock = true;
        FloatingNumber floatingNumber = _poolQueue.Dequeue();

        floatingNumber.Play(data.Text, data.Type, transform.position);

        Timer unlockTimer = new Timer(CycleTime, () => //顯示下一個數字
        {
            _isLock = false;
            if (_dataQueue.Count > 0)
            {
                Play(_dataQueue.Dequeue());
            }
        });

        Timer recycleTimer = new Timer(Duration, () => //當前的數字消失
        {
            Debug.Log("enqueue");
            _poolQueue.Enqueue(floatingNumber);
        });
    }
 /// <summary>
 ///     Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
 /// </summary>
 /// <param name="number">The current <see cref="float" />.</param>
 /// <param name="other">The other <see cref="float" />.</param>
 /// <param name="epsilon">The epsilon value that represents the tolerance.</param>
 /// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
 public static bool IsApproximatelyEqualTo(this float number, float other, double epsilon)
 => FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
Example #14
0
 /// <summary>
 ///     Implements the operator !=.
 /// </summary>
 /// <param name="left">The left <see cref="Matrix1x1" />.</param>
 /// <param name="right">The right <see cref="Matrix1x1" />.</param>
 /// <returns>
 ///     The result of the operator.
 /// </returns>
 public static bool operator !=(Matrix1x1 left, Matrix1x1 right)
 {
     return(!FloatingNumber.AreApproximatelyEqual(left[0, 0], right[0, 0]));
 }
Example #15
0
 /// <summary>
 ///     Determines whether two <see cref="IVector" /> instances are orthogonal to each other, or not.
 /// </summary>
 /// <param name="first">The first <see cref="IVector" />.</param>
 /// <param name="second">The second <see cref="IVector" />.</param>
 /// <returns><c>true</c>, if the <see cref="IVector" /> instances are orthogonal to each other, otherwise <c>false</c>.</returns>
 public static bool CheckForOrthogonality <T>(this T first, T second) where T : IVector
 {
     return(!first.IsZero && !second.IsZero && FloatingNumber.AreApproximatelyEqual(DotProduct(first, second), 0));
 }
Example #16
0
 /// <summary>
 ///     Determines whether this <see cref="Line2D" /> is parallel to the specified <see cref="Line2D" />.
 /// </summary>
 /// <param name="line">The other <see cref="Line2D" />.</param>
 /// <returns>
 ///     <c>true</c> if this <see cref="Line2D" /> is parallel to the specified <see cref="Line2D" />, otherwise
 ///     <c>false</c>.
 /// </returns>
 public bool IsParallelTo(Line2D line)
 {
     return(FloatingNumber.AreApproximatelyEqual(Slope, line.Slope));
 }
Example #17
0
 /// <summary>
 ///     Determines whether two floating numbers are approximately equal to each other using the specified epsilon value.
 /// </summary>
 /// <param name="number">The current <see cref="float" />.</param>
 /// <param name="other">The other <see cref="float" />.</param>
 /// <param name="epsilon">The epsilon value that represents the tolerance.</param>
 /// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
 public static bool IsApproximatelyEqualTo(this double number, double other, double epsilon)
 {
     return(FloatingNumber.AreApproximatelyEqual(number, other, epsilon));
 }
Example #18
0
 /// <summary>
 ///     Determines whether two floating numbers are approximately equal to each other using the
 ///     <see cref="FloatingNumber.Epsilon" /> value.
 /// </summary>
 /// <param name="number">The current <see cref="float" />.</param>
 /// <param name="other">The other <see cref="float" />.</param>
 /// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
 public static bool IsApproximatelyEqualTo(this float number, float other)
 {
     return(FloatingNumber.AreApproximatelyEqual(number, other));
 }
 /// <summary>
 ///     Determines whether two floating numbers are approximately equal to each other using the
 ///     <see cref="FloatingNumber.Epsilon" />
 ///     value.
 /// </summary>
 /// <param name="number">The current <see cref="float" />.</param>
 /// <param name="other">The other <see cref="float" />.</param>
 /// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
 public static bool IsApproximatelyEqualTo(this double number, double other)
 => FloatingNumber.AreApproximatelyEqual(number, other);