Example usage for java.awt.geom Point2D getY

List of usage examples for java.awt.geom Point2D getY

Introduction

In this page you can find the example usage for java.awt.geom Point2D getY.

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

From source file:ijfx.core.overlay.OverlayStatService.java

public boolean areColinear(Point2D pt1, Point2D pt2, Point2D pt3) {

    boolean colinear = false;

    double signedArea = ((pt2.getX() - pt1.getX()) * (pt3.getY() - pt1.getY()))
            - ((pt3.getX() - pt1.getX()) * (pt2.getY() - pt1.getY()));

    colinear = (signedArea == 0.0);//from   w ww  .j  a va2s . c o  m

    return colinear;
}

From source file:edu.uci.ics.jung.algorithms.layout.FRLayout.java

protected void calcRepulsion(V v1) {
    FRVertexData fvd1 = getFRData(v1);// www .j a  v  a2  s.  co m
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (V v2 : getGraph().getVertices()) {

            //                if (isLocked(v2)) continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta)));

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }

                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

From source file:org.jcurl.demo.tactics.BroomPromptSwingBean.java

private void syncM2V(final Point2D s) {
    if (s == null) {
        x.setValue(0);//from  w ww.ja v a2s .c  o  m
        y.setValue(0);
    } else {
        x.setValue(s.getX());
        y.setValue(s.getY());
    }
    x.setEnabled(s != null);
    y.setEnabled(s != null);
}

From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java

protected void calculateRepulsion() {
    try {//  ww w. ja  v  a  2s. co m
        for (V v : getGraph().getVertices()) {
            if (isLocked(v))
                continue;

            SpringVertexData svd = springVertexData.get(v);
            if (svd == null)
                continue;
            double dx = 0, dy = 0;

            for (V v2 : getGraph().getVertices()) {
                if (v == v2)
                    continue;
                Point2D p = transform(v);
                Point2D p2 = transform(v2);
                if (p == null || p2 == null)
                    continue;
                double vx = p.getX() - p2.getX();
                double vy = p.getY() - p2.getY();
                double distanceSq = p.distanceSq(p2);
                if (distanceSq == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distanceSq < repulsion_range_sq) {
                    double factor = 1;
                    dx += factor * vx / distanceSq;
                    dy += factor * vy / distanceSq;
                }
            }
            double dlen = dx * dx + dy * dy;
            if (dlen > 0) {
                dlen = Math.sqrt(dlen) / 2;
                svd.repulsiondx += dx / dlen;
                svd.repulsiondy += dy / dlen;
            }
        }
    } catch (ConcurrentModificationException cme) {
        calculateRepulsion();
    }
}

From source file:org.owasp.benchmark.score.report.ScatterVulns.java

private void makeDataLabels(String category, Set<Report> toolResults, XYPlot xyplot) {
    HashMap<Point2D, String> map = makePointList(category, toolResults);
    for (Entry<Point2D, String> e : map.entrySet()) {
        if (e.getValue() != null) {
            Point2D p = e.getKey();
            String label = sort(e.getValue());
            XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
            annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            if (label.toCharArray()[0] == averageLabel) {
                annotation.setPaint(Color.magenta);
            } else {
                annotation.setPaint(Color.blue);
            }/* ww  w.j a v  a  2 s. c o  m*/
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }
    }
}

From source file:org.apache.fontbox.cff.CharStringRenderer.java

private void rlineTo(Number dx, Number dy) {
    Point2D point = path.getCurrentPoint();
    path.lineTo((float) (point.getX() + dx.doubleValue()), (float) (point.getY() + dy.doubleValue()));
}

From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java

/**
 * process : Do : Paint the specified XObject (section 4.7).
 *
 * @param operator The operator that is being executed.
 * @param arguments List/*  www  .j a  va  2s.c o  m*/
 * @throws IOException If there is an error invoking the sub object.
 */
@Override
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context;

    PDPage page = extractor.getPage();
    COSName objectName = (COSName) arguments.get(0);
    Map<String, PDXObject> xobjects = extractor.getResources().getXObjects();
    PDXObject xobject = (PDXObject) xobjects.get(objectName.getName());
    if (xobject == null) {
        LOG.warn("Can't find the XObject for '" + objectName.getName() + "'");
    } else if (xobject instanceof PDXObjectImage) {
        PDXObjectImage image = (PDXObjectImage) xobject;
        try {
            if (image.getImageMask()) {
                // set the current non stroking colorstate, so that it can
                // be used to create a stencil masked image
                image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor());
            }
            BufferedImage awtImage = image.getRGBImage();
            if (awtImage == null) {
                LOG.warn("getRGBImage returned NULL");
                return;//TODO PKOCH
            }
            int imageWidth = awtImage.getWidth();
            int imageHeight = awtImage.getHeight();
            double pageHeight = extractor.getPageSize().getHeight();

            LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);

            Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix();
            float yScaling = ctm.getYScale();
            float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale());
            if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) {
                angle = (-1) * angle;
            }
            ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling));
            ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling));
            // because of the moved 0,0-reference, we have to shear in the opposite direction
            ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1));
            ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0));
            AffineTransform ctmAT = ctm.createAffineTransform();
            ctmAT.scale(1f / imageWidth, 1f / imageHeight);
            extractor.drawImage(awtImage, ctmAT);
        } catch (Exception e) {
            LOG.error(e, e);
        }
    } else if (xobject instanceof PDXObjectForm) {
        // save the graphics state
        context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone());

        PDXObjectForm form = (PDXObjectForm) xobject;
        COSStream formContentstream = form.getCOSStream();
        // find some optional resources, instead of using the current resources
        PDResources pdResources = form.getResources();
        // if there is an optional form matrix, we have to map the form space to the user space
        Matrix matrix = form.getMatrix();
        if (matrix != null) {
            Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix());
            context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
        }
        if (form.getBBox() != null) {
            PDGraphicsState graphicsState = context.getGraphicsState();
            PDRectangle bBox = form.getBBox();

            float x1 = bBox.getLowerLeftX();
            float y1 = bBox.getLowerLeftY();
            float x2 = bBox.getUpperRightX();
            float y2 = bBox.getUpperRightY();

            Point2D p0 = extractor.transformedPoint(x1, y1);
            Point2D p1 = extractor.transformedPoint(x2, y1);
            Point2D p2 = extractor.transformedPoint(x2, y2);
            Point2D p3 = extractor.transformedPoint(x1, y2);

            GeneralPath bboxPath = new GeneralPath();
            bboxPath.moveTo((float) p0.getX(), (float) p0.getY());
            bboxPath.lineTo((float) p1.getX(), (float) p1.getY());
            bboxPath.lineTo((float) p2.getX(), (float) p2.getY());
            bboxPath.lineTo((float) p3.getX(), (float) p3.getY());
            bboxPath.closePath();

            Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath());
            Area newArea = new Area(bboxPath);
            resultClippingArea.intersect(newArea);

            graphicsState.setCurrentClippingPath(resultClippingArea);
        }
        getContext().processSubStream(page, pdResources, formContentstream);

        // restore the graphics state
        context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop());
    }
}

