本文整理汇总了Java中java.awt.geom.FlatteningPathIterator类的典型用法代码示例。如果您正苦于以下问题:Java FlatteningPathIterator类的具体用法?Java FlatteningPathIterator怎么用?Java FlatteningPathIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FlatteningPathIterator类属于java.awt.geom包,在下文中一共展示了FlatteningPathIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: describeShapeDetail
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* Utility method that iterates over a Shape object and prints out the
* points. The flattening is used for a FlatteningPathIterator, controlling
* the scope of the path traversal.
*/
public static void describeShapeDetail(Shape shape, double flattening) {
PathIterator pi2 = shape.getPathIterator(null);
FlatteningPathIterator pi = new FlatteningPathIterator(pi2, flattening);
double[] coords = new double[6];
int pointCount = 0;
Debug.output(" -- start describeShapeDetail with flattening[" + flattening + "]");
while (!pi.isDone()) {
int type = pi.currentSegment(coords);
Debug.output(" Shape point [" + type + "] (" + (pointCount++) + ") " + coords[0] + ", "
+ coords[1]);
pi.next();
}
Debug.output(" -- end (" + pointCount + ")");
}
示例2: getStartPoint
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public static Point2D.Double getStartPoint(Shape shape) {
System.out.println("In getStartPoint Shape Bounds: "
+ shape.getBounds());
PathIterator pIter = new FlatteningPathIterator(
shape.getPathIterator(null), 1);
double x = 0.0, y = 0.0;
double[] coords = new double[6];
while (!pIter.isDone()) {
if (pIter == null)
break;
int currSeg = pIter.currentSegment(coords);
if (currSeg == PathIterator.SEG_MOVETO) {
for (int iter = 0; iter < coords.length; iter++) {
if (iter > 1)
break;
if (iter == 0)
x = coords[iter];
if (iter == 1)
y = coords[iter];
}
return new Point2D.Double(x, y);
}
pIter.next();
} // while(pIter.next())
return null;
}
示例3: length
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* Compute the length of the given shape.
* @param shape a path
* @return the length of the given path
*/
private static float length(Shape shape) {
float pathLength = 0f; // the accumulated length
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null),
TextStroke.FLATNESS);
float moveX = 0, moveY = 0, lastX = 0, lastY = 0;
while (!it.isDone()) {
float coords[] = new float[6];
int segmentType = it.currentSegment(coords);
switch(segmentType){
case PathIterator.SEG_MOVETO:
// store the new coordinates
moveX = lastX = coords[0];
moveY = lastY = coords[1];
break;
case PathIterator.SEG_CLOSE:
// close the path: in this case, the coords is empty so we put the
// last move as the new point...
coords[0] = moveX;
coords[1] = moveY;
// ... treat the segment type as a lineTo segment
case PathIterator.SEG_LINETO:
pathLength += Point2D.distance(lastX, lastY, coords[0], coords[1]);
lastX = coords[0];
lastY = coords[1];
break;
}
it.next(); // next segment
}
return pathLength;
}
示例4: doTraceAfterSetup
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
private void doTraceAfterSetup(Shape shape) {
int startingX = 0;
int startingY = 0;
PathIterator fpi = new FlatteningPathIterator(shape.getPathIterator(null), 1.0);
float[] coords = new float[2];
while (!fpi.isDone()) {
int type = fpi.currentSegment(coords);
int x = (int) coords[0];
int y = (int) coords[1];
brushAffectedArea.updateAffectedCoordinates(x, y);
switch (type) {
case PathIterator.SEG_MOVETO:
startingX = x;
startingY = y;
brush.onDragStart(x, y);
break;
case PathIterator.SEG_LINETO:
brush.onNewMousePoint(x, y);
break;
case PathIterator.SEG_CLOSE:
brush.onNewMousePoint(startingX, startingY);
break;
default:
throw new IllegalArgumentException("type = " + type);
}
fpi.next();
}
}
示例5: measurePathLength
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public float measurePathLength(Shape pShape) {
PathIterator it = new FlatteningPathIterator(pShape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float total = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch(type){
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX-lastX;
float dy = thisY-lastY;
total += (float)Math.sqrt(dx*dx + dy*dy);
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return total;
}
示例6: detectCollision
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* Determines, whether or not a given point p is in an epsilon-neighbourhood
* for the cubic curve.
*/
public boolean detectCollision(Point p) {
if (arrowLinkCurve == null)
return false;
Rectangle2D rec = getControlPoint(p);
// flatten the curve and test for intersection (bug fix, fc, 16.1.2004).
FlatteningPathIterator pi = new FlatteningPathIterator(
arrowLinkCurve.getPathIterator(null),
MAXIMAL_RECTANGLE_SIZE_FOR_COLLISION_DETECTION / 4, 10/*
* =maximal
* 2^10=1024
* points.
*/);
double oldCoordinateX = 0, oldCoordinateY = 0;
while (pi.isDone() == false) {
double[] coordinates = new double[6];
int type = pi.currentSegment(coordinates);
switch (type) {
case PathIterator.SEG_LINETO:
if (rec.intersectsLine(oldCoordinateX, oldCoordinateY,
coordinates[0], coordinates[1]))
return true;
/*
* this case needs the same action as the next case, thus no
* "break"
*/
case PathIterator.SEG_MOVETO:
oldCoordinateX = coordinates[0];
oldCoordinateY = coordinates[1];
break;
case PathIterator.SEG_QUADTO:
case PathIterator.SEG_CUBICTO:
case PathIterator.SEG_CLOSE:
default:
break;
}
pi.next();
}
return false;
}
示例7: printShape
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public static String printShape(Shape shape) {
System.out.println("In printShape Shape Bounds: " + shape.getBounds());
StringBuffer mesg = new StringBuffer();
PathIterator pIter = new FlatteningPathIterator(
shape.getPathIterator(null), 1);
// PathIterator pIter = shape.getPathIterator(null);
mesg.append("\n----PRINTING PATH DATA POINTS----\n");
int data_index = 0;
double[] coords = new double[6];
String pathSeg = "";
while (!pIter.isDone()) {
if (pIter == null)
break;
int currSeg = pIter.currentSegment(coords);
if (currSeg == PathIterator.SEG_MOVETO)
pathSeg = "MOVE TO ";
else if (currSeg == PathIterator.SEG_LINETO)
pathSeg = "LINE TO ";
else if (currSeg == PathIterator.SEG_CUBICTO)
pathSeg = "CUBIC TO ";
else if (currSeg == PathIterator.SEG_QUADTO)
pathSeg = "QUAD TO ";
else if (currSeg == PathIterator.SEG_CLOSE)
pathSeg = "CLOSE PATH ";
mesg.append(pathSeg);
for (int iter = 0; iter < coords.length; iter++) {
mesg.append(coords[iter] + " ");
}
mesg.append("\n");
pIter.next();
} // while(pIter.next())
return mesg.toString();
}
示例8: measurePathLength
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public static float measurePathLength(Shape shape) {
float FLATNESS = 1;
PathIterator it = new FlatteningPathIterator(
shape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float total = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX - lastX;
float dy = thisY - lastY;
total += (float) Math.sqrt(dx * dx + dy * dy);
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return total;
}
示例9: createStrokedShape
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape (Shape shape) {
GeneralPath result = new GeneralPath();
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float next = 0;
int phase = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
result.moveTo(moveX, moveY);
next = wavelength / 2;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float)Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
if ((phase & 1) == 0)
result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r);
else
result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r);
next += wavelength;
phase++;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
if (type == PathIterator.SEG_CLOSE) result.closePath();
break;
}
it.next();
}
return new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(result);
}
示例10: createStrokedShape
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
*/
public Shape createStrokedShape (Shape shape) {
GeneralPath result = new GeneralPath();
shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape);
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
float points[] = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float next = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = randomize(points[0]);
moveY = lastY = randomize(points[1]);
result.moveTo(moveX, moveY);
next = 0;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = randomize(points[0]);
thisY = randomize(points[1]);
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float)Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
result.lineTo(randomize(x), randomize(y));
next += detail;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return result;
}
示例11: getPathIterator
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public PathIterator getPathIterator(AffineTransform at, double flatness) {
return new FlatteningPathIterator(getPathIterator(at),flatness);
}
示例12: satin
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
protected Shape satin(Shape shape) {
if (shape == null) {
return null;
}
GeneralPath result = new GeneralPath();
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), flatness);
float[] points = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX, thisY;
int type;
float next = 0;
int phase = 0;
while (!it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
result.moveTo(moveX, moveY);
next = wavelength / 2;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float) Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
while (distance >= next) {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
if ((phase & 1) == 0) {
result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r);
} else {
result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r);
}
next += wavelength;
phase++;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
if (type == PathIterator.SEG_CLOSE) {
result.closePath();
}
break;
}
it.next();
}
return result;
}
示例13: textShape
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
private Shape textShape(Shape shape) {
AffineTransform t = new AffineTransform();
FontRenderContext frc = new FontRenderContext(null, true, true);
GlyphVector glyphVector = font.createGlyphVector(frc, content);
GeneralPath result = new GeneralPath();
PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), 1);
float[] points = new float[6];
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
int type = 0;
float next = 0;
int currentChar = 0;
int length = glyphVector.getNumGlyphs();
if (length == 0) {
return result;
}
float factor = 1.0f;
float nextAdvance = 0;
while (currentChar < length && !it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
moveX = lastX = points[0];
moveY = lastY = points[1];
result.moveTo(moveX, moveY);
nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f;
next = nextAdvance;
break;
case PathIterator.SEG_CLOSE:
points[0] = moveX;
points[1] = moveY;
// Fall into....
case PathIterator.SEG_LINETO:
thisX = points[0];
thisY = points[1];
float dx = thisX - lastX;
float dy = thisY - lastY;
float distance = (float) Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
float angle = (float) Math.atan2(dy, dx);
while (currentChar < length && distance >= next) {
Shape glyph = glyphVector.getGlyphOutline(currentChar);
Point2D p = glyphVector.getGlyphPosition(currentChar);
float px = (float) p.getX();
float py = (float) p.getY();
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
float advance = nextAdvance;
nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
t.setToTranslation(x, y);
t.rotate(angle);
t.translate(-px - advance, -py);
result.append(t.createTransformedShape(glyph), false);
next += (advance + nextAdvance) * factor;
currentChar++;
}
}
next -= distance;
lastX = thisX;
lastY = thisY;
break;
}
it.next();
}
return result;
}
示例14: getPathLength
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
public static double getPathLength(Path2D path, double scaleX, double scaleY)
{
PathIterator outline = new FlatteningPathIterator(path
.getPathIterator(null), 1e-4);
double length = 0;
double[] pointData = new double[6];
Point2D.Double start = new Point2D.Double();
Point2D.Double last = new Point2D.Double();
Point2D.Double current = new Point2D.Double();
double resultLength = 0;
double segLength = 0;
boolean first = true;
double dx = 0;
double dy = 0;
outline.next();
while (!outline.isDone())
{
if (outline.currentSegment(pointData) != PathIterator.SEG_CLOSE)
{
if (first)
{
first = false;
start.x = pointData[0];
start.y = pointData[1];
current.x = pointData[0];
current.y = pointData[1];
} else
{
last.x = current.x;
last.y = current.y;
current.x = pointData[0];
current.y = pointData[1];
dx = (last.x - current.x) * scaleX;
dy = (last.y - current.y) * scaleY;
segLength = Math.sqrt(dx * dx + dy * dy);
resultLength += segLength;
}
}
outline.next();
}
return resultLength;
}
示例15: getPathIterator
import java.awt.geom.FlatteningPathIterator; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public PathIterator getPathIterator(AffineTransform at, double flatness) {
return new FlatteningPathIterator(getPathIterator(at), flatness);
}