Пример #1
0
        public void TestRandomConvertFromSliderPath()
        {
            var rng        = new Random(1);
            var path       = new JuiceStreamPath();
            var sliderPath = new SliderPath();

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

                do
                {
                    int start = sliderPath.ControlPoints.Count;

                    do
                    {
                        float x = (float)(rng.NextDouble() * 1e3);
                        float y = (float)(rng.NextDouble() * 1e3);
                        sliderPath.ControlPoints.Add(new PathControlPoint(new Vector2(x, y)));
                    } while (rng.Next(2) != 0);

                    int length = sliderPath.ControlPoints.Count - start + 1;
                    sliderPath.ControlPoints[start].Type = length <= 2 ? PathType.Linear : length == 3 ? PathType.PerfectCurve : PathType.Bezier;
                } while (rng.Next(3) != 0);

                if (rng.Next(5) == 0)
                {
                    sliderPath.ExpectedDistance.Value = rng.NextDouble() * 3e3;
                }
                else
                {
                    sliderPath.ExpectedDistance.Value = null;
                }

                path.ConvertFromSliderPath(sliderPath);
                Assert.That(path.Vertices[0].Distance, Is.EqualTo(0));
                Assert.That(path.Distance, Is.EqualTo(sliderPath.Distance).Within(1e-3));
                assertInvariants(path.Vertices, true);

                double[] sampleDistances = Enumerable.Range(0, 10)
                                           .Select(_ => rng.NextDouble() * sliderPath.Distance)
                                           .ToArray();

                foreach (double distance in sampleDistances)
                {
                    float expected = sliderPath.PositionAt(distance / sliderPath.Distance).X;
                    Assert.That(path.PositionAtDistance(distance), Is.EqualTo(expected).Within(1e-3));
                }

                path.ResampleVertices(sampleDistances);
                assertInvariants(path.Vertices, true);

                foreach (double distance in sampleDistances)
                {
                    float expected = sliderPath.PositionAt(distance / sliderPath.Distance).X;
                    Assert.That(path.PositionAtDistance(distance), Is.EqualTo(expected).Within(1e-3));
                }
            }
        }
Пример #2
0
        public void TestRandomInsertSetPosition(double scale, bool checkSlope, bool integralValues)
        {
            var rng  = new Random(1);
            var path = new JuiceStreamPath();

            for (int iteration = 0; iteration < 100000; iteration++)
            {
                if (rng.Next(10) == 0)
                {
                    path.Clear();
                }

                int vertexCount = path.Vertices.Count;

                switch (rng.Next(2))
                {
                case 0:
                {
                    double distance = rng.NextDouble() * scale * 2 - scale;
                    if (integralValues)
                    {
                        distance = Math.Round(distance);
                    }

                    float oldX  = path.PositionAtDistance(distance);
                    int   index = path.InsertVertex(distance);
                    Assert.That(path.Vertices.Count, Is.EqualTo(vertexCount + 1));
                    Assert.That(path.Vertices[index].Distance, Is.EqualTo(distance));
                    Assert.That(path.Vertices[index].X, Is.EqualTo(oldX));
                    break;
                }

                case 1:
                {
                    int    index    = rng.Next(path.Vertices.Count);
                    double distance = path.Vertices[index].Distance;
                    float  newX     = (float)(rng.NextDouble() * scale * 2 - scale);
                    if (integralValues)
                    {
                        newX = MathF.Round(newX);
                    }

                    path.SetVertexPosition(index, newX);
                    Assert.That(path.Vertices.Count, Is.EqualTo(vertexCount));
                    Assert.That(path.Vertices[index].Distance, Is.EqualTo(distance));
                    Assert.That(path.Vertices[index].X, Is.EqualTo(newX));
                    break;
                }
                }

                assertInvariants(path.Vertices, checkSlope);
            }
        }
Пример #3
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));
                }
            }
        }