use of java.awt.geom.PathIterator in project android_frameworks_base by ParanoidAndroid.
the class Path_Delegate method offset.
/**
* Offset the path by (dx,dy), returning true on success
*
* @param dx The amount in the X direction to offset the entire path
* @param dy The amount in the Y direction to offset the entire path
* @param dst The translated path is written here. If this is null, then
* the original path is modified.
*/
public void offset(float dx, float dy, Path_Delegate dst) {
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
use of java.awt.geom.PathIterator in project silk by jbee.
the class TestMockingBinds method methodsOfMocksByDefaultReturnMocksIfPossible.
@Test
public void methodsOfMocksByDefaultReturnMocksIfPossible() {
Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
Shape shape = injector.resolve(dependency(Shape.class));
PathIterator iter = shape.getPathIterator(null);
assertNotNull(iter);
assertTrue(isProxyClass(iter.getClass()));
assertFalse(iter.isDone());
}
use of java.awt.geom.PathIterator in project openblocks by mikaelhg.
the class BlockShapeUtil method printPath.
/** Prints out a GeneralPath. Used for debugging only */
public static void printPath(GeneralPath gp) {
if (gp == null) {
System.out.println("(null path)");
return;
}
int type;
float[] segment = new float[6];
PathIterator i = gp.getPathIterator(new AffineTransform());
while (!i.isDone()) {
type = i.currentSegment(segment);
if (type == PathIterator.SEG_MOVETO) {
System.out.println("m: (" + segment[0] + ", " + segment[1] + ")");
} else if (type == PathIterator.SEG_LINETO) {
System.out.println("l: (" + segment[0] + ", " + segment[1] + ")");
} else if (type == PathIterator.SEG_QUADTO) {
System.out.println("q: (" + segment[0] + ", " + segment[1] + "), (" + segment[2] + ", " + segment[3] + ")");
} else if (type == PathIterator.SEG_CUBICTO) {
System.out.println("c: (" + segment[0] + ", " + segment[1] + "), (" + segment[2] + ", " + segment[3] + "), (" + segment[4] + ", " + segment[5] + ")");
}
i.next();
}
}
use of java.awt.geom.PathIterator in project scriptographer by scriptographer.
the class Raster method getAverageColor.
/**
* @jshide
*/
public Color getAverageColor(Shape shape) {
// Rectangle2D rect = shape.getBounds2D();
GeneralPath path;
int width = getWidth();
int height = getHeight();
int startX = 0;
int startY = 0;
if (shape != null) {
Matrix inverse = getInverseMatrix();
if (inverse == null)
return null;
// Create a transformed path. This is faster than
// path.clone() / path.transform(at);
PathIterator pi = shape.getPathIterator(inverse.toAffineTransform());
path = new GeneralPath();
path.setWindingRule(pi.getWindingRule());
path.append(pi, false);
Rectangle2D bounds = path.getBounds2D();
// Fetch the sub image to iterate over and calculate average colors
// from
// Crop to the maximum size.
Rectangle2D.intersect(bounds, new Rectangle2D.Double(startX, startY, width, height), bounds);
width = (int) Math.ceil(bounds.getWidth());
height = (int) Math.ceil(bounds.getHeight());
// Are we completely outside the raster? If so, return null
if (width <= 0 || height <= 0)
return null;
startX = (int) Math.floor(bounds.getX());
startY = (int) Math.floor(bounds.getY());
} else {
path = null;
}
BufferedImage img = getSubImage(startX, startY, width, height);
// Raster check = new Raster(img);
// check.setPosition(rect.getCenterX(), rect.getCenterY());
WritableRaster raster = img.getRaster();
byte[] data = (byte[]) raster.getDataElements(0, 0, null);
float[] components = new float[data.length];
for (int i = 0; i < data.length; i++) components[i] = data[i] & 0xff;
long total = 1;
for (int y = 0; y < height; y++) {
for (int x = (y == 0) ? 1 : 0; x < width; x++) {
if (path == null || path.contains(x + startX, y + startY)) {
data = (byte[]) raster.getDataElements(x, height - 1 - y, data);
for (int i = 0; i < data.length; i++) components[i] += data[i] & 0xff;
total++;
}
}
}
total *= 255;
for (int i = 0; i < components.length; i++) components[i] = components[i] / total;
// Return colors
if (components.length == 4)
return new CMYKColor(components);
else if (components.length == 3)
return new RGBColor(components);
else
return new GrayColor(components);
}
use of java.awt.geom.PathIterator in project platform_frameworks_base by android.
the class Path_Delegate method offset.
/**
* Offset the path by (dx,dy), returning true on success
*
* @param dx The amount in the X direction to offset the entire path
* @param dy The amount in the Y direction to offset the entire path
*/
public void offset(float dx, float dy) {
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
newPath.append(iterator, false);
mPath = newPath;
}
Aggregations