isTriangleCCW() private méthode

private isTriangleCCW ( Vector2 a, Vector2 center, Vector2 c ) : bool
a Microsoft.Xna.Framework.Vector2
center Microsoft.Xna.Framework.Vector2
c Microsoft.Xna.Framework.Vector2
Résultat bool
        /// <summary>
        /// Computes a triangle list that fully covers the area enclosed by the given set of points. If points are not CCW, pass false for
        /// the arePointsCCW parameter
        /// </summary>
        /// <param name="points">A list of points that defines an enclosing path.</param>
        /// <param name="count">The number of points in the path.</param>
        public void triangulate(Vector2[] points, bool arePointsCCW = true)
        {
            var count = points.Length;

            // set up previous and next links to effectively from a double-linked vert list
            initialize(count);

            // loop breaker for polys that are not triangulatable
            var iterations = 0;

            // start at vert 0
            var index = 0;

            // keep removing verts until just a triangle is left
            while (count > 3 && iterations < 500)
            {
                iterations++;
                // test if current vert is an ear
                var isEar = true;

                var a = points[_triPrev[index]];
                var b = points[index];
                var c = points[_triNext[index]];

                // an ear must be convex (here counterclockwise)
                if (Vector2Ext.isTriangleCCW(a, b, c))
                {
                    // loop over all verts not part of the tentative ear
                    var k = _triNext[_triNext[index]];
                    do
                    {
                        // if vert k is inside the ear triangle, then this is not an ear
                        if (testPointTriangle(points[k], a, b, c))
                        {
                            isEar = false;
                            break;
                        }
                        k = _triNext[k];
                    }                   while(k != _triPrev[index]);
                }
                else
                {
                    // the ear triangle is clockwise so points[i] is not an ear
                    isEar = false;
                }

                // if current vert is an ear, delete it and visit the previous vert
                if (isEar)
                {
                    // triangle is an ear
                    triangleIndices.Add(_triPrev[index]);
                    triangleIndices.Add(index);
                    triangleIndices.Add(_triNext[index]);

                    // delete vert by redirecting next and previous links of neighboring verts past it
                    // decrement vertext count
                    _triNext[_triPrev[index]] = _triNext[index];
                    _triPrev[_triNext[index]] = _triPrev[index];
                    count--;

                    // visit the previous vert next
                    index = _triPrev[index];
                }
                else
                {
                    // current vert is not an ear. visit the next vert
                    index = _triNext[index];
                }
            }

            // output the final triangle
            triangleIndices.Add(_triPrev[index]);
            triangleIndices.Add(index);
            triangleIndices.Add(_triNext[index]);

            if (!arePointsCCW)
            {
                triangleIndices.Reverse();
            }
        }
        void calculateVertices()
        {
            if (!_areVertsDirty || _points.length < 2)
            {
                return;
            }

            _areVertsDirty = false;
            _indices.reset();
            _vertices.reset();

            var maxX = float.MinValue;
            var minX = float.MaxValue;
            var maxY = float.MinValue;
            var minY = float.MaxValue;

            if (_useStartEndWidths)
            {
                _maxWidth = System.Math.Max(_startWidth, _endWidth);
            }

            // calculate line length first and simulataneously get our min/max points for the bounds
            var lineLength   = 0f;
            var halfMaxWidth = _maxWidth * 0.5f;

            _points.buffer[0].lengthFromPreviousPoint = 0;
            for (var i = 0; i < _points.length - 1; i++)
            {
                var distance = Vector2.Distance(_points.buffer[i].position, _points.buffer[i + 1].position);
                _points.buffer[i + 1].lengthFromPreviousPoint = distance;
                lineLength += distance;

                maxX = Mathf.maxOf(maxX, _points.buffer[i].position.X + halfMaxWidth, _points.buffer[i + 1].position.X + halfMaxWidth);
                minX = Mathf.minOf(minX, _points.buffer[i].position.X - halfMaxWidth, _points.buffer[i + 1].position.X - halfMaxWidth);
                maxY = Mathf.maxOf(maxY, _points.buffer[i].position.Y + halfMaxWidth, _points.buffer[i + 1].position.Y + halfMaxWidth);
                minY = Mathf.minOf(minY, _points.buffer[i].position.Y - halfMaxWidth, _points.buffer[i + 1].position.Y - halfMaxWidth);
            }

            _bounds.x      = minX;
            _bounds.y      = minY;
            _bounds.width  = maxX - minX;
            _bounds.height = maxY - minY;

            // special case: single segment
            if (_points.length == 2)
            {
                if (_useStartEndWidths)
                {
                    _points.buffer[0].width = _startWidth;
                    _points.buffer[1].width = _endWidth;
                }

                if (_useStartEndColors)
                {
                    _points.buffer[0].color = _startColor;
                    _points.buffer[1].color = _endColor;
                }

                _firstSegment.setPoints(ref _points.buffer[0], ref _points.buffer[1]);
                addSingleSegmentLine(ref _firstSegment, _points.buffer[1].color);
                return;
            }

            var distanceSoFar = 0f;
            var fusedPoint    = Vector2.Zero;
            var vertIndex     = 0;
            var thirdPoint    = new SegmentPoint();

            for (var i = 0; i < _points.length - 1; i++)
            {
                var firstPoint  = _points.buffer[i];
                var secondPoint = _points.buffer[i + 1];

                var hasThirdPoint = _points.length > i + 2;
                if (hasThirdPoint)
                {
                    thirdPoint = _points.buffer[i + 2];
                }

                // we need the distance along the line of both the first and second points. distanceSoFar will always be for the furthest point
                // which is the previous point before adding the current segment distance.
                var firstPointDistance = distanceSoFar;
                distanceSoFar += secondPoint.lengthFromPreviousPoint;

                var firstPointRatio  = firstPointDistance / lineLength;
                var secondPointRatio = distanceSoFar / lineLength;
                var thirdPointRatio  = 0f;
                if (hasThirdPoint)
                {
                    thirdPointRatio = (distanceSoFar + thirdPoint.lengthFromPreviousPoint) / lineLength;
                }

                if (_useStartEndColors)
                {
                    ColorExt.lerp(ref _startColor, ref _endColor, out firstPoint.color, firstPointRatio);
                    ColorExt.lerp(ref _startColor, ref _endColor, out secondPoint.color, secondPointRatio);

                    if (hasThirdPoint)
                    {
                        ColorExt.lerp(ref _startColor, ref _endColor, out thirdPoint.color, thirdPointRatio);
                    }
                }

                if (_useStartEndWidths)
                {
                    firstPoint.width  = Mathf.lerp(_startWidth, _endWidth, firstPointRatio);
                    secondPoint.width = Mathf.lerp(_startWidth, _endWidth, secondPointRatio);

                    if (hasThirdPoint)
                    {
                        thirdPoint.width = Mathf.lerp(_startWidth, _endWidth, thirdPointRatio);
                    }
                }


                if (i == 0)
                {
                    _firstSegment.setPoints(ref firstPoint, ref secondPoint);
                    _secondSegment.setPoints(ref secondPoint, ref thirdPoint);
                }
                else
                {
                    Utils.swap(ref _firstSegment, ref _secondSegment);
                    if (hasThirdPoint)
                    {
                        _secondSegment.setPoints(ref secondPoint, ref thirdPoint);
                    }
                }

                // dont recalculate the fusedPoint for the last segment since there will be no third point to work with
                if (hasThirdPoint)
                {
                    var shouldFuseBottom = Vector2Ext.isTriangleCCW(firstPoint.position, secondPoint.position, thirdPoint.position);
                    _secondSegment.setFusedData(shouldFuseBottom, ref _firstSegment);
                }

                // special care needs to be take with the first segment since it has a different vert count
                if (i == 0)
                {
                    addFirstSegment(ref _firstSegment, ref _secondSegment, ref vertIndex);
                }
                else
                {
                    addSegment(ref _firstSegment, ref vertIndex);
                }

                _lastSegment.cloneFrom(ref _firstSegment);
            }
        }