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