Пример #1
0
        /// <inheritdoc/>
        internal override void Flatten(Collections.ArrayList <Vector3> vertices, Collections.ArrayList <int> strokeIndices, Collections.ArrayList <int> fillIndices)
        {
            _arcSegment.IsLargeArc     = true;
            _arcSegment.Point1         = new Vector2F(RadiusX, 0);
            _arcSegment.Point2         = _arcSegment.Point1;
            _arcSegment.Radius         = new Vector2F(RadiusX, RadiusY);
            _arcSegment.RotationAngle  = 0;
            _arcSegment.SweepClockwise = false;

            var tempVertices = ResourcePools <Vector2F> .Lists.Obtain();

            _arcSegment.Flatten(tempVertices, MaxNumberOfIterations, Tolerance);

            int numberOfVertices = tempVertices.Count;

            if (numberOfVertices < 2)
            {
                return;
            }

            int startIndex = vertices.Count;

            // Add 3D vertices. We skip the duplicated vertices.
            for (int i = 0; i < numberOfVertices; i += 2)
            {
                vertices.Add(new Vector3(tempVertices[i].X, tempVertices[i].Y, 0));
            }

            // Add stroke indices.
            for (int i = 0; i < numberOfVertices - 1; i++)
            {
                strokeIndices.Add(startIndex + (i + 1) / 2);
            }

            // Closing stroke:
            strokeIndices.Add(startIndex);

            if (IsFilled)
            {
                // Add a center vertex.
                var centerIndex = vertices.Count;
                vertices.Add(new Vector3(0, 0, 0));

                // Add one triangle per circle segment.
                for (int i = 0; i < numberOfVertices / 2 - 1; i++)
                {
                    fillIndices.Add(centerIndex);
                    fillIndices.Add(startIndex + i + 1);
                    fillIndices.Add(startIndex + i);
                }

                // Last triangle:
                fillIndices.Add(centerIndex);
                fillIndices.Add(startIndex);
                fillIndices.Add(centerIndex - 1);
            }

            ResourcePools <Vector2F> .Lists.Recycle(tempVertices);
        }
Пример #2
0
 public void Flatten()
 {
     var s = new ArcSegment2F
       {
     Point1 = new Vector2F(1, 2),
     Point2 = new Vector2F(10, -3),
       };
       var points = new List<Vector2F>();
       var tolerance = 1f;
       s.Flatten(points, 10, tolerance);
       Assert.IsTrue(Vector2F.AreNumericallyEqual(points[0], s.Point1));
       Assert.IsTrue(Vector2F.AreNumericallyEqual(points.Last(), 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);
 }
Пример #3
0
        public void Flatten()
        {
            var s = new ArcSegment2F
            {
                Point1 = new Vector2F(1, 2),
                Point2 = new Vector2F(10, -3),
            };
            var points    = new List <Vector2F>();
            var tolerance = 1f;

            s.Flatten(points, 10, tolerance);
            Assert.IsTrue(Vector2F.AreNumericallyEqual(points[0], s.Point1));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(points.Last(), 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);
        }