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) })); }
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; } }
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)); } } }