public static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)
 {
     double x1 = src.getX1();
     double y1 = src.getY1();
     double cx1 = src.getCtrlX1();
     double cy1 = src.getCtrlY1();
     double cx2 = src.getCtrlX2();
     double cy2 = src.getCtrlY2();
     double x2 = src.getX2();
     double y2 = src.getY2();
     double cx = (cx1 + cx2) / 2.0;
     double cy = (cy1 + cy2) / 2.0;
     cx1 = (x1 + cx1) / 2.0;
     cy1 = (y1 + cy1) / 2.0;
     cx2 = (x2 + cx2) / 2.0;
     cy2 = (y2 + cy2) / 2.0;
     double ax = (cx1 + cx) / 2.0;
     double ay = (cy1 + cy) / 2.0;
     double bx = (cx2 + cx) / 2.0;
     double by = (cy2 + cy) / 2.0;
     cx = (ax + bx) / 2.0;
     cy = (ay + by) / 2.0;
     if (left != null) {
     left.setCurve(x1, y1, cx1, cy1, ax, ay, cx, cy);
     }
     if (right != null) {
     right.setCurve(cx, cy, bx, by, cx2, cy2, x2, y2);
     }
 }
Пример #2
0
        public static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)
        {
            double x1  = src.getX1();
            double y1  = src.getY1();
            double cx1 = src.getCtrlX1();
            double cy1 = src.getCtrlY1();
            double cx2 = src.getCtrlX2();
            double cy2 = src.getCtrlY2();
            double x2  = src.getX2();
            double y2  = src.getY2();
            double cx  = (cx1 + cx2) / 2.0;
            double cy  = (cy1 + cy2) / 2.0;

            cx1 = (x1 + cx1) / 2.0;
            cy1 = (y1 + cy1) / 2.0;
            cx2 = (x2 + cx2) / 2.0;
            cy2 = (y2 + cy2) / 2.0;
            double ax = (cx1 + cx) / 2.0;
            double ay = (cy1 + cy) / 2.0;
            double bx = (cx2 + cx) / 2.0;
            double by = (cy2 + cy) / 2.0;

            cx = (ax + bx) / 2.0;
            cy = (ay + by) / 2.0;
            if (left != null)
            {
                left.setCurve(x1, y1, cx1, cy1, ax, ay, cx, cy);
            }
            if (right != null)
            {
                right.setCurve(cx, cy, bx, by, cx2, cy2, x2, y2);
            }
        }
Пример #3
0
 public void setCurve(CubicCurve2D curve)
 {
     setCurve(
         curve.getX1(), curve.getY1(),
         curve.getCtrlX1(), curve.getCtrlY1(),
         curve.getCtrlX2(), curve.getCtrlY2(),
         curve.getX2(), curve.getY2());
 }
Пример #4
0
 public void subdivide(CubicCurve2D left, CubicCurve2D right)
 {
     subdivide(this, left, right);
 }
Пример #5
0
 /**
  * Constructs a new CubicCurve2D.Iterator for given line and transformation
  * @param c - the source CubicCurve2D object
  * @param at - the AffineTransform object to apply rectangle path
  */
 internal Iterator(CubicCurve2D c, AffineTransform t)
 {
     this.c = c;
     this.t = t;
 }
Пример #6
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;
            }
        }
 /**
  * Constructs a new CubicCurve2D.Iterator for given line and transformation
  * @param c - the source CubicCurve2D object
  * @param at - the AffineTransform object to apply rectangle path
  */
 internal Iterator(CubicCurve2D c, AffineTransform t)
 {
     this.c = c;
     this.t = t;
 }
 public void subdivide(CubicCurve2D left, CubicCurve2D right)
 {
     subdivide(this, left, right);
 }
 public void setCurve(CubicCurve2D curve)
 {
     setCurve(
         curve.getX1(), curve.getY1(),
         curve.getCtrlX1(), curve.getCtrlY1(),
         curve.getCtrlX2(), curve.getCtrlY2(),
         curve.getX2(), curve.getY2());
 }