public void TestRandomConvertFromSliderPath(double velocity) { 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, velocity); Assert.That(path.Vertices[0].Time, Is.EqualTo(0)); Assert.That(path.Duration * velocity, Is.EqualTo(sliderPath.Distance).Within(1e-3)); assertInvariants(path.Vertices); double[] sampleTimes = Enumerable.Range(0, 10) .Select(_ => rng.NextDouble() * sliderPath.Distance / velocity) .ToArray(); foreach (double time in sampleTimes) { float expected = sliderPath.PositionAt(time * velocity / sliderPath.Distance).X; Assert.That(path.PositionAtTime(time), Is.EqualTo(expected).Within(1e-3)); } path.ResampleVertices(sampleTimes); assertInvariants(path.Vertices); foreach (double time in sampleTimes) { float expected = sliderPath.PositionAt(time * velocity / sliderPath.Distance).X; Assert.That(path.PositionAtTime(time), Is.EqualTo(expected).Within(1e-3)); } } }
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 time = rng.NextDouble() * scale * 2 - scale; if (integralValues) { time = Math.Round(time); } float oldX = path.PositionAtTime(time); int index = path.InsertVertex(time); Assert.That(path.Vertices.Count, Is.EqualTo(vertexCount + 1)); Assert.That(path.Vertices[index].Time, Is.EqualTo(time)); Assert.That(path.Vertices[index].X, Is.EqualTo(oldX)); break; } case 1: { int index = rng.Next(path.Vertices.Count); double time = path.Vertices[index].Time; 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].Time, Is.EqualTo(time)); Assert.That(path.Vertices[index].X, Is.EqualTo(newX)); break; } } assertInvariants(path.Vertices); } }
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)); } } }