Esempio n. 1
0
        public void TwoKeyCurvesTest()
        {
            Path2F curve = new Path2F();
              curve.Add(new PathKey2F()
                  {
                    Parameter = 1,
                    Point = new Vector2F(1, 2),
                    Interpolation = SplineInterpolation.CatmullRom,
                  });
              curve.Add(new PathKey2F()
                  {
                    Parameter = 3,
                    Point = new Vector2F(3, 4),
                    Interpolation = SplineInterpolation.CatmullRom,
                  });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(2, 3), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(3, 4), curve.GetPoint(3));
              Assert.AreEqual(new Vector2F(3, 4), curve.GetPoint(4));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(1, 1), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(1, 1), curve.GetTangent(2));
              Assert.AreEqual(new Vector2F(1, 1), curve.GetTangent(3));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(4));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(2, 2).Length, curve.GetLength(0, 4, 10, 0.01f), 0.01f));

              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
        }
Esempio n. 2
0
 public void GetTangentShouldReturnZeroIfPathIsEmpty()
 {
     Path2F empty = new Path2F();
       empty.Sort();
       Assert.AreEqual(Vector2F.Zero, empty.GetTangent(-0.5f));
       Assert.AreEqual(Vector2F.Zero, empty.GetTangent(0));
       Assert.AreEqual(Vector2F.Zero, empty.GetTangent(0.5f));
 }
Esempio n. 3
0
        public void OneKeyCurvesTest()
        {
            // Test linear curves with 1 point
              Path2F curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.Linear,
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));

              // Test step curves with 1 point
              curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.StepLeft,
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));

              // Test B-spline curves with 1 point
              curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.BSpline,
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));

              // Test Catmull-Rom curves with 1 point
              curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.CatmullRom,
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));

              // Test Hermite curves with 1 point
              curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.Hermite,
            TangentIn = new Vector2F(2, -2),
            TangentOut = new Vector2F(2, 2),
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 20, 0.01f));
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(3, 4), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(2, 2), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(2, 2), curve.GetTangent(2));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(2, 2).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(-1, 4), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(2, -2), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(2, -2), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(2, 2).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(-1, 4), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(3, 4), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(2, -2), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(2, 2), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(2, 2), curve.GetTangent(2));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(4, 4).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));

              // Test Bezier curves with 1 point
              curve = new Path2F();
              curve.Add(new PathKey2F()
              {
            Parameter = 1,
            Point = new Vector2F(1, 2),
            Interpolation = SplineInterpolation.Bezier,
            TangentIn = new Vector2F(1, 2) - new Vector2F(2, -2) / 3,
            TangentOut = new Vector2F(1, 2) + new Vector2F(2, 2) / 3,
              });
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Constant;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(3, 4), curve.GetPoint(2)));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, 2), curve.GetTangent(1)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, 2), curve.GetTangent(2)));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(2, 2).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Constant;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(-1, 4), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, -2), curve.GetTangent(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, -2), curve.GetTangent(1)));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(2, 2).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Linear;
              curve.PostLoop = CurveLoopType.Linear;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(-1, 4), curve.GetPoint(0));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(3, 4), curve.GetPoint(2)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, -2), curve.GetTangent(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, 2), curve.GetTangent(1)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(2, 2), curve.GetTangent(2)));
              Assert.IsTrue(Numeric.AreEqual(new Vector2F(4, 4).Length, curve.GetLength(0, 2, 10, 0.01f), 0.1f));
              curve.PreLoop = CurveLoopType.Cycle;
              curve.PostLoop = CurveLoopType.Cycle;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.CycleOffset;
              curve.PostLoop = CurveLoopType.CycleOffset;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
              curve.PreLoop = CurveLoopType.Oscillate;
              curve.PostLoop = CurveLoopType.Oscillate;
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(1));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(0));
              Assert.AreEqual(new Vector2F(1, 2), curve.GetPoint(2));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(0));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(1));
              Assert.AreEqual(new Vector2F(0, 0), curve.GetTangent(2));
              Assert.AreEqual(0, curve.GetLength(0, 2, 10, 0.01f));
        }
