コード例 #1
0
        /*
         * Calculates flat path points for current segment of the source shape.
         *
         * Line segment is flat by itself. Flatness of quad and cubic curves evaluated by getFlatnessSq() method.
         * Curves subdivided until current flatness is bigger than user defined and subdivision limit isn't exhausted.
         * Single source segment translated to series of buffer points. The less flatness the bigger serries.
         * Every currentSegment() call extract one point from the buffer. When series completed evaluate() takes next source shape segment.
         */
        void evaluate()
        {
            if (bufEmpty)
            {
                bufType = p.currentSegment(coords);
            }

            switch (bufType)
            {
            case PathIteratorConstants.SEG_MOVETO:
            case PathIteratorConstants.SEG_LINETO:
                px = coords[0];
                py = coords[1];
                break;

            case PathIteratorConstants.SEG_QUADTO:
                if (bufEmpty)
                {
                    bufIndex         -= 6;
                    buf[bufIndex + 0] = px;
                    buf[bufIndex + 1] = py;
                    java.lang.SystemJ.arraycopy(coords, 0, buf, bufIndex + 2, 4);
                    bufSubdiv = 0;
                }

                while (bufSubdiv < bufLimit)
                {
                    if (QuadCurve2D.getFlatnessSq(buf, bufIndex) < flatness2)
                    {
                        break;
                    }

                    // Realloc buffer
                    if (bufIndex <= 4)
                    {
                        double[] tmp = new double[bufSize + BUFFER_CAPACITY];
                        java.lang.SystemJ.arraycopy(
                            buf, bufIndex,
                            tmp, bufIndex + BUFFER_CAPACITY,
                            bufSize - bufIndex);
                        buf       = tmp;
                        bufSize  += BUFFER_CAPACITY;
                        bufIndex += BUFFER_CAPACITY;
                    }

                    QuadCurve2D.subdivide(buf, bufIndex, buf, bufIndex - 4, buf, bufIndex);

                    bufIndex -= 4;
                    bufSubdiv++;
                }

                bufIndex += 4;
                px        = buf[bufIndex];
                py        = buf[bufIndex + 1];

                bufEmpty = (bufIndex == bufSize - 2);
                if (bufEmpty)
                {
                    bufIndex = bufSize;
                    bufType  = PathIteratorConstants.SEG_LINETO;
                }
                break;

            case PathIteratorConstants.SEG_CUBICTO:
                if (bufEmpty)
                {
                    bufIndex         -= 8;
                    buf[bufIndex + 0] = px;
                    buf[bufIndex + 1] = py;
                    java.lang.SystemJ.arraycopy(coords, 0, buf, bufIndex + 2, 6);
                    bufSubdiv = 0;
                }

                while (bufSubdiv < bufLimit)
                {
                    if (CubicCurve2D.getFlatnessSq(buf, bufIndex) < flatness2)
                    {
                        break;
                    }

                    // Realloc buffer
                    if (bufIndex <= 6)
                    {
                        double [] tmp = new double[bufSize + BUFFER_CAPACITY];
                        java.lang.SystemJ.arraycopy(
                            buf, bufIndex,
                            tmp, bufIndex + BUFFER_CAPACITY,
                            bufSize - bufIndex);
                        buf       = tmp;
                        bufSize  += BUFFER_CAPACITY;
                        bufIndex += BUFFER_CAPACITY;
                    }

                    CubicCurve2D.subdivide(buf, bufIndex, buf, bufIndex - 6, buf, bufIndex);

                    bufIndex -= 6;
                    bufSubdiv++;
                }

                bufIndex += 6;
                px        = buf[bufIndex];
                py        = buf[bufIndex + 1];

                bufEmpty = (bufIndex == bufSize - 2);
                if (bufEmpty)
                {
                    bufIndex = bufSize;
                    bufType  = PathIteratorConstants.SEG_LINETO;
                }
                break;
            }
        }