Search in sources :

Example 76 with Polygon

use of java.awt.Polygon in project airavata by apache.

the class DoWhileNodeGUI method createHeader.

private Polygon createHeader(Point position) {
    Polygon head = new Polygon();
    head.addPoint(position.x, position.y + this.headHeight / 2);
    head.addPoint(position.x, position.y + this.headHeight);
    head.addPoint(position.x + this.dimension.width, position.y + this.headHeight);
    head.addPoint(position.x + this.dimension.width, position.y + this.headHeight / 2);
    head.addPoint(position.x + this.dimension.width / 2, position.y);
    return head;
}
Also used : Polygon(java.awt.Polygon)

Example 77 with Polygon

use of java.awt.Polygon in project runelite by runelite.

the class Perspective method getAABB.

private static Area getAABB(Client client, List<Vertex> vertices, int orientation, int tileX, int tileY) {
    int maxX = 0;
    int minX = 0;
    int maxY = 0;
    int minY = 0;
    int maxZ = 0;
    int minZ = 0;
    for (Vertex vertex : vertices) {
        int x = vertex.getX();
        int y = vertex.getY();
        int z = vertex.getZ();
        if (x > maxX) {
            maxX = x;
        }
        if (x < minX) {
            minX = x;
        }
        if (y > maxY) {
            maxY = y;
        }
        if (y < minY) {
            minY = y;
        }
        if (z > maxZ) {
            maxZ = z;
        }
        if (z < minZ) {
            minZ = z;
        }
    }
    int centerX = (minX + maxX) / 2;
    int centerY = (minY + maxY) / 2;
    int centerZ = (minZ + maxZ) / 2;
    int extremeX = (maxX - minX + 1) / 2;
    int extremeY = (maxY - minY + 1) / 2;
    int extremeZ = (maxZ - minZ + 1) / 2;
    if (extremeX < 32) {
        extremeX = 32;
    }
    if (extremeZ < 32) {
        extremeZ = 32;
    }
    int x1 = tileX - (centerX - extremeX);
    int y1 = centerY - extremeY;
    int z1 = tileY - (centerZ - extremeZ);
    int x2 = tileX - (centerX + extremeX);
    int y2 = centerY + extremeY;
    int z2 = tileY - (centerZ + extremeZ);
    Point p1 = worldToCanvas(client, x1, z1, -y1, tileX, tileY);
    Point p2 = worldToCanvas(client, x1, z2, -y1, tileX, tileY);
    Point p3 = worldToCanvas(client, x2, z2, -y1, tileX, tileY);
    Point p4 = worldToCanvas(client, x2, z1, -y1, tileX, tileY);
    Point p5 = worldToCanvas(client, x1, z1, -y2, tileX, tileY);
    Point p6 = worldToCanvas(client, x1, z2, -y2, tileX, tileY);
    Point p7 = worldToCanvas(client, x2, z2, -y2, tileX, tileY);
    Point p8 = worldToCanvas(client, x2, z1, -y2, tileX, tileY);
    List<Point> points = new ArrayList<>(8);
    points.add(p1);
    points.add(p2);
    points.add(p3);
    points.add(p4);
    points.add(p5);
    points.add(p6);
    points.add(p7);
    points.add(p8);
    try {
        points = Jarvis.convexHull(points);
    } catch (NullPointerException e) {
        // No non-null screen points for this AABB e.g. for an way off-screen model
        return null;
    }
    if (points == null) {
        return null;
    }
    Polygon hull = new Polygon();
    for (Point p : points) {
        if (p != null) {
            hull.addPoint(p.getX(), p.getY());
        }
    }
    return new Area(hull);
}
Also used : Vertex(net.runelite.api.model.Vertex) Area(java.awt.geom.Area) ArrayList(java.util.ArrayList) LocalPoint(net.runelite.api.coords.LocalPoint) Polygon(java.awt.Polygon) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 78 with Polygon

