Пример #1
0
        private void CompileClosedPath(IList <CCVector2> points, IList <float> accumLengths, int offset, int count, Pen outlinePen)
        {
            if (_strokeType != StrokeType.Outline)
            {
                InitializeBuffers(count + 1);
            }

            if (IsClose(points[offset], points[offset + count - 1]))
            {
                count--;
            }

            IList <float> lengths = accumLengths ?? _zeroList;

            Buffer <CCVector2> insetBuffer  = null;
            Buffer <CCVector2> outsetBuffer = null;

            if (outlinePen != null && _strokeType != StrokeType.Fill)
            {
                insetBuffer = Pools <Buffer <CCVector2> > .Obtain();

                outsetBuffer = Pools <Buffer <CCVector2> > .Obtain();

                int vCount = _positionData != null ? _positionData.Length : _pen.MaximumVertexCount(count);

                insetBuffer.EnsureCapacity(vCount);
                outsetBuffer.EnsureCapacity(vCount);
            }

            PenWorkspace ws = Pools <PenWorkspace> .Obtain();

            ws.ResetWorkspace(_pen);

            JoinSample joinSample = new JoinSample(points[offset + count - 1], points[offset + 0], points[offset + 1], 0, lengths[offset + 0], lengths[offset + 1]);

            int vBaseIndex = _vertexBufferIndex;
            int vBaseCount = AddJoint(0, ref joinSample, ws, insetBuffer, outsetBuffer);

            int vPrevCount = 0;
            int vNextCount = vBaseCount;

            for (int i = 0; i < count - 2; i++)
            {
                joinSample.Advance(points[offset + i + 2], lengths[offset + i + 2]);

                vPrevCount = vNextCount;
                vNextCount = AddJoint(i + 1, ref joinSample, ws, insetBuffer, outsetBuffer);
                if (_strokeType != StrokeType.Outline)
                {
                    AddSegment(_vertexBufferIndex - vNextCount - vPrevCount, vPrevCount, _jointCCW[i], _vertexBufferIndex - vNextCount, vNextCount, _jointCCW[i + 1]);
                }
            }

            joinSample.Advance(points[offset + 0], lengths[offset + 0]);

            vPrevCount = vNextCount;
            vNextCount = AddJoint(count - 1, ref joinSample, ws, insetBuffer, outsetBuffer);

            if (_strokeType != StrokeType.Outline)
            {
                AddSegment(_vertexBufferIndex - vNextCount - vPrevCount, vPrevCount, _jointCCW[count - 2], _vertexBufferIndex - vNextCount, vNextCount, _jointCCW[count - 1]);
                AddSegment(_vertexBufferIndex - vNextCount, vNextCount, _jointCCW[count - 1], vBaseIndex, vBaseCount, _jointCCW[0]);
            }

            Pools <PenWorkspace> .Release(ws);

            if (outlinePen != null && _strokeType != StrokeType.Fill)
            {
                Array.Reverse(insetBuffer.Data, 0, insetBuffer.Index);

                _outlinePaths = new GraphicsPath[] {
                    new GraphicsPath(outlinePen, insetBuffer.Data, PathType.Closed, 0, insetBuffer.Index),
                    new GraphicsPath(outlinePen, outsetBuffer.Data, PathType.Closed, 0, outsetBuffer.Index),
                };

                Pools <Buffer <CCVector2> > .Release(insetBuffer);

                Pools <Buffer <CCVector2> > .Release(outsetBuffer);
            }
        }