From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java

/**
 * {@inheritDoc}/*from w w  w. j  av  a2s  .co m*/
 * Mode.PICKING      : Move node & edge
 * Mode.EDITING      : Add  node & edge
 * Mode.TRANSFORMING : Move graph layout
 */
@Override
public void mousePressed(MouseEvent e) {
    before.clear();
    //System.out.println("Before map cleared");
    if (!mode.equals(Mode.EDITING)) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY());

            if (mode.equals(Mode.TRANSFORMING)) {
                if (vertex != null || edge != null) {
                    setMode(Mode.PICKING);
                    vv.setCursor(Cursor.getPredefinedCursor(12));
                }
                if ((vertex == null && edge == null) && (e.isShiftDown())) {
                    setMode(Mode.PICKING);
                    vv.setCursor(Cursor.getPredefinedCursor(12));
                }
            } else if (mode.equals(Mode.PICKING) && !e.isShiftDown()) {
                if (vertex == null && edge == null) {
                    setMode(Mode.TRANSFORMING);
                }
            }
            //Final choosen mode is transforming ! -> Deselect all nodes
            if (mode.equals(Mode.TRANSFORMING)) {
                commandDispatcher.dispatch(new DeselectAllCommand());
            }

            //Save initial positions
            if (mode.equals(Mode.PICKING)) {
                if (vertex != null) {
                    saveInitialPositionOfPickedNodes(vv);
                }
            }
        }
    }

    //will call either :
    // - CadralEditingGraphMousePlugin.mousePressed(e)
    // - CadralPickingGraphMousePlugin.mousePressed(e)
    super.mousePressed(e);

    //System.out.println("Coords clicked : " + e.getPoint());
}

From source file:org.opensha.sha.calc.IM_EventSet.v03.test.IM_EventSetHazardCurveTest.java

