private void posUpdater(CancellationToken aCancellationToken)
        {
            LinearCurrentTime = DateTime.Now.Ticks;
            while (!aCancellationToken.IsCancellationRequested)
            {
                var now = DateTime.Now.Ticks;
                if (LinearCurrentPosition != LinearTargetPosition)
                {
                    var diff  = FleshlightHelper.GetDistance(Convert.ToUInt32(new TimeSpan(now - LinearCurrentTime).TotalMilliseconds), LinearSpeed);
                    var diff2 = LinearTargetPosition - LinearCurrentPosition;
                    if (diff2 < 0)
                    {
                        diff *= -1;
                        diff  = Math.Max(diff2, diff);
                    }
                    else
                    {
                        diff = Math.Min(diff2, diff);
                    }

                    LinearCurrentPosition += diff;

                    Dispatcher.Invoke(() =>
                    {
                        LinearPosition.Value = LinearCurrentPosition * LinearPosition.Maximum;
                    });
                }

                LinearCurrentTime = now;
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 2
0
 public void TestOutOfBounds()
 {
     (Math.Abs(FleshlightHelper.GetSpeed(0, 500) - FleshlightHelper.GetSpeed(-1, 500)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetSpeed(1, 500) - FleshlightHelper.GetSpeed(2, 500)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(100, 0) - FleshlightHelper.GetDistance(100, -1)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(100, 1) - FleshlightHelper.GetDistance(100, 2)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(1000, 0.17379819904439015016403395523936)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0.5, 0) - FleshlightHelper.GetDuration(0.5, -1)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0.5, 1) - FleshlightHelper.GetDuration(0.5, 2)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0, 0.5) - FleshlightHelper.GetDuration(-1, 0.5)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(1, 0.5) - FleshlightHelper.GetDuration(2, 0.5)) < 0.0001).Should().BeTrue();
 }
Ejemplo n.º 3
0
        public void TestRoundTrip()
        {
            var delta = FleshlightHelper.GetDistance(100, 0.5);
            var speed = FleshlightHelper.GetSpeed(delta, 100);
            var time  = FleshlightHelper.GetDuration(delta, 0.5);

            (Math.Abs(0.5 - speed) < 0.01).Should().BeTrue();
            (Math.Abs(100 - time) < 0.01).Should().BeTrue();

            var speed2 = FleshlightHelper.GetSpeed(0.5, 500);
            var delta2 = FleshlightHelper.GetDistance(500, speed2);
            var time2  = FleshlightHelper.GetDuration(0.5, speed2);

            (Math.Abs(0.5 - delta2) < 0.01).Should().BeTrue();
            (Math.Abs(500 - time2) < 10).Should().BeTrue();

            var time3  = Convert.ToUInt32(FleshlightHelper.GetDuration(0.5, 0.5));
            var speed3 = FleshlightHelper.GetSpeed(0.5, time3);
            var delta3 = FleshlightHelper.GetDistance(time3, 0.5);

            (Math.Abs(0.5 - delta3) < 0.01).Should().BeTrue();
            (Math.Abs(0.5 - speed3) < 0.01).Should().BeTrue();
        }