203 * @param s the specified {@code Shape} object 204 * @since 1.6 205 */ 206 public Float(Shape s) { 207 this(s, null); 208 } 209 210 /** 211 * Constructs a new single precision {@code Path2D} object 212 * from an arbitrary {@link Shape} object, transformed by an 213 * {@link AffineTransform} object. 214 * All of the initial geometry and the winding rule for this path are 215 * taken from the specified {@code Shape} object and transformed 216 * by the specified {@code AffineTransform} object. 217 * 218 * @param s the specified {@code Shape} object 219 * @param at the specified {@code AffineTransform} object 220 * @since 1.6 221 */ 222 public Float(Shape s, AffineTransform at) { 223 if (s instanceof Path2D) { 224 Path2D p2d = (Path2D) s; 225 setWindingRule(p2d.windingRule); 226 this.numTypes = p2d.numTypes; 227 this.pointTypes = Arrays.copyOf(p2d.pointTypes, 228 p2d.pointTypes.length); 229 this.numCoords = p2d.numCoords; 230 this.floatCoords = p2d.cloneCoordsFloat(at); 231 } else { 232 PathIterator pi = s.getPathIterator(at); 233 setWindingRule(pi.getWindingRule()); 234 this.pointTypes = new byte[INIT_SIZE]; 235 this.floatCoords = new float[INIT_SIZE * 2]; 236 append(pi, false); 237 } 238 } 239 240 float[] cloneCoordsFloat(AffineTransform at) { 241 float ret[]; 242 if (at == null) { 243 ret = Arrays.copyOf(this.floatCoords, this.floatCoords.length); 244 } else { 245 ret = new float[floatCoords.length]; 246 at.transform(floatCoords, 0, ret, 0, numCoords / 2); 247 } 248 return ret; 249 } 250 251 double[] cloneCoordsDouble(AffineTransform at) { 252 double ret[] = new double[floatCoords.length]; 253 if (at == null) { 254 for (int i = 0; i < numCoords; i++) { 255 ret[i] = floatCoords[i]; 256 } 257 } else { 258 at.transform(floatCoords, 0, ret, 0, numCoords / 2); 259 } 260 return ret; 261 } 262 263 void append(float x, float y) { 264 floatCoords[numCoords++] = x; 265 floatCoords[numCoords++] = y; 266 } 267 268 void append(double x, double y) { 269 floatCoords[numCoords++] = (float) x; 270 floatCoords[numCoords++] = (float) y; 271 } 272 1040 * @param s the specified {@code Shape} object 1041 * @since 1.6 1042 */ 1043 public Double(Shape s) { 1044 this(s, null); 1045 } 1046 1047 /** 1048 * Constructs a new double precision {@code Path2D} object 1049 * from an arbitrary {@link Shape} object, transformed by an 1050 * {@link AffineTransform} object. 1051 * All of the initial geometry and the winding rule for this path are 1052 * taken from the specified {@code Shape} object and transformed 1053 * by the specified {@code AffineTransform} object. 1054 * 1055 * @param s the specified {@code Shape} object 1056 * @param at the specified {@code AffineTransform} object 1057 * @since 1.6 1058 */ 1059 public Double(Shape s, AffineTransform at) { 1060 if (s instanceof Path2D) { 1061 Path2D p2d = (Path2D) s; 1062 setWindingRule(p2d.windingRule); 1063 this.numTypes = p2d.numTypes; 1064 this.pointTypes = Arrays.copyOf(p2d.pointTypes, 1065 p2d.pointTypes.length); 1066 this.numCoords = p2d.numCoords; 1067 this.doubleCoords = p2d.cloneCoordsDouble(at); 1068 } else { 1069 PathIterator pi = s.getPathIterator(at); 1070 setWindingRule(pi.getWindingRule()); 1071 this.pointTypes = new byte[INIT_SIZE]; 1072 this.doubleCoords = new double[INIT_SIZE * 2]; 1073 append(pi, false); 1074 } 1075 } 1076 1077 float[] cloneCoordsFloat(AffineTransform at) { 1078 float ret[] = new float[doubleCoords.length]; 1079 if (at == null) { 1080 for (int i = 0; i < numCoords; i++) { 1081 ret[i] = (float) doubleCoords[i]; 1082 } 1083 } else { 1084 at.transform(doubleCoords, 0, ret, 0, numCoords / 2); 1085 } 1086 return ret; 1087 } 1088 1089 double[] cloneCoordsDouble(AffineTransform at) { 1090 double ret[]; 1091 if (at == null) { 1092 ret = Arrays.copyOf(this.doubleCoords, 1093 this.doubleCoords.length); 1094 } else { 1095 ret = new double[doubleCoords.length]; 1096 at.transform(doubleCoords, 0, ret, 0, numCoords / 2); 1097 } 1098 return ret; 1099 } 1100 1101 void append(float x, float y) { 1102 doubleCoords[numCoords++] = x; 1103 doubleCoords[numCoords++] = y; 1104 } 1105 1106 void append(double x, double y) { 1107 doubleCoords[numCoords++] = x; 1108 doubleCoords[numCoords++] = y; 1109 } 1110 1111 Point2D getPoint(int coordindex) { 1112 return new Point2D.Double(doubleCoords[coordindex], 1113 doubleCoords[coordindex+1]); 1114 } 1115 | 203 * @param s the specified {@code Shape} object 204 * @since 1.6 205 */ 206 public Float(Shape s) { 207 this(s, null); 208 } 209 210 /** 211 * Constructs a new single precision {@code Path2D} object 212 * from an arbitrary {@link Shape} object, transformed by an 213 * {@link AffineTransform} object. 214 * All of the initial geometry and the winding rule for this path are 215 * taken from the specified {@code Shape} object and transformed 216 * by the specified {@code AffineTransform} object. 217 * 218 * @param s the specified {@code Shape} object 219 * @param at the specified {@code AffineTransform} object 220 * @since 1.6 221 */ 222 public Float(Shape s, AffineTransform at) { 223 super(); 224 if (s instanceof Path2D) { 225 Path2D p2d = (Path2D) s; 226 setWindingRule(p2d.windingRule); 227 this.numTypes = p2d.numTypes; 228 // trim arrays: 229 this.pointTypes = Arrays.copyOf(p2d.pointTypes, this.numTypes); 230 this.numCoords = p2d.numCoords; 231 this.floatCoords = p2d.cloneCoordsFloat(at); 232 } else { 233 PathIterator pi = s.getPathIterator(at); 234 setWindingRule(pi.getWindingRule()); 235 this.pointTypes = new byte[INIT_SIZE]; 236 this.floatCoords = new float[INIT_SIZE * 2]; 237 append(pi, false); 238 } 239 } 240 241 @Override 242 float[] cloneCoordsFloat(AffineTransform at) { 243 // trim arrays: 244 float ret[]; 245 if (at == null) { 246 ret = Arrays.copyOf(floatCoords, numCoords); 247 } else { 248 ret = new float[numCoords]; 249 at.transform(floatCoords, 0, ret, 0, numCoords / 2); 250 } 251 return ret; 252 } 253 254 @Override 255 double[] cloneCoordsDouble(AffineTransform at) { 256 // trim arrays: 257 double ret[] = new double[numCoords]; 258 if (at == null) { 259 for (int i = 0; i < numCoords; i++) { 260 ret[i] = floatCoords[i]; 261 } 262 } else { 263 at.transform(floatCoords, 0, ret, 0, numCoords / 2); 264 } 265 return ret; 266 } 267 268 void append(float x, float y) { 269 floatCoords[numCoords++] = x; 270 floatCoords[numCoords++] = y; 271 } 272 273 void append(double x, double y) { 274 floatCoords[numCoords++] = (float) x; 275 floatCoords[numCoords++] = (float) y; 276 } 277 1045 * @param s the specified {@code Shape} object 1046 * @since 1.6 1047 */ 1048 public Double(Shape s) { 1049 this(s, null); 1050 } 1051 1052 /** 1053 * Constructs a new double precision {@code Path2D} object 1054 * from an arbitrary {@link Shape} object, transformed by an 1055 * {@link AffineTransform} object. 1056 * All of the initial geometry and the winding rule for this path are 1057 * taken from the specified {@code Shape} object and transformed 1058 * by the specified {@code AffineTransform} object. 1059 * 1060 * @param s the specified {@code Shape} object 1061 * @param at the specified {@code AffineTransform} object 1062 * @since 1.6 1063 */ 1064 public Double(Shape s, AffineTransform at) { 1065 super(); 1066 if (s instanceof Path2D) { 1067 Path2D p2d = (Path2D) s; 1068 setWindingRule(p2d.windingRule); 1069 this.numTypes = p2d.numTypes; 1070 // trim arrays: 1071 this.pointTypes = Arrays.copyOf(p2d.pointTypes, this.numTypes); 1072 this.numCoords = p2d.numCoords; 1073 this.doubleCoords = p2d.cloneCoordsDouble(at); 1074 } else { 1075 PathIterator pi = s.getPathIterator(at); 1076 setWindingRule(pi.getWindingRule()); 1077 this.pointTypes = new byte[INIT_SIZE]; 1078 this.doubleCoords = new double[INIT_SIZE * 2]; 1079 append(pi, false); 1080 } 1081 } 1082 1083 @Override 1084 float[] cloneCoordsFloat(AffineTransform at) { 1085 // trim arrays: 1086 float ret[] = new float[numCoords]; 1087 if (at == null) { 1088 for (int i = 0; i < numCoords; i++) { 1089 ret[i] = (float) doubleCoords[i]; 1090 } 1091 } else { 1092 at.transform(doubleCoords, 0, ret, 0, numCoords / 2); 1093 } 1094 return ret; 1095 } 1096 1097 @Override 1098 double[] cloneCoordsDouble(AffineTransform at) { 1099 // trim arrays: 1100 double ret[]; 1101 if (at == null) { 1102 ret = Arrays.copyOf(doubleCoords, numCoords); 1103 } else { 1104 ret = new double[numCoords]; 1105 at.transform(doubleCoords, 0, ret, 0, numCoords / 2); 1106 } 1107 return ret; 1108 } 1109 1110 void append(float x, float y) { 1111 doubleCoords[numCoords++] = x; 1112 doubleCoords[numCoords++] = y; 1113 } 1114 1115 void append(double x, double y) { 1116 doubleCoords[numCoords++] = x; 1117 doubleCoords[numCoords++] = y; 1118 } 1119 1120 Point2D getPoint(int coordindex) { 1121 return new Point2D.Double(doubleCoords[coordindex], 1122 doubleCoords[coordindex+1]); 1123 } 1124 |