MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / makeShapeFromArray

Method makeShapeFromArray

ij/src/main/java/ij/gui/ShapeRoi.java:355–385  ·  view source on GitHub ↗

Constructs a GeneralPath from a float array of segment type+coordinates for each segment. The resulting GeneralPath has winding rule WIND_EVEN_ODD, which is appropriate for closed shapes

(float[] array)

Source from the content-addressed store, hash-verified

353 /** Constructs a GeneralPath from a float array of segment type+coordinates for each segment.
354 * The resulting GeneralPath has winding rule WIND_EVEN_ODD, which is appropriate for closed shapes */
355 static GeneralPath makeShapeFromArray(float[] array) {
356 if(array==null) return null;
357 GeneralPath s = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
358 int index=0;
359 float[] seg = new float[7];
360 while (true) {
361 //if(index<array.length)IJ.log(index+" type="+array[index]);
362 index = getSegment(array, seg, index);
363 if (index<0) break;
364 int type = (int)seg[0];
365 switch(type) {
366 case PathIterator.SEG_MOVETO:
367 ((GeneralPath)s).moveTo(seg[1], seg[2]);
368 break;
369 case PathIterator.SEG_LINETO:
370 ((GeneralPath)s).lineTo(seg[1], seg[2]);
371 break;
372 case PathIterator.SEG_QUADTO:
373 ((GeneralPath)s).quadTo(seg[1], seg[2],seg[3], seg[4]);
374 break;
375 case PathIterator.SEG_CUBICTO:
376 ((GeneralPath)s).curveTo(seg[1], seg[2], seg[3], seg[4], seg[5], seg[6]);
377 break;
378 case PathIterator.SEG_CLOSE:
379 ((GeneralPath)s).closePath();
380 break;
381 default: break;
382 }
383 }
384 return s;
385 }
386
387 /** Reads the data of a segment from an array describing the shape at as in a PathIterator. Reading starts at 'index'.
388 * The position in the array for the next segment is returned, -1 if the array ends.

Callers 3

ShapeRoiMethod · 0.95
cloneShapeMethod · 0.95
parsePathMethod · 0.95

Calls 3

getSegmentMethod · 0.95
moveToMethod · 0.45
lineToMethod · 0.45

Tested by

no test coverage detected