use of java.awt.Polygon in project runelite by runelite.

the class Perspective method getCanvasTileAreaPoly.

/**
 * Returns a polygon representing an area.
 *
 * @param client
 * @param localLocation Center location of the AoE
 * @param size size of the area. Ex. Lizardman Shaman AoE is a 3x3, so
 * size = 3
 * @return a polygon representing the tiles in the area
 */
public static Polygon getCanvasTileAreaPoly(Client client, LocalPoint localLocation, int size) {
    int plane = client.getPlane();
    int halfTile = LOCAL_TILE_SIZE / 2;
    // If the size is 5, we need to shift it up and left 2 units, then expand by 5 units to make a 5x5
    int aoeSize = size / 2;
    // Shift over one half tile as localLocation is the center point of the tile, and then shift the area size
    Point topLeft = new Point(localLocation.getX() - (aoeSize * LOCAL_TILE_SIZE) - halfTile, localLocation.getY() - (aoeSize * LOCAL_TILE_SIZE) - halfTile);
    // expand by size
    Point bottomRight = new Point(topLeft.getX() + size * LOCAL_TILE_SIZE - 1, topLeft.getY() + size * LOCAL_TILE_SIZE - 1);
    // Take the x of top left and the y of bottom right to create bottom left
    Point bottomLeft = new Point(topLeft.getX(), bottomRight.getY());
    // Similarly for top right
    Point topRight = new Point(bottomRight.getX(), topLeft.getY());
    Point p1 = worldToCanvas(client, topLeft.getX(), topLeft.getY(), plane);
    Point p2 = worldToCanvas(client, topRight.getX(), topRight.getY(), plane);
    Point p3 = worldToCanvas(client, bottomRight.getX(), bottomRight.getY(), plane);
    Point p4 = worldToCanvas(client, bottomLeft.getX(), bottomLeft.getY(), plane);
    if (p1 == null || p2 == null || p3 == null || p4 == null) {
        return null;
    }
    Polygon poly = new Polygon();
    poly.addPoint(p1.getX(), p1.getY());
    poly.addPoint(p2.getX(), p2.getY());
    poly.addPoint(p3.getX(), p3.getY());
    poly.addPoint(p4.getX(), p4.getY());
    return poly;
}
Also used : LocalPoint(net.runelite.api.coords.LocalPoint) Polygon(java.awt.Polygon) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 79 with Polygon

use of java.awt.Polygon in project org.alloytools.alloy by AlloyTools.

the class OurPDFWriter method drawShape.

/**
 * Draws a shape.
 */
public OurPDFWriter drawShape(Shape shape, boolean fillOrNot) {
    if (shape instanceof Polygon) {
        Polygon obj = (Polygon) shape;
        for (int i = 0; i < obj.npoints; i++) buf.writes(obj.xpoints[i]).writes(obj.ypoints[i]).write(i == 0 ? "m\n" : "l\n");
        buf.write("h\n");
    } else {
        double moveX = 0, moveY = 0, nowX = 0, nowY = 0, pt[] = new double[6];
        for (PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next()) switch(it.currentSegment(pt)) {
            case PathIterator.SEG_MOVETO:
                nowX = moveX = pt[0];
                nowY = moveY = pt[1];
                buf.writes(nowX).writes(nowY).write("m\n");
                break;
            case PathIterator.SEG_CLOSE:
                nowX = moveX;
                nowY = moveY;
                buf.write("h\n");
                break;
            case PathIterator.SEG_LINETO:
                nowX = pt[0];
                nowY = pt[1];
                buf.writes(nowX).writes(nowY).write("l\n");
                break;
            case PathIterator.SEG_CUBICTO:
                nowX = pt[4];
                nowY = pt[5];
                buf.writes(pt[0]).writes(pt[1]).writes(pt[2]).writes(pt[3]).writes(nowX).writes(nowY).write("c\n");
                break;
            case // Convert quadratic bezier
            PathIterator.SEG_QUADTO:
                // into cubic bezier using
                // de Casteljau algorithm
                double px = nowX + (pt[0] - nowX) * (2.0 / 3.0), qx = px + (pt[2] - nowX) / 3.0;
                double py = nowY + (pt[1] - nowY) * (2.0 / 3.0), qy = py + (pt[3] - nowY) / 3.0;
                nowX = pt[2];
                nowY = pt[3];
                buf.writes(px).writes(py).writes(qx).writes(qy).writes(nowX).writes(nowY).write("c\n");
                break;
        }
    }
    buf.write(fillOrNot ? "f\n" : "S\n");
    return this;
}
Also used : PathIterator(java.awt.geom.PathIterator) Polygon(java.awt.Polygon)

