public void Sort() { Path3F empty = new Path3F(); empty.Sort(); Path3F path = CreatePath(); // Un-sort the keys. path[7].Parameter = 13; path.Sort(); Assert.AreEqual(8, path.Count); Assert.AreEqual(10, path[0].Parameter); Assert.AreEqual(13, path[1].Parameter); Assert.AreEqual(15, path[2].Parameter); // ... Assert.AreEqual(35, path[7].Parameter); }
public void GetLength() { Path3F empty = new Path3F(); empty.Sort(); Assert.AreEqual(0, empty.GetLength(0, 1, 100, 0.0001f)); Path3F path = CreatePath(); path.PreLoop = CurveLoopType.Constant; path.PostLoop = CurveLoopType.Oscillate; Assert.IsTrue(Numeric.AreEqual((new Vector3F(0, 0, 1) - new Vector3F(1, 2, 3)).Length, path.GetLength(-1, 12, 100, 0.0001f), 0.001f)); Assert.IsTrue(Numeric.AreEqual((new Vector3F(0, 0, 1) - new Vector3F(1, 2, 3)).Length, path.GetLength(-1, 20, 100, 0.0001f), 0.001f)); CatmullRomSegment3F catmullOscillate = new CatmullRomSegment3F() { Point1 = new Vector3F(10, 12, 14), Point2 = new Vector3F(10, 14, 8), Point3 = new Vector3F(20, 14, 8), Point4 = new Vector3F(30, 14, 8), }; float desiredLength = catmullOscillate.GetLength(0, 1, 20, 0.0001f); float actualLength = path.GetLength(40, 50, 20, 0.0001f); Assert.IsTrue(Numeric.AreEqual(desiredLength, actualLength, 0.001f)); desiredLength = catmullOscillate.GetLength(1, 0.8f, 20, 0.0001f); actualLength = path.GetLength(52, 50, 20, 0.0001f); Assert.IsTrue(Numeric.AreEqual(desiredLength, actualLength, 0.001f)); desiredLength = catmullOscillate.GetLength(1, 0.8f, 20, 0.0001f) * 2; actualLength = path.GetLength(52, 48, 20, 0.0001f); Assert.IsTrue(Numeric.AreEqual(desiredLength, actualLength, 0.001f)); path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Cycle; path.PreLoop = CurveLoopType.Cycle; path.PostLoop = CurveLoopType.CycleOffset; path.PreLoop = CurveLoopType.CycleOffset; path.PostLoop = CurveLoopType.Linear; path.PreLoop = CurveLoopType.Oscillate; path.PostLoop = CurveLoopType.Constant; }
public void LoopParameter() { Path3F empty = new Path3F(); empty.Sort(); Assert.AreEqual(3, empty.LoopParameter(3)); Assert.AreEqual(false, empty.IsInMirroredOscillation(3)); Path3F path = CreatePath(); path.PreLoop = CurveLoopType.Constant; path.PostLoop = CurveLoopType.Oscillate; Assert.AreEqual(10, path.LoopParameter(3)); Assert.AreEqual(false, path.IsInMirroredOscillation(3)); Assert.AreEqual(10, path.LoopParameter(10)); Assert.AreEqual(false, path.IsInMirroredOscillation(10)); Assert.AreEqual(13, path.LoopParameter(13)); Assert.AreEqual(false, path.IsInMirroredOscillation(13)); Assert.AreEqual(40, path.LoopParameter(40)); Assert.AreEqual(false, path.IsInMirroredOscillation(40)); Assert.AreEqual(35, path.LoopParameter(45)); Assert.AreEqual(true, path.IsInMirroredOscillation(45)); Assert.AreEqual(14, path.LoopParameter(74)); Assert.AreEqual(false, path.IsInMirroredOscillation(74)); path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Cycle; Assert.AreEqual(3, path.LoopParameter(3)); Assert.AreEqual(false, path.IsInMirroredOscillation(3)); Assert.AreEqual(10, path.LoopParameter(10)); Assert.AreEqual(false, path.IsInMirroredOscillation(10)); Assert.AreEqual(13, path.LoopParameter(13)); Assert.AreEqual(false, path.IsInMirroredOscillation(13)); Assert.AreEqual(40, path.LoopParameter(40)); Assert.AreEqual(false, path.IsInMirroredOscillation(40)); Assert.AreEqual(15, path.LoopParameter(45)); Assert.AreEqual(false, path.IsInMirroredOscillation(45)); Assert.AreEqual(14, path.LoopParameter(74)); Assert.AreEqual(false, path.IsInMirroredOscillation(74)); path.PreLoop = CurveLoopType.Cycle; path.PostLoop = CurveLoopType.CycleOffset; Assert.AreEqual(20, path.LoopParameter(-40)); Assert.AreEqual(false, path.IsInMirroredOscillation(-40)); Assert.AreEqual(33, path.LoopParameter(3)); Assert.AreEqual(false, path.IsInMirroredOscillation(3)); Assert.AreEqual(10, path.LoopParameter(10)); Assert.AreEqual(false, path.IsInMirroredOscillation(10)); Assert.AreEqual(13, path.LoopParameter(13)); Assert.AreEqual(false, path.IsInMirroredOscillation(13)); Assert.AreEqual(40, path.LoopParameter(40)); Assert.AreEqual(false, path.IsInMirroredOscillation(40)); Assert.AreEqual(15, path.LoopParameter(45)); Assert.AreEqual(false, path.IsInMirroredOscillation(45)); Assert.AreEqual(14, path.LoopParameter(74)); Assert.AreEqual(false, path.IsInMirroredOscillation(74)); Assert.AreEqual(20, path.LoopParameter(200)); Assert.AreEqual(false, path.IsInMirroredOscillation(200)); path.PreLoop = CurveLoopType.CycleOffset; path.PostLoop = CurveLoopType.Linear; Assert.AreEqual(20, path.LoopParameter(-40)); Assert.AreEqual(false, path.IsInMirroredOscillation(-40)); Assert.AreEqual(33, path.LoopParameter(3)); Assert.AreEqual(false, path.IsInMirroredOscillation(3)); Assert.AreEqual(10, path.LoopParameter(10)); Assert.AreEqual(false, path.IsInMirroredOscillation(10)); Assert.AreEqual(13, path.LoopParameter(13)); Assert.AreEqual(false, path.IsInMirroredOscillation(13)); Assert.AreEqual(40, path.LoopParameter(40)); Assert.AreEqual(false, path.IsInMirroredOscillation(40)); Assert.AreEqual(45, path.LoopParameter(45)); Assert.AreEqual(false, path.IsInMirroredOscillation(45)); Assert.AreEqual(74, path.LoopParameter(74)); Assert.AreEqual(false, path.IsInMirroredOscillation(74)); Assert.AreEqual(200, path.LoopParameter(200)); Assert.AreEqual(false, path.IsInMirroredOscillation(200)); path.PreLoop = CurveLoopType.Oscillate; path.PostLoop = CurveLoopType.Constant; Assert.AreEqual(20, path.LoopParameter(-40)); Assert.AreEqual(false, path.IsInMirroredOscillation(-40)); Assert.AreEqual(17, path.LoopParameter(3)); Assert.AreEqual(true, path.IsInMirroredOscillation(3)); Assert.AreEqual(10, path.LoopParameter(10)); Assert.AreEqual(false, path.IsInMirroredOscillation(10)); Assert.AreEqual(13, path.LoopParameter(13)); Assert.AreEqual(false, path.IsInMirroredOscillation(13)); Assert.AreEqual(40, path.LoopParameter(40)); Assert.AreEqual(false, path.IsInMirroredOscillation(40)); Assert.AreEqual(40, path.LoopParameter(45)); Assert.AreEqual(false, path.IsInMirroredOscillation(45)); Assert.AreEqual(40, path.LoopParameter(74)); Assert.AreEqual(false, path.IsInMirroredOscillation(74)); Assert.AreEqual(40, path.LoopParameter(200)); Assert.AreEqual(false, path.IsInMirroredOscillation(200)); }
public void GetKey() { Path3F empty = new Path3F(); empty.Sort(); Assert.AreEqual(-1, empty.GetKeyIndex(20)); Path3F path = CreatePath(); path.PreLoop = CurveLoopType.Constant; path.PostLoop = CurveLoopType.Oscillate; Assert.AreEqual(0, path.GetKeyIndex(-28)); Assert.AreEqual(0, path.GetKeyIndex(3)); Assert.AreEqual(0, path.GetKeyIndex(10)); Assert.AreEqual(3, path.GetKeyIndex(20)); Assert.AreEqual(4, path.GetKeyIndex(28)); Assert.AreEqual(7, path.GetKeyIndex(40)); Assert.AreEqual(6, path.GetKeyIndex(42)); Assert.AreEqual(2, path.GetKeyIndex(78)); path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Cycle; Assert.AreEqual(-1, path.GetKeyIndex(-28)); Assert.AreEqual(-1, path.GetKeyIndex(3)); Assert.AreEqual(0, path.GetKeyIndex(10)); Assert.AreEqual(3, path.GetKeyIndex(20)); Assert.AreEqual(4, path.GetKeyIndex(28)); Assert.AreEqual(7, path.GetKeyIndex(40)); Assert.AreEqual(0, path.GetKeyIndex(42)); Assert.AreEqual(2, path.GetKeyIndex(78)); path.PreLoop = CurveLoopType.Cycle; path.PostLoop = CurveLoopType.CycleOffset; Assert.AreEqual(5, path.GetKeyIndex(-28)); Assert.AreEqual(5, path.GetKeyIndex(3)); Assert.AreEqual(0, path.GetKeyIndex(10)); Assert.AreEqual(3, path.GetKeyIndex(20)); Assert.AreEqual(4, path.GetKeyIndex(28)); Assert.AreEqual(7, path.GetKeyIndex(40)); Assert.AreEqual(0, path.GetKeyIndex(42)); Assert.AreEqual(2, path.GetKeyIndex(78)); path.PreLoop = CurveLoopType.CycleOffset; path.PostLoop = CurveLoopType.Linear; Assert.AreEqual(5, path.GetKeyIndex(-28)); Assert.AreEqual(5, path.GetKeyIndex(3)); Assert.AreEqual(0, path.GetKeyIndex(10)); Assert.AreEqual(3, path.GetKeyIndex(20)); Assert.AreEqual(4, path.GetKeyIndex(28)); Assert.AreEqual(7, path.GetKeyIndex(40)); Assert.AreEqual(7, path.GetKeyIndex(42)); Assert.AreEqual(7, path.GetKeyIndex(78)); path.PreLoop = CurveLoopType.Oscillate; path.PostLoop = CurveLoopType.Constant; Assert.AreEqual(5, path.GetKeyIndex(-28)); Assert.AreEqual(1, path.GetKeyIndex(3)); Assert.AreEqual(0, path.GetKeyIndex(10)); Assert.AreEqual(3, path.GetKeyIndex(20)); Assert.AreEqual(4, path.GetKeyIndex(28)); Assert.AreEqual(7, path.GetKeyIndex(40)); Assert.AreEqual(7, path.GetKeyIndex(42)); Assert.AreEqual(7, path.GetKeyIndex(78)); }
public void ParameterizeByLength() { Path3F empty = new Path3F(); empty.Sort(); empty.ParameterizeByLength(20, 0.001f); // No exception, do nothing. Path3F path = CreatePath(); Path3F lengthPath = CreatePath(); lengthPath.ParameterizeByLength(20, 0.001f); Assert.AreEqual(0, lengthPath[0].Parameter); Assert.AreEqual(3, lengthPath[1].Parameter); Assert.AreEqual(3, lengthPath[2].Parameter); Assert.AreEqual(3, lengthPath[3].Parameter); float step = 0.001f; float length = 3; int i = 4; float u = 20; Vector3F oldPoint = path.GetPoint(u); for (; u < 51 && i<10; u += step) { if (Numeric.AreEqual(u, path[i].Parameter)) { Assert.IsTrue(Numeric.AreEqual(length, lengthPath[i].Parameter, 0.01f)); // Set explicit values against numerical problems. length = lengthPath[i].Parameter; u = path[i].Parameter; oldPoint = path.GetPoint(u); i++; } Vector3F newPoint = path.GetPoint(u + step); length += (newPoint - oldPoint).Length; oldPoint = newPoint; } Assert.AreEqual(10, i); // Have we checked all keys? path.PreLoop = CurveLoopType.Constant; path.PostLoop = CurveLoopType.Oscillate; path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Cycle; path.PreLoop = CurveLoopType.Cycle; path.PostLoop = CurveLoopType.CycleOffset; path.PreLoop = CurveLoopType.CycleOffset; path.PostLoop = CurveLoopType.Linear; path.PreLoop = CurveLoopType.Oscillate; path.PostLoop = CurveLoopType.Constant; }
public void GetTangent() { Path3F path = CreatePath(); path.PreLoop = CurveLoopType.Constant; path.PostLoop = CurveLoopType.Oscillate; Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 0), path.GetTangent(-10))); Assert.IsTrue(Vector3F.AreNumericallyEqual((new Vector3F(1, 2, 3) - new Vector3F(0, 0, 1)) / 2, path.GetTangent(10))); Assert.IsTrue(Vector3F.AreNumericallyEqual((new Vector3F(1, 2, 3) - new Vector3F(0, 0, 1)) / 2, path.GetTangent(11.5f))); Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 0), path.GetTangent(16))); Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 0), path.GetTangent(85))); CatmullRomSegment3F catmullOscillate = new CatmullRomSegment3F() { Point1 = new Vector3F(10, 12, 14), Point2 = new Vector3F(10, 14, 8), Point3 = new Vector3F(20, 14, 8), Point4 = new Vector3F(30, 14, 8), }; Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetTangent(0.3f) / 10.0f, path.GetTangent(43))); Assert.IsTrue(Vector3F.AreNumericallyEqual(-catmullOscillate.GetTangent(0.7f) / 10.0f, path.GetTangent(53))); path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Cycle; Assert.IsTrue(Vector3F.AreNumericallyEqual((new Vector3F(1, 2, 3) - new Vector3F(0, 0, 1)) / 2, path.GetTangent(0))); path.PreLoop = CurveLoopType.Cycle; path.PostLoop = CurveLoopType.CycleOffset; Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetTangent(0.4f) / 10.0f, path.GetTangent(-36))); Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetTangent(0.4f) / 10.0f, path.GetTangent(4))); Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetTangent(0.3f) / 10.0f, path.GetTangent(83))); path.PreLoop = CurveLoopType.CycleOffset; path.PostLoop = CurveLoopType.Linear; Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetTangent(1f) / 10.0f, path.GetTangent(434))); path.PreLoop = CurveLoopType.Oscillate; path.PostLoop = CurveLoopType.Constant; path = new Path3F(); path.Add(new PathKey3F() { Parameter = 25, Point = new Vector3F(6, 7, 14), Interpolation = SplineInterpolation.Bezier, TangentIn = new Vector3F(5, 6, 13), TangentOut = new Vector3F(7, 8, 15), }); path.Add(new PathKey3F() { Parameter = 35, Point = new Vector3F(10, 12, 14), Interpolation = SplineInterpolation.Hermite, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.PreLoop = CurveLoopType.Linear; path.PostLoop = CurveLoopType.Linear; float Δu = path[1].Parameter - path[0].Parameter; Assert.IsTrue(Vector3F.AreNumericallyEqual((new Vector3F(6, 7, 14) - new Vector3F(5, 6, 13)) * 3 / Δu, path.GetTangent(0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(1, 0, 0) / Δu, path.GetTangent(100))); path[1].Parameter = 25; path[0].Parameter = 35; path.Sort(); Δu = path[1].Parameter - path[0].Parameter; Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(1, 0, 0) / Δu, path.GetTangent(0))); Assert.IsTrue(Vector3F.AreNumericallyEqual((new Vector3F(7, 8, 15) - new Vector3F(6, 7, 14)) * 3 / Δu, path.GetTangent(100))); path.Add(new PathKey3F() { Parameter = 15, Point = new Vector3F(0, 0, 0), Interpolation = SplineInterpolation.BSpline, }); path.Sort(); }
public void GetTangentShouldReturnZeroIfPathIsEmpty() { Path3F empty = new Path3F(); empty.Sort(); Assert.AreEqual(Vector3F.Zero, empty.GetTangent(-0.5f)); Assert.AreEqual(Vector3F.Zero, empty.GetTangent(0)); Assert.AreEqual(Vector3F.Zero, empty.GetTangent(0.5f)); }
public void GetPointShouldReturnNanIfPathIsEmpty() { Path3F empty = new Path3F(); empty.Sort(); Vector3F p = empty.GetPoint(-0.5f); Assert.IsNaN(p.X); Assert.IsNaN(p.Y); Assert.IsNaN(p.Z); p = empty.GetPoint(0); Assert.IsNaN(p.X); Assert.IsNaN(p.Y); Assert.IsNaN(p.Z); p = empty.GetPoint(0.5f); Assert.IsNaN(p.X); Assert.IsNaN(p.Y); Assert.IsNaN(p.Z); }
private Path3F CreatePath() { Path3F path = new Path3F(); path.Add(new PathKey3F() { Parameter = 10, Point = new Vector3F(0, 0, 1), Interpolation = SplineInterpolation.Linear, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 12, Point = new Vector3F(1, 2, 3), Interpolation = SplineInterpolation.StepLeft, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 15, Point = new Vector3F(4, 5, 7), Interpolation = SplineInterpolation.StepCentered, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 18, Point = new Vector3F(5, 7, 10), Interpolation = SplineInterpolation.StepRight, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 20, Point = new Vector3F(5, 7, 13), Interpolation = SplineInterpolation.Linear, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 31, Point = new Vector3F(8, 10, 16), Interpolation = SplineInterpolation.BSpline, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 35, Point = new Vector3F(10, 12, 14), Interpolation = SplineInterpolation.Hermite, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 25, Point = new Vector3F(6, 7, 14), Interpolation = SplineInterpolation.Bezier, TangentIn = new Vector3F(5, 6, 13), TangentOut = new Vector3F(7, 8, 15), }); path.Add(new PathKey3F() { Parameter = 40, Point = new Vector3F(10, 14, 8), Interpolation = SplineInterpolation.CatmullRom, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Add(new PathKey3F() { Parameter = 50, Point = new Vector3F(20, 14, 8), Interpolation = SplineInterpolation.CatmullRom, TangentIn = new Vector3F(1, 0, 0), TangentOut = new Vector3F(1, 0, 0), }); path.Sort(); return path; }