Example usage for java.awt.geom Area getPathIterator

List of usage examples for java.awt.geom Area getPathIterator

Introduction

In this page you can find the example usage for java.awt.geom Area getPathIterator.

Prototype

public PathIterator getPathIterator(AffineTransform at) 

Source Link

Document

Creates a PathIterator for the outline of this Area object.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.subtract(a2);/*from  w ww .j ava2s.  c o  m*/

    g2.setColor(Color.orange);
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("subtract", 20, 140);

    System.out.println(a1.getPathIterator(new AffineTransform()));
}

From source file:it.unibo.alchemist.model.implementations.linkingrules.ConnectionBeam.java

private boolean projectedBeamOvercomesObstacle(final Position pos1, final Position pos2) {
    final double p1x = pos1.getCoordinate(0);
    final double p1y = pos1.getCoordinate(1);
    final double p2x = pos2.getCoordinate(0);
    final double p2y = pos2.getCoordinate(1);
    final double x = p2x - p1x;
    final double y = p2y - p1y;
    /*/*from  w ww .ja  v  a2s.c om*/
     * Compute the angle
     */
    final double angle = atan2(y, x);
    /*
     * Deduce surrounding beam vertices
     */
    final double dx = range * cos(PI / 2 + angle);
    final double dy = range * sin(PI / 2 + angle);
    /*
     * Enlarge the beam
     */
    final double cx = range * cos(angle);
    final double cy = range * sin(angle);
    /*
     * Create the beam
     */
    final Path2D.Double beamShape = new Path2D.Double();
    beamShape.moveTo(p1x + dx - cx, p1y + dy - cy);
    beamShape.lineTo(p1x - dx - cx, p1y - dy - cy);
    beamShape.lineTo(p2x - dx + cx, p2y - dy + cy);
    beamShape.lineTo(p2x + dx + cx, p2y + dy + cy);
    beamShape.closePath();
    final Area beam = new Area(beamShape);
    /*
     * Perform subtraction
     */
    beam.subtract(obstacles);
    /*
     * Rebuild single areas
     */
    final List<Path2D.Double> subareas = new ArrayList<>();
    Path2D.Double curpath = new Path2D.Double();
    final PathIterator pi = beam.getPathIterator(null);
    final double[] coords = new double[COORDS];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
            curpath = new Path2D.Double();
            curpath.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_LINETO:
            curpath.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_CLOSE:
            curpath.closePath();
            subareas.add(curpath);
            break;
        default:
            throw new IllegalArgumentException();
        }
        pi.next();
    }
    /*
     * At least one area must contain both points
     */
    for (final Path2D.Double p : subareas) {
        if (p.contains(p1x, p1y) && p.contains(p2x, p2y)) {
            return true;
        }
    }
    return false;
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public static GeneralPath areaToPath(final Area negativeArea, final double deltaX,
        final GeneralPath pixelPath) {

    final float[] floats = new float[6];
    // move to correct rectangle
    final AffineTransform transform = AffineTransform.getTranslateInstance(deltaX, 0.0);
    final PathIterator iterator = negativeArea.getPathIterator(transform);

    while (!iterator.isDone()) {
        final int segmentType = iterator.currentSegment(floats);
        if (segmentType == PathIterator.SEG_LINETO) {
            pixelPath.lineTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_MOVETO) {
            pixelPath.moveTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_CLOSE) {
            pixelPath.closePath();/*  w w w .j a  v  a  2  s .c o  m*/
        }
        iterator.next();
    }
    return pixelPath;
}

From source file:org.opensha.commons.geo.RegionTest.java

private static void readArea(Area area) {
    PathIterator pi = area.getPathIterator(null);
    double[] vertex = new double[6];
    while (!pi.isDone()) {
        pi.currentSegment(vertex);/*  w w  w  .  j a  v  a  2s .c  o  m*/
        System.out.println("AreaCoord: " + vertex[1] + " " + vertex[0]);
        pi.next();
    }
}