Esempio n. 4
0
        public void GetTangent()
        {
            Path2F path = CreatePath();
              path.PreLoop = CurveLoopType.Constant;
              path.PostLoop = CurveLoopType.Oscillate;
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(0, 0), path.GetTangent(-10)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual((new Vector2F(1, 2) - new Vector2F(0, 1)) / 2, path.GetTangent(10)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual((new Vector2F(1, 2) - new Vector2F(0, 1)) / 2, path.GetTangent(11.5f)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(0, 0), path.GetTangent(16)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(0, 0), path.GetTangent(85)));

              CatmullRomSegment2F catmullOscillate = new CatmullRomSegment2F()
              {
            Point1 = new Vector2F(10, 12),
            Point2 = new Vector2F(10, 14),
            Point3 = new Vector2F(20, 14),
            Point4 = new Vector2F(30, 14),
              };
              Assert.IsTrue(Vector2F.AreNumericallyEqual(catmullOscillate.GetTangent(0.3f) / 10.0f, path.GetTangent(43)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(-catmullOscillate.GetTangent(0.7f) / 10.0f, path.GetTangent(53)));

              path.PreLoop = CurveLoopType.Linear;
              path.PostLoop = CurveLoopType.Cycle;
              Assert.IsTrue(Vector2F.AreNumericallyEqual((new Vector2F(1, 2) - new Vector2F(0, 1)) / 2, path.GetTangent(0)));

              path.PreLoop = CurveLoopType.Cycle;
              path.PostLoop = CurveLoopType.CycleOffset;
              Assert.IsTrue(Vector2F.AreNumericallyEqual(catmullOscillate.GetTangent(0.4f) / 10.0f, path.GetTangent(-36)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(catmullOscillate.GetTangent(0.4f) / 10.0f, path.GetTangent(4)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(catmullOscillate.GetTangent(0.3f) / 10.0f, path.GetTangent(83)));

              path.PreLoop = CurveLoopType.CycleOffset;
              path.PostLoop = CurveLoopType.Linear;
              Assert.IsTrue(Vector2F.AreNumericallyEqual(catmullOscillate.GetTangent(1f) / 10.0f, path.GetTangent(434)));

              path.PreLoop = CurveLoopType.Oscillate;
              path.PostLoop = CurveLoopType.Constant;

              path = new Path2F();
              path.Add(new PathKey2F()
              {
            Parameter = 25,
            Point = new Vector2F(6, 7),
            Interpolation = SplineInterpolation.Bezier,
            TangentIn = new Vector2F(5, 6),
            TangentOut = new Vector2F(7, 8),
              });
              path.Add(new PathKey2F()
              {
            Parameter = 35,
            Point = new Vector2F(10, 12),
            Interpolation = SplineInterpolation.Hermite,
            TangentIn = new Vector2F(1, 0),
            TangentOut = new Vector2F(1, 0),
              });
              path.PreLoop = CurveLoopType.Linear;
              path.PostLoop = CurveLoopType.Linear;
              float Δu = path[1].Parameter - path[0].Parameter;
              Assert.IsTrue(Vector2F.AreNumericallyEqual((new Vector2F(6, 7) - new Vector2F(5, 6)) * 3 / Δu, path.GetTangent(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(1, 0) / Δu, path.GetTangent(100)));

              path[1].Parameter = 25;
              path[0].Parameter = 35;
              path.Sort();
              Δu = path[1].Parameter - path[0].Parameter;
              Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F(1, 0) / Δu, path.GetTangent(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual((new Vector2F(7, 8) - new Vector2F(6, 7)) * 3 / Δu, path.GetTangent(100)));

              path.Add(new PathKey2F()
              {
            Parameter = 15,
            Point = new Vector2F(0, 0),
            Interpolation = SplineInterpolation.BSpline,
              });
              path.Sort();
        }