< prev index next >

src/java.desktop/share/classes/java/awt/geom/Path2D.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2015, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 259          */
 260         public Float(Shape s, AffineTransform at) {
 261             if (s instanceof Path2D) {
 262                 Path2D p2d = (Path2D) s;
 263                 setWindingRule(p2d.windingRule);
 264                 this.numTypes = p2d.numTypes;
 265                 // trim arrays:
 266                 this.pointTypes = Arrays.copyOf(p2d.pointTypes, p2d.numTypes);
 267                 this.numCoords = p2d.numCoords;
 268                 this.floatCoords = p2d.cloneCoordsFloat(at);
 269             } else {
 270                 PathIterator pi = s.getPathIterator(at);
 271                 setWindingRule(pi.getWindingRule());
 272                 this.pointTypes = new byte[INIT_SIZE];
 273                 this.floatCoords = new float[INIT_SIZE * 2];
 274                 append(pi, false);
 275             }
 276         }
 277 
 278         @Override











 279         float[] cloneCoordsFloat(AffineTransform at) {
 280             // trim arrays:
 281             float ret[];
 282             if (at == null) {
 283                 ret = Arrays.copyOf(floatCoords, numCoords);
 284             } else {
 285                 ret = new float[numCoords];
 286                 at.transform(floatCoords, 0, ret, 0, numCoords / 2);
 287             }
 288             return ret;
 289         }
 290 
 291         @Override
 292         double[] cloneCoordsDouble(AffineTransform at) {
 293             // trim arrays:
 294             double ret[] = new double[numCoords];
 295             if (at == null) {
 296                 for (int i = 0; i < numCoords; i++) {
 297                     ret[i] = floatCoords[i];
 298                 }


1128          */
1129         public Double(Shape s, AffineTransform at) {
1130             if (s instanceof Path2D) {
1131                 Path2D p2d = (Path2D) s;
1132                 setWindingRule(p2d.windingRule);
1133                 this.numTypes = p2d.numTypes;
1134                 // trim arrays:
1135                 this.pointTypes = Arrays.copyOf(p2d.pointTypes, p2d.numTypes);
1136                 this.numCoords = p2d.numCoords;
1137                 this.doubleCoords = p2d.cloneCoordsDouble(at);
1138             } else {
1139                 PathIterator pi = s.getPathIterator(at);
1140                 setWindingRule(pi.getWindingRule());
1141                 this.pointTypes = new byte[INIT_SIZE];
1142                 this.doubleCoords = new double[INIT_SIZE * 2];
1143                 append(pi, false);
1144             }
1145         }
1146 
1147         @Override











1148         float[] cloneCoordsFloat(AffineTransform at) {
1149             // trim arrays:
1150             float ret[] = new float[numCoords];
1151             if (at == null) {
1152                 for (int i = 0; i < numCoords; i++) {
1153                     ret[i] = (float) doubleCoords[i];
1154                 }
1155             } else {
1156                 at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
1157             }
1158             return ret;
1159         }
1160 
1161         @Override
1162         double[] cloneCoordsDouble(AffineTransform at) {
1163             // trim arrays:
1164             double ret[];
1165             if (at == null) {
1166                 ret = Arrays.copyOf(doubleCoords, numCoords);
1167             } else {


2452     public final PathIterator getPathIterator(AffineTransform at,
2453                                               double flatness)
2454     {
2455         return new FlatteningPathIterator(getPathIterator(at), flatness);
2456     }
2457 
2458     /**
2459      * Creates a new object of the same class as this object.
2460      *
2461      * @return     a clone of this instance.
2462      * @exception  OutOfMemoryError            if there is not enough memory.
2463      * @see        java.lang.Cloneable
2464      * @since      1.6
2465      */
2466     public abstract Object clone();
2467         // Note: It would be nice to have this return Path2D
2468         // but one of our subclasses (GeneralPath) needs to
2469         // offer "public Object clone()" for backwards
2470         // compatibility so we cannot restrict it further.
2471         // REMIND: Can we do both somehow?









2472 
2473     /*
2474      * Support fields and methods for serializing the subclasses.
2475      */
2476     private static final byte SERIAL_STORAGE_FLT_ARRAY = 0x30;
2477     private static final byte SERIAL_STORAGE_DBL_ARRAY = 0x31;
2478 
2479     private static final byte SERIAL_SEG_FLT_MOVETO    = 0x40;
2480     private static final byte SERIAL_SEG_FLT_LINETO    = 0x41;
2481     private static final byte SERIAL_SEG_FLT_QUADTO    = 0x42;
2482     private static final byte SERIAL_SEG_FLT_CUBICTO   = 0x43;
2483 
2484     private static final byte SERIAL_SEG_DBL_MOVETO    = 0x50;
2485     private static final byte SERIAL_SEG_DBL_LINETO    = 0x51;
2486     private static final byte SERIAL_SEG_DBL_QUADTO    = 0x52;
2487     private static final byte SERIAL_SEG_DBL_CUBICTO   = 0x53;
2488 
2489     private static final byte SERIAL_SEG_CLOSE         = 0x60;
2490     private static final byte SERIAL_PATH_END          = 0x61;
2491 


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 259          */
 260         public Float(Shape s, AffineTransform at) {
 261             if (s instanceof Path2D) {
 262                 Path2D p2d = (Path2D) s;
 263                 setWindingRule(p2d.windingRule);
 264                 this.numTypes = p2d.numTypes;
 265                 // trim arrays:
 266                 this.pointTypes = Arrays.copyOf(p2d.pointTypes, p2d.numTypes);
 267                 this.numCoords = p2d.numCoords;
 268                 this.floatCoords = p2d.cloneCoordsFloat(at);
 269             } else {
 270                 PathIterator pi = s.getPathIterator(at);
 271                 setWindingRule(pi.getWindingRule());
 272                 this.pointTypes = new byte[INIT_SIZE];
 273                 this.floatCoords = new float[INIT_SIZE * 2];
 274                 append(pi, false);
 275             }
 276         }
 277 
 278         @Override
 279         public final void trimToSize() {
 280             // trim arrays:
 281             if (numTypes < pointTypes.length) {
 282                 this.pointTypes = Arrays.copyOf(pointTypes, numTypes);
 283             }
 284             if (numCoords < floatCoords.length) {
 285                 this.floatCoords = Arrays.copyOf(floatCoords, numCoords);
 286             }
 287         }
 288 
 289         @Override
 290         float[] cloneCoordsFloat(AffineTransform at) {
 291             // trim arrays:
 292             float ret[];
 293             if (at == null) {
 294                 ret = Arrays.copyOf(floatCoords, numCoords);
 295             } else {
 296                 ret = new float[numCoords];
 297                 at.transform(floatCoords, 0, ret, 0, numCoords / 2);
 298             }
 299             return ret;
 300         }
 301 
 302         @Override
 303         double[] cloneCoordsDouble(AffineTransform at) {
 304             // trim arrays:
 305             double ret[] = new double[numCoords];
 306             if (at == null) {
 307                 for (int i = 0; i < numCoords; i++) {
 308                     ret[i] = floatCoords[i];
 309                 }


1139          */
1140         public Double(Shape s, AffineTransform at) {
1141             if (s instanceof Path2D) {
1142                 Path2D p2d = (Path2D) s;
1143                 setWindingRule(p2d.windingRule);
1144                 this.numTypes = p2d.numTypes;
1145                 // trim arrays:
1146                 this.pointTypes = Arrays.copyOf(p2d.pointTypes, p2d.numTypes);
1147                 this.numCoords = p2d.numCoords;
1148                 this.doubleCoords = p2d.cloneCoordsDouble(at);
1149             } else {
1150                 PathIterator pi = s.getPathIterator(at);
1151                 setWindingRule(pi.getWindingRule());
1152                 this.pointTypes = new byte[INIT_SIZE];
1153                 this.doubleCoords = new double[INIT_SIZE * 2];
1154                 append(pi, false);
1155             }
1156         }
1157 
1158         @Override
1159         public final void trimToSize() {
1160             // trim arrays:
1161             if (numTypes < pointTypes.length) {
1162                 this.pointTypes = Arrays.copyOf(pointTypes, numTypes);
1163             }
1164             if (numCoords < doubleCoords.length) {
1165                 this.doubleCoords = Arrays.copyOf(doubleCoords, numCoords);
1166             }
1167         }
1168 
1169         @Override
1170         float[] cloneCoordsFloat(AffineTransform at) {
1171             // trim arrays:
1172             float ret[] = new float[numCoords];
1173             if (at == null) {
1174                 for (int i = 0; i < numCoords; i++) {
1175                     ret[i] = (float) doubleCoords[i];
1176                 }
1177             } else {
1178                 at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
1179             }
1180             return ret;
1181         }
1182 
1183         @Override
1184         double[] cloneCoordsDouble(AffineTransform at) {
1185             // trim arrays:
1186             double ret[];
1187             if (at == null) {
1188                 ret = Arrays.copyOf(doubleCoords, numCoords);
1189             } else {


2474     public final PathIterator getPathIterator(AffineTransform at,
2475                                               double flatness)
2476     {
2477         return new FlatteningPathIterator(getPathIterator(at), flatness);
2478     }
2479 
2480     /**
2481      * Creates a new object of the same class as this object.
2482      *
2483      * @return     a clone of this instance.
2484      * @exception  OutOfMemoryError            if there is not enough memory.
2485      * @see        java.lang.Cloneable
2486      * @since      1.6
2487      */
2488     public abstract Object clone();
2489         // Note: It would be nice to have this return Path2D
2490         // but one of our subclasses (GeneralPath) needs to
2491         // offer "public Object clone()" for backwards
2492         // compatibility so we cannot restrict it further.
2493         // REMIND: Can we do both somehow?
2494 
2495     /**
2496      * Trims the capacity of this Path2D instance to its current
2497      * size. An application can use this operation to minimize the
2498      * storage of a path.
2499      *
2500      * @since 10
2501      */
2502     public abstract void trimToSize();
2503 
2504     /*
2505      * Support fields and methods for serializing the subclasses.
2506      */
2507     private static final byte SERIAL_STORAGE_FLT_ARRAY = 0x30;
2508     private static final byte SERIAL_STORAGE_DBL_ARRAY = 0x31;
2509 
2510     private static final byte SERIAL_SEG_FLT_MOVETO    = 0x40;
2511     private static final byte SERIAL_SEG_FLT_LINETO    = 0x41;
2512     private static final byte SERIAL_SEG_FLT_QUADTO    = 0x42;
2513     private static final byte SERIAL_SEG_FLT_CUBICTO   = 0x43;
2514 
2515     private static final byte SERIAL_SEG_DBL_MOVETO    = 0x50;
2516     private static final byte SERIAL_SEG_DBL_LINETO    = 0x51;
2517     private static final byte SERIAL_SEG_DBL_QUADTO    = 0x52;
2518     private static final byte SERIAL_SEG_DBL_CUBICTO   = 0x53;
2519 
2520     private static final byte SERIAL_SEG_CLOSE         = 0x60;
2521     private static final byte SERIAL_PATH_END          = 0x61;
2522 


< prev index next >