Save This Page
Home » openjdk-7 » java » awt » geom » [javadoc | source]
    1   /*
    2    * Copyright 1997 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package java.awt.geom;
   27   
   28   import java.util;
   29   
   30   /**
   31    * A utility class to iterate over the path segments of a cubic curve
   32    * segment through the PathIterator interface.
   33    *
   34    * @author      Jim Graham
   35    */
   36   class CubicIterator implements PathIterator {
   37       CubicCurve2D cubic;
   38       AffineTransform affine;
   39       int index;
   40   
   41       CubicIterator(CubicCurve2D q, AffineTransform at) {
   42           this.cubic = q;
   43           this.affine = at;
   44       }
   45   
   46       /**
   47        * Return the winding rule for determining the insideness of the
   48        * path.
   49        * @see #WIND_EVEN_ODD
   50        * @see #WIND_NON_ZERO
   51        */
   52       public int getWindingRule() {
   53           return WIND_NON_ZERO;
   54       }
   55   
   56       /**
   57        * Tests if there are more points to read.
   58        * @return true if there are more points to read
   59        */
   60       public boolean isDone() {
   61           return (index > 1);
   62       }
   63   
   64       /**
   65        * Moves the iterator to the next segment of the path forwards
   66        * along the primary direction of traversal as long as there are
   67        * more points in that direction.
   68        */
   69       public void next() {
   70           index++;
   71       }
   72   
   73       /**
   74        * Returns the coordinates and type of the current path segment in
   75        * the iteration.
   76        * The return value is the path segment type:
   77        * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
   78        * A float array of length 6 must be passed in and may be used to
   79        * store the coordinates of the point(s).
   80        * Each point is stored as a pair of float x,y coordinates.
   81        * SEG_MOVETO and SEG_LINETO types will return one point,
   82        * SEG_QUADTO will return two points,
   83        * SEG_CUBICTO will return 3 points
   84        * and SEG_CLOSE will not return any points.
   85        * @see #SEG_MOVETO
   86        * @see #SEG_LINETO
   87        * @see #SEG_QUADTO
   88        * @see #SEG_CUBICTO
   89        * @see #SEG_CLOSE
   90        */
   91       public int currentSegment(float[] coords) {
   92           if (isDone()) {
   93               throw new NoSuchElementException("cubic iterator iterator out of bounds");
   94           }
   95           int type;
   96           if (index == 0) {
   97               coords[0] = (float) cubic.getX1();
   98               coords[1] = (float) cubic.getY1();
   99               type = SEG_MOVETO;
  100           } else {
  101               coords[0] = (float) cubic.getCtrlX1();
  102               coords[1] = (float) cubic.getCtrlY1();
  103               coords[2] = (float) cubic.getCtrlX2();
  104               coords[3] = (float) cubic.getCtrlY2();
  105               coords[4] = (float) cubic.getX2();
  106               coords[5] = (float) cubic.getY2();
  107               type = SEG_CUBICTO;
  108           }
  109           if (affine != null) {
  110               affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 3);
  111           }
  112           return type;
  113       }
  114   
  115       /**
  116        * Returns the coordinates and type of the current path segment in
  117        * the iteration.
  118        * The return value is the path segment type:
  119        * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
  120        * A double array of length 6 must be passed in and may be used to
  121        * store the coordinates of the point(s).
  122        * Each point is stored as a pair of double x,y coordinates.
  123        * SEG_MOVETO and SEG_LINETO types will return one point,
  124        * SEG_QUADTO will return two points,
  125        * SEG_CUBICTO will return 3 points
  126        * and SEG_CLOSE will not return any points.
  127        * @see #SEG_MOVETO
  128        * @see #SEG_LINETO
  129        * @see #SEG_QUADTO
  130        * @see #SEG_CUBICTO
  131        * @see #SEG_CLOSE
  132        */
  133       public int currentSegment(double[] coords) {
  134           if (isDone()) {
  135               throw new NoSuchElementException("cubic iterator iterator out of bounds");
  136           }
  137           int type;
  138           if (index == 0) {
  139               coords[0] = cubic.getX1();
  140               coords[1] = cubic.getY1();
  141               type = SEG_MOVETO;
  142           } else {
  143               coords[0] = cubic.getCtrlX1();
  144               coords[1] = cubic.getCtrlY1();
  145               coords[2] = cubic.getCtrlX2();
  146               coords[3] = cubic.getCtrlY2();
  147               coords[4] = cubic.getX2();
  148               coords[5] = cubic.getY2();
  149               type = SEG_CUBICTO;
  150           }
  151           if (affine != null) {
  152               affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 3);
  153           }
  154           return type;
  155       }
  156   }

Save This Page
Home » openjdk-7 » java » awt » geom » [javadoc | source]