@Test
public void testHazardCurve() throws IOException {
    HazardCurveCalculator calc = new HazardCurveCalculator();

    ArbitrarilyDiscretizedFunc realCurve = CyberShakePlotFromDBControlPanel.createUSGS_PGA_Function();
    ArbitrarilyDiscretizedFunc rLogHazFunction = getLogFunction(realCurve);
    System.out.println("IMR Params: " + imr.getAllParamMetadata());
    System.out.println("Calculating regular curve");
    calc.getHazardCurve(rLogHazFunction, site, imr, erf);
    realCurve = unLogFunction(realCurve, rLogHazFunction);

    runHAZ01A();//from  ww w .j a va2 s. c o  m
    String fileName = outputDir.getAbsolutePath() + File.separator + HAZ01Writer.HAZ01A_FILE_NAME;
    ScalarIntensityMeasureRelationshipAPI hIMR = new HAZ01A_FakeAttenRel(fileName);
    EqkRupForecastAPI hERF = new HAZ01A_FakeERF(erf);
    hERF.updateForecast();

    ArbitrarilyDiscretizedFunc hCurve = CyberShakePlotFromDBControlPanel.createUSGS_PGA_Function();
    System.out.println("Calculating IM based curve");
    ArbitrarilyDiscretizedFunc hLogHazFunction = getLogFunction(hCurve);
    calc.getHazardCurve(hLogHazFunction, site, hIMR, hERF);
    hCurve = unLogFunction(hCurve, hLogHazFunction);
    //      ArbitrarilyDiscretizedFunc realCurve =
    //         ArbitrarilyDiscretizedFunc.loadFuncFromSimpleFile("/tmp/imEventSetTest/curve.txt");

    ArrayList<ArbitrarilyDiscretizedFunc> curves = new ArrayList<ArbitrarilyDiscretizedFunc>();
    curves.add(realCurve);
    curves.add(hCurve);

    boolean xLog = false;
    boolean yLog = false;
    boolean customAxis = true;
    this.gp.drawGraphPanel(imt, "", curves, xLog, yLog, customAxis, "Curves", this);
    this.gp.setVisible(true);

    this.gp.togglePlot(null);

    this.gp.validate();
    this.gp.repaint();

    ChartUtilities.saveChartAsPNG(new File(outputDir.getAbsolutePath() + File.separator + "curves.png"),
            gp.getCartPanel().getChart(), 800, 600);

    double maxDiff = 0;
    double maxPDiff = 0;

    for (int i = 0; i < hCurve.getNum(); i++) {
        Point2D hPt = hCurve.get(i);
        Point2D rPt = realCurve.get(i);

        assertEquals(hPt.getX(), rPt.getX(), 0);

        if (hPt.getX() >= 10.)
            continue;

        System.out.println("Comparing point: " + i);

        System.out.println("\"Real\" point:\t" + rPt.getX() + ", " + rPt.getY());
        System.out.println("HAZ01A point:\t" + hPt.getX() + ", " + hPt.getY());

        if (hPt.getY() == 0 && rPt.getY() == 0)
            continue;

        double absDiff = Math.abs(hPt.getY() - rPt.getY());
        if (absDiff > maxDiff)
            maxDiff = absDiff;
        double absPDiff = absDiff / rPt.getY() * 100d;
        if (absPDiff > maxPDiff)
            maxPDiff = absPDiff;

        System.out.println("absDiff: " + absDiff + ", abs % diff: " + absPDiff);

        boolean success = absPDiff < TOL_PERCENT;
        if (!success) {
            System.out.println("FAIL!");
        }
        assertTrue(success);
    }

    System.out.println("Max Diff: " + maxDiff);
    System.out.println("Max Diff %: " + maxPDiff);
}

From source file:org.opennms.features.topology.app.internal.jung.TopoFRLayout.java

protected void calcRepulsion(V v1) {
    FRVertexData fvd1 = getFRData(v1);/*w  w  w .j  a  v  a 2 s . co m*/
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (V v2 : getGraph().getVertices()) {
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                xDelta = Math.abs(xDelta) > EPSILON ? xDelta
                        : xDelta == 0 ? epsilon() : Math.signum(xDelta) * EPSILON;
                yDelta = Math.abs(yDelta) > EPSILON ? yDelta
                        : yDelta == 0 ? epsilon() : Math.signum(yDelta) * EPSILON;

                double deltaLength = Math.sqrt((xDelta * xDelta) + (yDelta * yDelta));

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }
                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}