public void GetParameter() { BezierSegment1F b = new BezierSegment1F() { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; Assert.IsTrue(Numeric.AreEqual(0, CurveHelper.GetParameter(b, 1, 100))); Assert.IsTrue(Numeric.AreEqual(1, CurveHelper.GetParameter(b, 8, 100))); Assert.IsTrue(Numeric.AreEqual(0.3f, CurveHelper.GetParameter(b, b.GetPoint(0.3f), 100))); Assert.IsTrue(Numeric.AreEqual(0.4f, CurveHelper.GetParameter(b, b.GetPoint(0.4f), 100))); Assert.IsTrue(Numeric.AreEqual(0.5f, CurveHelper.GetParameter(b, b.GetPoint(0.5f), 100))); Assert.IsTrue(Numeric.AreEqual(0.6f, CurveHelper.GetParameter(b, b.GetPoint(0.6f), 100))); Assert.IsTrue(Numeric.AreEqual(0.9f, CurveHelper.GetParameter(b, b.GetPoint(0.9f), 100))); Assert.IsFalse(Numeric.AreEqual(0.9f, CurveHelper.GetParameter(b, b.GetPoint(0.9f), 1))); // limited iterations. for (int i = 0; i < 1000; i++) { float u = RandomHelper.Random.NextFloat(0, 1); float point = b.GetPoint(u); Assert.IsTrue(Numeric.AreEqual(u, CurveHelper.GetParameter(b, point, 100))); } for (int i = 0; i < 1000; i++) { float u = RandomHelper.Random.NextFloat(0, 1); float point = b.GetPoint(u); Assert.IsTrue(Numeric.AreEqual(u, CurveHelper.GetParameter(b, point, 100), 0.01f)); } }
public void GetTangent() { BezierSegment1F b = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; Assert.IsTrue(Numeric.AreEqual(3 * (3 - 1), b.GetTangent(0))); Assert.IsTrue(Numeric.AreEqual(3 * (8 - 4), b.GetTangent(1))); }
public void GetPoint() { BezierSegment1F b = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; Assert.IsTrue(Numeric.AreEqual(1, b.GetPoint(0))); Assert.IsTrue(Numeric.AreEqual(8, b.GetPoint(1))); Assert.IsTrue(Numeric.AreEqual(2.638f, b.GetPoint(0.3f))); }
public void Flatten() { var s = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; var points = new List<float>(); s.Flatten(points, 1, 1); Assert.AreEqual(2, points.Count); Assert.IsTrue(points.Contains(s.Point1)); Assert.IsTrue(points.Contains(s.Point2)); }
public void Flatten() { var s = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; var points = new List <float>(); s.Flatten(points, 1, 1); Assert.AreEqual(2, points.Count); Assert.IsTrue(points.Contains(s.Point1)); Assert.IsTrue(points.Contains(s.Point2)); }
public void GetLength() { BezierSegment1F b = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; Assert.IsTrue(Numeric.AreEqual(7, b.GetLength(0, 1, 100, Numeric.EpsilonF))); BezierSegment1F bSymmetric = new BezierSegment1F { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 6, }; Assert.IsTrue(Numeric.AreEqual(2.5f, bSymmetric.GetLength(0.5f, 1, 100, Numeric.EpsilonF))); }
public void GetParameter() { BezierSegment1F b = new BezierSegment1F() { Point1 = 1, ControlPoint1 = 3, ControlPoint2 = 4, Point2 = 8, }; Assert.IsTrue(Numeric.AreEqual(0, CurveHelper.GetParameter(b, 1, 100))); Assert.IsTrue(Numeric.AreEqual(1, CurveHelper.GetParameter(b, 8, 100))); Assert.IsTrue(Numeric.AreEqual(0.3f, CurveHelper.GetParameter(b, b.GetPoint(0.3f), 100))); Assert.IsTrue(Numeric.AreEqual(0.4f, CurveHelper.GetParameter(b, b.GetPoint(0.4f), 100))); Assert.IsTrue(Numeric.AreEqual(0.5f, CurveHelper.GetParameter(b, b.GetPoint(0.5f), 100))); Assert.IsTrue(Numeric.AreEqual(0.6f, CurveHelper.GetParameter(b, b.GetPoint(0.6f), 100))); Assert.IsTrue(Numeric.AreEqual(0.9f, CurveHelper.GetParameter(b, b.GetPoint(0.9f), 100))); Assert.IsFalse(Numeric.AreEqual(0.9f, CurveHelper.GetParameter(b, b.GetPoint(0.9f), 1))); // limited iterations. for (int i=0; i<1000; i++) { float u = RandomHelper.Random.NextFloat(0, 1); float point = b.GetPoint(u); Assert.IsTrue(Numeric.AreEqual(u, CurveHelper.GetParameter(b, point, 100))); } for (int i = 0; i < 1000; i++) { float u = RandomHelper.Random.NextFloat(0, 1); float point = b.GetPoint(u); Assert.IsTrue(Numeric.AreEqual(u, CurveHelper.GetParameter(b, point, 100), 0.01f)); } }