Example 80 with Polygon

use of java.awt.Polygon in project TranskribusCore by Transkribus.

the class PageXmlUtils method doesIntersect.

// public static boolean isBaselineInLineBounds(TextLineType tl, String baseline, final int threshold) {
// final Polygon linePoly = PageXmlUtils.buildPolygon(tl.getCoords());
// Rectangle boundRect = linePoly.getBounds();
// List<Point> blPoints = PointStrUtils.parsePoints(baseline);
// boolean isIncluded = true;
// for(Point p : blPoints) {
// if(!GeomUtils.isInside(p.x, p.y, boundRect, threshold)) {
// isIncluded = false;
// break;
// }
// }
// return isIncluded;
// }
// public static double getOverlap(TextLineType tl, String baseline) {
// final String linePoints = tl.getCoords().getPoints();
// logger.debug("Line points: " + linePoints);
// List<Point2D> pointsLine = PointStrUtils.buildPoints2DList(linePoints);
// List<Point2D> pointsBaseline = PointStrUtils.buildPoints2DList(baseline);
// double o = GeomUtils.getOverlap(pointsLine, pointsBaseline);
// if(o > 0) {
// logger.debug("Overlap is: " + o);
// }
// return o;
// }
public static boolean doesIntersect(TextLineType tl, String baseline) {
    final String linePoints = tl.getCoords().getPoints();
    Polygon linePoly = PointStrUtils.buildPolygon(linePoints);
    Polygon baselinePoly = PointStrUtils.buildPolygon(baseline);
    // logger.debug(linePoly.getBounds2D().toString());
    // logger.debug(baselinePoly.getBounds2D().toString());
    Rectangle2D baselineRect = baselinePoly.getBounds2D();
    if (baselineRect.getHeight() == 0) {
        /*
			 * if the baseline is horizontal, the boundRect includes no area and thus
			 * there will not be an intersection...
			 */
        baselineRect.setRect(baselineRect.getX(), baselineRect.getY(), baselineRect.getWidth(), // blow this up to be height 1
        1);
    }
    return linePoly.intersects(baselineRect);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Polygon(java.awt.Polygon)

Aggregations

Polygon (java.awt.Polygon)192 Point (java.awt.Point)53 Rectangle (java.awt.Rectangle)30 Graphics2D (java.awt.Graphics2D)28 Area (java.awt.geom.Area)22 ArrayList (java.util.ArrayList)21 BasicStroke (java.awt.BasicStroke)20 Color (java.awt.Color)19 Paint (java.awt.Paint)15 Point2D (java.awt.geom.Point2D)13 AffineTransform (java.awt.geom.AffineTransform)12 Rectangle2D (java.awt.geom.Rectangle2D)12 Shape (java.awt.Shape)11 LocalPoint (net.runelite.api.coords.LocalPoint)11 Point (net.runelite.api.Point)10 FloatPolygon (ij.process.FloatPolygon)9 Font (java.awt.Font)8 List (java.util.List)8 FontMetrics (java.awt.FontMetrics)7 Stroke (java.awt.Stroke)7