Example #1
0
        public bool AnimateRenderPosition(bool isAnimating, DateTime utcNow, float animationSpeed)
        {
            if (IsVisible)
            {
                if (isAnimating && animationTargetPosition != MathHelper.PositiveInfinityVector2)
                {
                    if (animationTargetPosition != targetLayoutPosition)
                    {
                        animatingEndUtc = utcNow.AddMilliseconds(animationSpeed);
                    }
                }
                else
                {
                    animatingEndUtc = null;
                }

                animationTargetPosition = targetLayoutPosition;

                float fractionComplete = 1;

                if (animatingEndUtc.HasValue)
                {
                    var timeRemaining = (float)(animatingEndUtc.Value - utcNow).TotalMilliseconds;

                    fractionComplete -= Math.Min(1, Math.Max(0, timeRemaining / animationSpeed));
                }

                UpdatePosition(
                    new Vector2(
                        MathHelper.Interpolate(fractionComplete, RenderPosition.X, targetLayoutPosition.X),
                        MathHelper.Interpolate(fractionComplete, RenderPosition.Y, targetLayoutPosition.Y)));

                return(!MathHelper.AboutEqual(targetLayoutPosition, RenderPosition));
            }

            animationTargetPosition = MathHelper.PositiveInfinityVector2;

            return(false);
        }
Example #2
0
        public void AboutEquals_Vector2_ByEpsilon_ReturnsTrue()
        {
            Vector2 v = new Vector2(10, 50);

            Assert.True(MathHelper.AboutEqual(v, v + new Vector2(float.Epsilon, float.Epsilon)));
        }
Example #3
0
        public void AboutEquals_Double_ByEpsilon_ReturnsTrue()
        {
            double v = 10;

            Assert.True(MathHelper.AboutEqual(v, v + double.Epsilon));
        }
Example #4
0
        public void AboutEquals_Float_ByEpsilon_ReturnsTrue()
        {
            float v = 10;

            Assert.True(MathHelper.AboutEqual(v, v + float.Epsilon));
        }