public void GetLength()
        {
            BezierSegment2F b = new BezierSegment2F
              {
            Point1 = new Vector2F(1, 2),
            ControlPoint1 = new Vector2F(4, 5),
            ControlPoint2 = new Vector2F(7, 8),
            Point2 = new Vector2F(10, 2),
              };

              float lowerBound = (b.Point2 - b.Point1).Length;
              float upperBound = (b.Point2 - b.ControlPoint2).Length
                         + (b.ControlPoint2 - b.ControlPoint1).Length
                         + (b.ControlPoint1 - b.Point1).Length;
              Assert.Less(lowerBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));
              Assert.Greater(upperBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));

              float length1 = b.GetLength(0, 1, 20, Numeric.EpsilonF);
              float length2 = b.GetLengthWithDeCasteljau(20, Numeric.EpsilonF);

              Assert.IsTrue(Numeric.AreEqual(length1, length2));
              // Compare numerical integration method and de Casteljau method.

              float approxLength = 0;
              const float step = 0.0001f;
              for (float u = 0; u <= 1.0f; u += step)
            approxLength += (b.GetPoint(u) - b.GetPoint(u + step)).Length;

              Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
              Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + b.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
              Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
        public void GetLength()
        {
            HermiteSegment2F s = new HermiteSegment2F
            {
                Point1   = new Vector2F(1, 2),
                Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
                Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
                Point2   = new Vector2F(10, 2),
            };

            BezierSegment2F b = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(10, 3),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };

            float length1 = s.GetLength(0, 1, 20, Numeric.EpsilonF);
            float length2 = b.GetLength(0, 1, 20, Numeric.EpsilonF);

            Assert.IsTrue(Numeric.AreEqual(length1, length2));

            float       approxLength = 0;
            const float step         = 0.0001f;

            for (float u = 0; u <= 1.0f; u += step)
            {
                approxLength += (s.GetPoint(u) - s.GetPoint(u + step)).Length;
            }

            Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
            Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + s.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
            Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
        public void GetLength()
        {
            HermiteSegment2F s = new HermiteSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
            Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
            Point2 = new Vector2F(10, 2),
              };

              BezierSegment2F b = new BezierSegment2F
              {
            Point1 = new Vector2F(1, 2),
            ControlPoint1 = new Vector2F(10, 3),
            ControlPoint2 = new Vector2F(7, 8),
            Point2 = new Vector2F(10, 2),
              };

              float length1 = s.GetLength(0, 1, 20, Numeric.EpsilonF);
              float length2 = b.GetLength(0, 1, 20, Numeric.EpsilonF);
              Assert.IsTrue(Numeric.AreEqual(length1, length2));

              float approxLength = 0;
              const float step = 0.0001f;
              for (float u = 0; u <= 1.0f; u += step)
            approxLength += (s.GetPoint(u) - s.GetPoint(u + step)).Length;

              Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
              Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + s.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
              Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
 public void Flatten()
 {
     var s = new BezierSegment2F
       {
     Point1 = new Vector2F(1, 2),
     ControlPoint1 = new Vector2F(4, 5),
     ControlPoint2 = new Vector2F(7, 8),
     Point2 = new Vector2F(10, 2),
       };
       var points = new List<Vector2F>();
       var tolerance = 0.01f;
       s.Flatten(points, 10, tolerance);
       Assert.IsTrue(points.Contains(s.Point1));
       Assert.IsTrue(points.Contains(s.Point2));
       var curveLength = s.GetLength(0, 1, 10, tolerance);
       Assert.IsTrue(CurveHelper.GetLength(points) >= curveLength - tolerance * points.Count / 2);
       Assert.IsTrue(CurveHelper.GetLength(points) <= curveLength);
 }
Example #5
0
        public void Flatten()
        {
            var s = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(4, 5),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };
            var points    = new List <Vector2F>();
            var tolerance = 0.01f;

            s.Flatten(points, 10, tolerance);
            Assert.IsTrue(points.Contains(s.Point1));
            Assert.IsTrue(points.Contains(s.Point2));
            var curveLength = s.GetLength(0, 1, 10, tolerance);

            Assert.IsTrue(CurveHelper.GetLength(points) >= curveLength - tolerance * points.Count / 2);
            Assert.IsTrue(CurveHelper.GetLength(points) <= curveLength);
        }
Example #6
0
        public void GetLength()
        {
            BezierSegment2F b = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(4, 5),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };

            float lowerBound = (b.Point2 - b.Point1).Length;
            float upperBound = (b.Point2 - b.ControlPoint2).Length
                               + (b.ControlPoint2 - b.ControlPoint1).Length
                               + (b.ControlPoint1 - b.Point1).Length;

            Assert.Less(lowerBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));
            Assert.Greater(upperBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));

            float length1 = b.GetLength(0, 1, 20, Numeric.EpsilonF);
            float length2 = b.GetLengthWithDeCasteljau(20, Numeric.EpsilonF);

            Assert.IsTrue(Numeric.AreEqual(length1, length2));
            // Compare numerical integration method and de Casteljau method.

            float       approxLength = 0;
            const float step         = 0.0001f;

            for (float u = 0; u <= 1.0f; u += step)
            {
                approxLength += (b.GetPoint(u) - b.GetPoint(u + step)).Length;
            }

            Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
            Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + b.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
            Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }