< 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 Path2D 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             return this;
 288         }
 289 
 290         @Override
 291         float[] cloneCoordsFloat(AffineTransform at) {
 292             // trim arrays:
 293             float ret[];
 294             if (at == null) {
 295                 ret = Arrays.copyOf(floatCoords, numCoords);
 296             } else {
 297                 ret = new float[numCoords];
 298                 at.transform(floatCoords, 0, ret, 0, numCoords / 2);
 299             }
 300             return ret;
 301         }
 302 
 303         @Override
 304         double[] cloneCoordsDouble(AffineTransform at) {
 305             // trim arrays:
 306             double ret[] = new double[numCoords];
 307             if (at == null) {
 308                 for (int i = 0; i < numCoords; i++) {
 309                     ret[i] = floatCoords[i];
 310                 }


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


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


< prev index next >