Пример #2
0
        private void CompileOpenPath(IList <CCVector2> points, IList <float> accumLengths, int offset, int count, Pen outlinePen)
        {
            if (_strokeType != StrokeType.Outline)
            {
                InitializeBuffers(count);
            }

            IList <float> lengths = accumLengths ?? _zeroList;

            Buffer <CCVector2> insetBuffer  = null;
            Buffer <CCVector2> outsetBuffer = null;

            if (outlinePen != null && _strokeType != StrokeType.Fill)
            {
                insetBuffer = Pools <Buffer <CCVector2> > .Obtain();

                outsetBuffer = Pools <Buffer <CCVector2> > .Obtain();

                int vCount = _positionData != null ? _positionData.Length : _pen.MaximumVertexCount(count);

                insetBuffer.EnsureCapacity(vCount);
                outsetBuffer.EnsureCapacity(vCount);
            }

            PenWorkspace ws = Pools <PenWorkspace> .Obtain();

            ws.ResetWorkspace(_pen);
            ws.PathLength = lengths[offset + count - 1];

            int vPrevCount = 0;
            int vNextCount = AddStartPoint(0, points[offset + 0], points[offset + 1], ws, insetBuffer);

            if (insetBuffer != null)
            {
                Array.Reverse(insetBuffer.Data, 0, insetBuffer.Index);
            }

            JoinSample joinSample = new JoinSample(CCVector2.Zero, points[offset + 0], points[offset + 1], 0, lengths[offset + 0], lengths[offset + 1]);

            for (int i = 0; i < count - 2; i++)
            {
                joinSample.Advance(points[offset + i + 2], lengths[offset + i + 2]);

                vPrevCount = vNextCount;
                vNextCount = AddJoint(i + 1, ref joinSample, ws, insetBuffer, outsetBuffer);
                if (_strokeType != StrokeType.Outline)
                {
                    AddSegment(_vertexBufferIndex - vNextCount - vPrevCount, vPrevCount, _jointCCW[i], _vertexBufferIndex - vNextCount, vNextCount, _jointCCW[i + 1]);
                }
            }

            /*for (int i = 0; i < count - 2; i++) {
             *  int i0 = offset + i;
             *  int i1 = i0 + 1;
             *  int i2 = i0 + 2;
             *
             *  vPrevCount = vNextCount;
             *  vNextCount = AddJoint(i + 1, points[i0], points[i1], points[i2], lengths[i0], lengths[i1], lengths[i2], ws, insetBuffer, outsetBuffer);
             *  if (_strokeType != StrokeType.Outline)
             *      AddSegment(_vertexBufferIndex - vNextCount - vPrevCount, vPrevCount, _jointCCW[i], _vertexBufferIndex - vNextCount, vNextCount, _jointCCW[i + 1]);
             * }*/

            vPrevCount = vNextCount;
            vNextCount = AddEndPoint(count - 1, points[offset + count - 2], points[offset + count - 1], ws, insetBuffer);
            if (_strokeType != StrokeType.Outline)
            {
                AddSegment(_vertexBufferIndex - vNextCount - vPrevCount, vPrevCount, _jointCCW[count - 2], _vertexBufferIndex - vNextCount, vNextCount, _jointCCW[count - 1]);
            }

            if (insetBuffer != null)
            {
                Array.Reverse(insetBuffer.Data, 0, insetBuffer.Index);
            }

            Pools <PenWorkspace> .Release(ws);

            if (outlinePen != null && _strokeType != StrokeType.Fill)
            {
                Buffer <CCVector2> mergedBuffer = Pools <Buffer <CCVector2> > .Obtain();

                mergedBuffer.EnsureCapacity(insetBuffer.Index + outsetBuffer.Index);

                Array.Copy(insetBuffer.Data, 0, mergedBuffer.Data, 0, insetBuffer.Index);
                Array.Copy(outsetBuffer.Data, 0, mergedBuffer.Data, insetBuffer.Index, outsetBuffer.Index);

                _outlinePaths = new GraphicsPath[] {
                    new GraphicsPath(outlinePen, mergedBuffer.Data, PathType.Closed, 0, insetBuffer.Index + outsetBuffer.Index),
                };

                Pools <Buffer <CCVector2> > .Release(mergedBuffer);

                Pools <Buffer <CCVector2> > .Release(insetBuffer);

                Pools <Buffer <CCVector2> > .Release(outsetBuffer);
            }
        }