use of java.awt.geom.PathIterator in project android_frameworks_base by ResurrectionRemix.
the class Path_Delegate method isEmpty.
/**
* Returns whether the path is empty (contains no lines or curves).
* @see Path#isEmpty
*/
public boolean isEmpty() {
if (!mCachedIsEmpty) {
return false;
}
float[] coords = new float[6];
mCachedIsEmpty = Boolean.TRUE;
for (PathIterator it = mPath.getPathIterator(null); !it.isDone(); it.next()) {
int type = it.currentSegment(coords);
if (type != PathIterator.SEG_MOVETO) {
// Once we know that the path is not empty, we do not need to check again unless
// Path#reset is called.
mCachedIsEmpty = false;
return false;
}
}
return true;
}
use of java.awt.geom.PathIterator in project jdk8u_jdk by JetBrains.
the class Path2DCopyConstructor method testEqual.
static void testEqual(Path2D pathA, Path2D pathB) {
final PathIterator itA = pathA.getPathIterator(null);
final PathIterator itB = pathB.getPathIterator(null);
float[] coordsA = new float[6];
float[] coordsB = new float[6];
int n = 0;
for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
int typeA = itA.currentSegment(coordsA);
int typeB = itB.currentSegment(coordsB);
if (typeA != typeB) {
throw new IllegalStateException("Path-segment[" + n + "] " + " type are not equals [" + typeA + "|" + typeB + "] !");
}
if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
throw new IllegalStateException("Path-segment[" + n + "] coords" + " are not equals [" + Arrays.toString(coordsA) + "|" + Arrays.toString(coordsB) + "] !");
}
}
if (!itA.isDone() || !itB.isDone()) {
throw new IllegalStateException("Paths do not have same lengths !");
}
log("testEqual: " + n + " segments.");
}
use of java.awt.geom.PathIterator in project poi by apache.
the class HSLFFreeformShape method setPath.
@Override
public int setPath(Path2D.Double path) {
Rectangle2D bounds = path.getBounds2D();
PathIterator it = path.getPathIterator(new AffineTransform());
List<byte[]> segInfo = new ArrayList<byte[]>();
List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
boolean isClosed = false;
int numPoints = 0;
while (!it.isDone()) {
double[] vals = new double[6];
int type = it.currentSegment(vals);
switch(type) {
case PathIterator.SEG_MOVETO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
segInfo.add(SEGMENTINFO_MOVETO);
numPoints++;
break;
case PathIterator.SEG_LINETO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(SEGMENTINFO_ESCAPE);
numPoints++;
break;
case PathIterator.SEG_CUBICTO:
pntInfo.add(new Point2D.Double(vals[0], vals[1]));
pntInfo.add(new Point2D.Double(vals[2], vals[3]));
pntInfo.add(new Point2D.Double(vals[4], vals[5]));
segInfo.add(SEGMENTINFO_CUBICTO);
segInfo.add(SEGMENTINFO_ESCAPE2);
numPoints++;
break;
case PathIterator.SEG_QUADTO:
//TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
LOG.log(POILogger.WARN, "SEG_QUADTO is not supported");
break;
case PathIterator.SEG_CLOSE:
pntInfo.add(pntInfo.get(0));
segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(SEGMENTINFO_ESCAPE);
segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(SEGMENTINFO_CLOSE);
isClosed = true;
numPoints++;
break;
default:
LOG.log(POILogger.WARN, "Ignoring invalid segment type " + type);
break;
}
it.next();
}
if (!isClosed) {
segInfo.add(SEGMENTINFO_LINETO);
}
segInfo.add(SEGMENTINFO_END);
AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
verticesProp.setNumberOfElementsInArray(pntInfo.size());
verticesProp.setNumberOfElementsInMemory(pntInfo.size());
verticesProp.setSizeOfElements(8);
for (int i = 0; i < pntInfo.size(); i++) {
Point2D.Double pnt = pntInfo.get(i);
byte[] data = new byte[8];
LittleEndian.putInt(data, 0, Units.pointsToMaster(pnt.getX() - bounds.getX()));
LittleEndian.putInt(data, 4, Units.pointsToMaster(pnt.getY() - bounds.getY()));
verticesProp.setElement(i, data);
}
opt.addEscherProperty(verticesProp);
EscherArrayProperty segmentsProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);
segmentsProp.setNumberOfElementsInArray(segInfo.size());
segmentsProp.setNumberOfElementsInMemory(segInfo.size());
segmentsProp.setSizeOfElements(0x2);
for (int i = 0; i < segInfo.size(); i++) {
byte[] seg = segInfo.get(i);
segmentsProp.setElement(i, seg);
}
opt.addEscherProperty(segmentsProp);
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(bounds.getWidth())));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bounds.getHeight())));
opt.sortProperties();
setAnchor(bounds);
return numPoints;
}
use of java.awt.geom.PathIterator in project JMRI by JMRI.
the class PositionablePolygon method scale.
private GeneralPath scale(float ratioX, float ratioY) {
// log.info("scale("+ratioX+" , "+ratioY+")");
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
PathIterator iter = getPathIterator(null);
float[] coord = new float[6];
while (!iter.isDone()) {
int type = iter.currentSegment(coord);
switch(type) {
case PathIterator.SEG_MOVETO:
path.moveTo(coord[0] * ratioX, coord[1] * ratioY);
break;
case PathIterator.SEG_LINETO:
path.lineTo(coord[0] * ratioX, coord[1] * ratioY);
break;
case PathIterator.SEG_QUADTO:
path.quadTo(coord[0], coord[1], coord[2], coord[3]);
break;
case PathIterator.SEG_CUBICTO:
path.curveTo(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
break;
case PathIterator.SEG_CLOSE:
path.closePath();
break;
default:
log.warn("Unhandled path iterator type: {}", type);
break;
}
// log.debug("type= "+type+" x= "+coord[0]+", y= "+ coord[1]);
iter.next();
}
return path;
}
use of java.awt.geom.PathIterator in project JMRI by JMRI.
the class DrawPolygon method makeParamsPanel.
@Override
protected JPanel makeParamsPanel(PositionableShape ps) {
JPanel panel = super.makeParamsPanel(ps);
_pShape = (PositionablePolygon) ps;
_editing = true;
_pShape.editing(true);
int x = getX();
int y = getY();
PathIterator iter = ps.getPathIterator(null);
float[] coord = new float[6];
while (!iter.isDone()) {
iter.currentSegment(coord);
_vertices.add(new Point(x + Math.round(coord[0]), y + Math.round(coord[1])));
iter.next();
}
_pShape.drawHandles();
return panel;
}
Aggregations