本文整理汇总了Java中java.awt.geom.Area.getPathIterator方法的典型用法代码示例。如果您正苦于以下问题:Java Area.getPathIterator方法的具体用法?Java Area.getPathIterator怎么用?Java Area.getPathIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Area
的用法示例。
在下文中一共展示了Area.getPathIterator方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toMultiPolygon
import java.awt.geom.Area; //导入方法依赖的package包/类
static MultiPolygon toMultiPolygon(Area area) {
MultiPolygon ret = new MultiPolygon();
List<Vertex> verts = ret.getVertices();
PathIterator pi = area.getPathIterator(null);
double[] prev = null;
int type;
while (!pi.isDone()) {
double[] coords = new double[2];
type = pi.currentSegment(coords);
if (type == PathIterator.SEG_MOVETO) {
verts.add(new Vertex(coords[0], coords[1], SegmentType.MOVE));
} else if (type == PathIterator.SEG_LINETO) {
verts.add(new Vertex(coords[0], coords[1], SegmentType.LINE));
} else if (type == PathIterator.SEG_CLOSE) {
verts.add(new Vertex(0.0, 0.0, SegmentType.CLOSE));
} else {
throw new IllegalStateException("unexpected PathIterator segment type: " + type);
}
prev = coords;
pi.next();
}
return ret;
}
示例2: outline
import java.awt.geom.Area; //导入方法依赖的package包/类
public void outline(Area area, Consumer<Integer> drawLine) {
PathIterator pathIterator = area.getPathIterator(null);
double[] coordinates = new double[6];
int lastX = 0;
int lastY = 0;
while (!pathIterator.isDone()) {
int type = pathIterator.currentSegment(coordinates);
int x = (int) coordinates[0];
int y = (int) coordinates[1];
if (type == PathIterator.SEG_LINETO || type == PathIterator.SEG_MOVETO) {
if (type == PathIterator.SEG_LINETO) {
int deltaX = x - lastX;
int deltaY = y - lastY;
drawLine.accept(MathHelper.ceil(Math.sqrt((deltaX * deltaX) + (deltaY * deltaY))));
this.graphics.drawLine(lastX, lastY, x, y);
}
lastX = x;
lastY = y;
}
pathIterator.next();
}
}
示例3: getAreaPaths
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the paths described by the given <code>area</code>.
*/
private List<GeneralPath> getAreaPaths(Area area)
{
List<GeneralPath> roomPaths = new ArrayList<GeneralPath>();
GeneralPath roomPath = new GeneralPath();
for (PathIterator it = area.getPathIterator(null, 0.5f); !it.isDone(); it.next())
{
float[] roomPoint = new float[2];
switch (it.currentSegment(roomPoint))
{
case PathIterator.SEG_MOVETO:
roomPath.moveTo(roomPoint[0], roomPoint[1]);
break;
case PathIterator.SEG_LINETO:
roomPath.lineTo(roomPoint[0], roomPoint[1]);
break;
case PathIterator.SEG_CLOSE:
roomPath.closePath();
roomPaths.add(roomPath);
roomPath = new GeneralPath();
break;
}
}
return roomPaths;
}
示例4: getPath
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the path matching a given area.
*/
private GeneralPath getPath(Area area)
{
GeneralPath path = new GeneralPath();
float[] point = new float[2];
for (PathIterator it = area.getPathIterator(null, 0.5f); !it.isDone(); it.next())
{
switch (it.currentSegment(point))
{
case PathIterator.SEG_MOVETO:
path.moveTo(point[0], point[1]);
break;
case PathIterator.SEG_LINETO:
path.lineTo(point[0], point[1]);
break;
}
}
return path;
}
示例5: findKClosestLandmarks
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Finds and returns the k closest landmarks of a specific type to the point (x, y).
*
* @param k
* The number of landmarks to return.
* @param landmarks
* The landmarks to compare for the closest ones.
* @param type
* The type of landmarks to search.
* @param x
* The x coordinate of the point.
* @param y
* The y coordinate of the point.
* @return The k closest landmarks to the point (x, y).
*/
private static Iterable<Integer> findKClosestLandmarks(int k, List<Landmark> landmarks,
Path2D.Double navigableArea, Landmark.LandmarkType type, Rectangle2D.Double tile) {
LandmarkComparator comparator = new LandmarkComparator();
PriorityQueue<Object[]> orderedLandmarks =
new PriorityQueue<Object[]>(NUM_OF_MINIMAP_TILE_LANDMARKS, comparator);
int index = 0;
Area tileArea = new Area(tile);
tileArea.intersect(new Area(navigableArea));
for (Landmark landmark : landmarks) {
if (landmark.getType() == type) {
double distance = Distance.euclidean(tile.getCenterX(), tile.getCenterY(),
landmark.getLocation().getX(), landmark.getLocation().getY());
for (PathIterator pi = tileArea.getPathIterator(null); !pi.isDone(); pi.next()) {
double[] coordinates = new double[6];
if (pi.currentSegment(coordinates) != PathIterator.SEG_CLOSE && isAccessible(
new Line2D.Double(coordinates[0], coordinates[1], landmark.getParticles(0).getX(),
landmark.getParticles(0).getY()),
navigableArea)) {
Object[] orderedLandmark = { distance, index };
orderedLandmarks.add(orderedLandmark);
break;
}
}
}
++index;
}
int size = Math.min(orderedLandmarks.size(), k);
List<Integer> kClosestLandmarks = new LinkedList<>();
for (int i = 0; i < size; ++i)
kClosestLandmarks.add((Integer) orderedLandmarks.poll()[1]);
return kClosestLandmarks;
}
示例6: drawVertices
import java.awt.geom.Area; //导入方法依赖的package包/类
public void drawVertices(Area area) {
PathIterator pathIterator = area.getPathIterator(null);
double[] coordinates = new double[6];
while (!pathIterator.isDone()) {
int type = pathIterator.currentSegment(coordinates);
if (type == PathIterator.SEG_LINETO || type == PathIterator.SEG_MOVETO) {
int x = (int) coordinates[0];
int y = (int) coordinates[1];
this.graphics.drawLine(x, y, x, y);
}
pathIterator.next();
}
}
示例7: getAreaPoints
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the list of points that defines the given area.
*/
private List<float[][]> getAreaPoints(Area area)
{
List<float[][]> areaPoints = new ArrayList<float[][]>();
List<float[]> areaPartPoints = new ArrayList<float[]>();
float[] previousRoomPoint = null;
for (PathIterator it = area.getPathIterator(null, 1); !it.isDone(); it.next())
{
float[] roomPoint = new float[2];
if (it.currentSegment(roomPoint) == PathIterator.SEG_CLOSE)
{
if (areaPartPoints.get(0)[0] == previousRoomPoint[0]
&& areaPartPoints.get(0)[1] == previousRoomPoint[1])
{
areaPartPoints.remove(areaPartPoints.size() - 1);
}
if (areaPartPoints.size() > 2)
{
areaPoints.add(areaPartPoints.toArray(new float[areaPartPoints.size()][]));
}
areaPartPoints.clear();
previousRoomPoint = null;
}
else
{
if (previousRoomPoint == null || roomPoint[0] != previousRoomPoint[0]
|| roomPoint[1] != previousRoomPoint[1])
{
areaPartPoints.add(roomPoint);
}
previousRoomPoint = roomPoint;
}
}
return areaPoints;
}
示例8: getMirroredArea
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the mirror area of the given <code>area</code>.
*/
private Area getMirroredArea(Area area)
{
// As applying a -1 scale transform reverses the holes / non holes interpretation of the points,
// we have to create a mirrored shape by parsing points
GeneralPath mirrorPath = new GeneralPath();
float[] point = new float[6];
for (PathIterator it = area.getPathIterator(null); !it.isDone(); it.next())
{
switch (it.currentSegment(point))
{
case PathIterator.SEG_MOVETO:
mirrorPath.moveTo(1 - point[0], point[1]);
break;
case PathIterator.SEG_LINETO:
mirrorPath.lineTo(1 - point[0], point[1]);
break;
case PathIterator.SEG_QUADTO:
mirrorPath.quadTo(1 - point[0], point[1], 1 - point[2], point[3]);
break;
case PathIterator.SEG_CUBICTO:
mirrorPath.curveTo(1 - point[0], point[1], 1 - point[2], point[3], 1 - point[4], point[5]);
break;
case PathIterator.SEG_CLOSE:
mirrorPath.closePath();
break;
}
}
return new Area(mirrorPath);
}
示例9: getArea
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the area of this room.
*/
public float getArea()
{
if (this.areaCache == null)
{
Area roomArea = new Area(getShape());
if (roomArea.isSingular())
{
this.areaCache = Math.abs(getSignedArea(getPoints()));
}
else
{
// Add the surface of the different polygons of this room
float area = 0;
List<float[]> currentPathPoints = new ArrayList<float[]>();
for (PathIterator it = roomArea.getPathIterator(null); !it.isDone();)
{
float[] roomPoint = new float[2];
switch (it.currentSegment(roomPoint))
{
case PathIterator.SEG_MOVETO:
currentPathPoints.add(roomPoint);
break;
case PathIterator.SEG_LINETO:
currentPathPoints.add(roomPoint);
break;
case PathIterator.SEG_CLOSE:
float[][] pathPoints = currentPathPoints.toArray(new float[currentPathPoints.size()][]);
area += Math.abs(getSignedArea(pathPoints));
currentPathPoints.clear();
break;
}
it.next();
}
this.areaCache = area;
}
}
return this.areaCache;
}
示例10: getSurface
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns the surface of the given <code>area</code>.
*/
private float getSurface(Area area)
{
// Add the surface of the different polygons of this room
float surface = 0;
List<float[]> currentPathPoints = new ArrayList<float[]>();
for (PathIterator it = area.getPathIterator(null); !it.isDone();)
{
float[] roomPoint = new float[2];
switch (it.currentSegment(roomPoint))
{
case PathIterator.SEG_MOVETO:
currentPathPoints.add(roomPoint);
break;
case PathIterator.SEG_LINETO:
currentPathPoints.add(roomPoint);
break;
case PathIterator.SEG_CLOSE:
float[][] pathPoints = currentPathPoints.toArray(new float[currentPathPoints.size()][]);
surface += Math.abs(getSignedSurface(pathPoints));
currentPathPoints.clear();
break;
}
it.next();
}
return surface;
}
示例11: getConstrainingLines
import java.awt.geom.Area; //导入方法依赖的package包/类
public static List<Line2D.Double> getConstrainingLines(final Area area) {
final ArrayList<double[]> areaPoints = new ArrayList<>();
final ArrayList<Line2D.Double> areaSegments = new ArrayList<>();
final double[] coords = new double[6];
for (final PathIterator pi = area.getPathIterator(null); !pi.isDone(); pi.next()) {
// The type will be SEG_LINETO, SEG_MOVETO, or SEG_CLOSE
// Because the Area is composed of straight lines
final int type = pi.currentSegment(coords);
// We record a double array of x coord and y coord
final double[] pathIteratorCoords = { type, coords[0], coords[1] };
areaPoints.add(pathIteratorCoords);
}
double[] start = new double[3]; // To record where each polygon starts
for (int i = 0; i < areaPoints.size(); i++) {
// If we're not on the last point, return a line from this point to the
// next
final double[] currentElement = areaPoints.get(i);
// We need a default value in case we've reached the end of the ArrayList
double[] nextElement = { -1, -1, -1 };
if (i < areaPoints.size() - 1) {
nextElement = areaPoints.get(i + 1);
}
// Make the lines
if (currentElement[0] == PathIterator.SEG_MOVETO) {
start = currentElement; // Record where the polygon started to close it
// later
}
if (nextElement[0] == PathIterator.SEG_LINETO) {
areaSegments.add(new Line2D.Double(currentElement[1], currentElement[2], nextElement[1], nextElement[2]));
} else if (nextElement[0] == PathIterator.SEG_CLOSE) {
areaSegments.add(new Line2D.Double(currentElement[1], currentElement[2], start[1], start[2]));
}
}
return areaSegments;
}
示例12: getLightScopeOutsideWallsArea
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns walls area used for light scope outside.
*/
private Area getLightScopeOutsideWallsArea()
{
if (this.lightScopeOutsideWallsAreaCache == null)
{
// Compute a smaller area surrounding all walls at all levels
Area wallsPath = new Area();
for (Wall wall : home.getWalls())
{
Wall thinnerWall = wall.clone();
thinnerWall.setThickness(Math.max(thinnerWall.getThickness() - 0.1f, 0.08f));
wallsPath.add(new Area(getShape(thinnerWall.getPoints())));
}
Area lightScopeOutsideWallsArea = new Area();
List<float[]> points = new ArrayList<float[]>();
for (PathIterator it = wallsPath.getPathIterator(null, 1); !it.isDone(); it.next())
{
float[] point = new float[2];
switch (it.currentSegment(point))
{
case PathIterator.SEG_MOVETO:
case PathIterator.SEG_LINETO:
points.add(point);
break;
case PathIterator.SEG_CLOSE:
if (points.size() > 2)
{
float[][] pointsArray = points.toArray(new float[points.size()][]);
if (new Room(pointsArray).isClockwise())
{
lightScopeOutsideWallsArea.add(new Area(getShape(pointsArray)));
}
}
points.clear();
break;
}
}
this.lightScopeOutsideWallsAreaCache = lightScopeOutsideWallsArea;
}
return this.lightScopeOutsideWallsAreaCache;
}
示例13: splitAreaToPolygons
import java.awt.geom.Area; //导入方法依赖的package包/类
public static PolygonROI[][] splitAreaToPolygons(final Area area) {
Map<Boolean, List<PolygonROI>> map = new HashMap<>();
map.put(Boolean.TRUE, new ArrayList<>());
map.put(Boolean.FALSE, new ArrayList<>());
PathIterator iter = area.getPathIterator(null, 0.5);
List<Point2> points = new ArrayList<>();
double areaTempSigned = 0;
double areaCached = 0;
double[] seg = new double[6];
double startX = Double.NaN, startY = Double.NaN;
double x0 = 0, y0 = 0, x1 = 0, y1 = 0;
boolean closed = false;
while (!iter.isDone()) {
switch(iter.currentSegment(seg)) {
case PathIterator.SEG_MOVETO:
// Log starting positions - need them again for closing the path
startX = seg[0];
startY = seg[1];
x0 = startX;
y0 = startY;
iter.next();
areaCached += areaTempSigned;
areaTempSigned = 0;
points.clear();
points.add(new Point2(startX, startY));
closed = false;
continue;
case PathIterator.SEG_CLOSE:
x1 = startX;
y1 = startY;
closed = true;
break;
case PathIterator.SEG_LINETO:
x1 = seg[0];
y1 = seg[1];
points.add(new Point2(x1, y1));
closed = false;
break;
default:
// Shouldn't happen because of flattened PathIterator
throw new RuntimeException("Invalid area computation!");
};
areaTempSigned += 0.5 * (x0 * y1 - x1 * y0);
// Add polygon if it has just been closed
if (closed) {
if (areaTempSigned < 0)
map.get(Boolean.FALSE).add(new PolygonROI(points));
else if (areaTempSigned > 0)
map.get(Boolean.TRUE).add(new PolygonROI(points));
// Zero indicates the shape is empty...
}
// Update the coordinates
x0 = x1;
y0 = y1;
iter.next();
}
// TODO: Decide which is positive and which is negative
areaCached += areaTempSigned;
PolygonROI[][] polyOutput = new PolygonROI[2][];
if (areaCached < 0) {
polyOutput[0] = map.get(Boolean.TRUE).toArray(new PolygonROI[0]);
polyOutput[1] = map.get(Boolean.FALSE).toArray(new PolygonROI[0]);
} else {
polyOutput[0] = map.get(Boolean.FALSE).toArray(new PolygonROI[0]);
polyOutput[1] = map.get(Boolean.TRUE).toArray(new PolygonROI[0]);
}
// areaCached = Math.abs(areaCached + areaTempSigned);
return polyOutput;
}