Beispiel #1
0
        public void TestRemoveVertices()
        {
            var path = new JuiceStreamPath();

            path.Add(10, 5);
            path.Add(20, -5);

            int removeCount = path.RemoveVertices((v, i) => v.Distance == 10 && i == 1);

            Assert.That(removeCount, Is.EqualTo(1));
            Assert.That(path.Vertices, Is.EqualTo(new[]
            {
                new JuiceStreamPathVertex(0, 0),
                new JuiceStreamPathVertex(20, -5)
            }));

            removeCount = path.RemoveVertices((_, i) => i == 0);
            Assert.That(removeCount, Is.EqualTo(1));
            Assert.That(path.Vertices, Is.EqualTo(new[]
            {
                new JuiceStreamPathVertex(20, -5)
            }));

            removeCount = path.RemoveVertices((_, i) => true);
            Assert.That(removeCount, Is.EqualTo(1));
            Assert.That(path.Vertices, Is.EqualTo(new[]
            {
                new JuiceStreamPathVertex()
            }));
        }
Beispiel #2
0
        public void TestResampleVertices()
        {
            var path = new JuiceStreamPath();

            path.Add(-100, -10);
            path.Add(100, 50);
            path.ResampleVertices(new double[]
            {
                -50,
                0,
                70,
                120
            });
            Assert.That(path.Vertices, Is.EqualTo(new[]
            {
                new JuiceStreamPathVertex(-100, -10),
                new JuiceStreamPathVertex(-50, -5),
                new JuiceStreamPathVertex(0, 0),
                new JuiceStreamPathVertex(70, 35),
                new JuiceStreamPathVertex(100, 50),
                new JuiceStreamPathVertex(100, 50),
            }));

            path.Clear();
            path.SetVertexPosition(0, 10);
            path.ResampleVertices(Array.Empty <double>());
            Assert.That(path.Vertices, Is.EqualTo(new[]
            {
                new JuiceStreamPathVertex(0, 10)
            }));
        }
Beispiel #3
0
        public void TestInvalidation()
        {
            var path = new JuiceStreamPath();

            Assert.That(path.InvalidationID, Is.EqualTo(1));
            int previousId = path.InvalidationID;

            path.InsertVertex(10);
            checkNewId();

            path.SetVertexPosition(1, 5);
            checkNewId();

            path.Add(20, 0);
            checkNewId();

            path.RemoveVertices((v, _) => v.Distance == 20);
            checkNewId();

            path.ResampleVertices(new double[] { 5, 10, 15 });
            checkNewId();

            path.Clear();
            checkNewId();

            path.ConvertFromSliderPath(new SliderPath());
            checkNewId();

            void checkNewId()
            {
                Assert.That(path.InvalidationID, Is.Not.EqualTo(previousId));
                previousId = path.InvalidationID;
            }
        }
        private void addBlueprintStep(double[] times, float[] positions, double velocity = 0.5)
        {
            var path = new JuiceStreamPath();
            for (int i = 1; i < times.Length; i++)
                path.Add((times[i] - times[0]) * velocity, positions[i] - positions[0]);

            var sliderPath = new SliderPath();
            path.ConvertToSliderPath(sliderPath, 0);
            addBlueprintStep(times[0], positions[0], sliderPath, velocity);
        }
Beispiel #5
0
        public void TestRandomConvertToSliderPath()
        {
            var rng        = new Random(1);
            var path       = new JuiceStreamPath();
            var sliderPath = new SliderPath();

            for (int iteration = 0; iteration < 10000; iteration++)
            {
                path.Clear();

                do
                {
                    double time = rng.NextDouble() * 1e3;
                    float  x    = (float)(rng.NextDouble() * 1e3);
                    path.Add(time, x);
                } while (rng.Next(5) != 0);

                float sliderStartY = (float)(rng.NextDouble() * JuiceStreamPath.OSU_PLAYFIELD_HEIGHT);

                double requiredVelocity = path.ComputeRequiredVelocity();
                double velocity         = Math.Clamp(requiredVelocity, 1, 100);

                path.ConvertToSliderPath(sliderPath, sliderStartY, velocity);

                foreach (var point in sliderPath.ControlPoints)
                {
                    Assert.That(point.Type, Is.EqualTo(PathType.Linear).Or.Null);
                    Assert.That(sliderStartY + point.Position.Y, Is.InRange(0, JuiceStreamPath.OSU_PLAYFIELD_HEIGHT));
                }

                Assert.That(sliderPath.ControlPoints[0].Position.X, Is.EqualTo(path.Vertices[0].X));

                // The path is preserved only if required velocity is used.
                if (velocity < requiredVelocity)
                {
                    continue;
                }

                Assert.That(sliderPath.Distance / velocity, Is.EqualTo(path.Duration).Within(1e-3));

                for (int i = 0; i < 10; i++)
                {
                    double time     = rng.NextDouble() * path.Duration;
                    float  expected = path.PositionAtTime(time);
                    Assert.That(sliderPath.PositionAt(time * velocity / sliderPath.Distance).X, Is.EqualTo(expected).Within(3e-3));
                }
            }
        }
Beispiel #6
0
        public void TestRandomConvertToSliderPath()
        {
            var rng        = new Random(1);
            var path       = new JuiceStreamPath();
            var sliderPath = new SliderPath();

            for (int iteration = 0; iteration < 10000; iteration++)
            {
                path.Clear();

                do
                {
                    double distance = rng.NextDouble() * 1e3;
                    float  x        = (float)(rng.NextDouble() * 1e3);
                    path.Add(distance, x);
                } while (rng.Next(5) != 0);

                float sliderStartY = (float)(rng.NextDouble() * JuiceStreamPath.OSU_PLAYFIELD_HEIGHT);

                path.ConvertToSliderPath(sliderPath, sliderStartY);
                Assert.That(sliderPath.Distance, Is.EqualTo(path.Distance).Within(1e-3));
                Assert.That(sliderPath.ControlPoints[0].Position.X, Is.EqualTo(path.Vertices[0].X));
                assertInvariants(path.Vertices, true);

                foreach (var point in sliderPath.ControlPoints)
                {
                    Assert.That(point.Type, Is.EqualTo(PathType.Linear).Or.Null);
                    Assert.That(sliderStartY + point.Position.Y, Is.InRange(0, JuiceStreamPath.OSU_PLAYFIELD_HEIGHT));
                }

                for (int i = 0; i < 10; i++)
                {
                    double distance = rng.NextDouble() * path.Distance;
                    float  expected = path.PositionAtDistance(distance);
                    Assert.That(sliderPath.PositionAt(distance / sliderPath.Distance).X, Is.EqualTo(expected).Within(1e-3));
                }
            }
        }