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:util.ModSpringLayout2.java

protected void relaxEdges() {
    try {//from   w w  w  .j a va2 s .  c  o m
        for (E e : getGraph().getEdges()) {

            V v1 = getAVertex(e);
            V v2 = getGraph().getOpposite(v1, e);

            Point2D p1 = transform(v1);
            Point2D p2 = transform(v2);
            if (p1 == null || p2 == null)
                continue;
            double vx = p1.getX() - p2.getX();
            double vy = p1.getY() - p2.getY();
            double len = Math.sqrt(vx * vx + vy * vy);

            SpringEdgeData<E> sed = getSpringDataEdge(e);
            if (sed == null) {
                continue;
            }
            double desiredLen = sed.length;

            // round from zero, if needed [zero would be Bad.].
            len = (len == 0) ? .0001 : len;

            double f = force_multiplier * (desiredLen - len) / len;

            f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

            // the actual movement distance 'dx' is the force multiplied by the
            // distance to go.
            double dx = f * vx;
            double dy = f * vy;
            SpringVertexData v1D, v2D;
            v1D = getSpringData(v1);
            v2D = getSpringData(v2);

            sed.f = f;

            v1D.edgedx += dx;
            v1D.edgedy += dy;
            v2D.edgedx += -dx;
            v2D.edgedy += -dy;
        }
    } catch (ConcurrentModificationException cme) {
        relaxEdges();
    }
}

From source file:grafix.telas.MolduraAreaDados.java

private Point2D converterPontoNoPlotParaMoldura_EixoLog(final Point2D pontoPlot) {
    XYPlot plot = getPlot();/*  w ww .  j  av a  2s .  c o m*/
    ValueAxis vAxis = plot.getRangeAxis();
    ValueAxis dAxis = plot.getDomainAxis();
    double dX = dAxis.getUpperBound() - dAxis.getLowerBound();
    double dYlog = Math.log10(vAxis.getUpperBound()) - Math.log10(vAxis.getLowerBound());
    double proporcaoX = this.getWidth() / dX;
    double fracaoX = pontoPlot.getX() - dAxis.getLowerBound();
    double fracaoYlog = Math.log10(pontoPlot.getY()) - Math.log10(vAxis.getLowerBound());
    double coefYlog = fracaoYlog / dYlog;
    return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (coefYlog * this.getHeight()));
}

From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java

/**
 * Find way-points in a rectangular area defined by the given
 * {@link GeoPosition}s/*from w w w .  jav a  2 s .co  m*/
 * 
 * @param topLeft the top left position
 * @param bottomRight the bottom right position
 * @param worldRect the bounding box in world pixel coordinates
 * @param converter the pixel converter
 * @param zoom the zoom level
 * 
 * @return the way-points in the area
 */
public Set<W> findWaypoints(GeoPosition topLeft, GeoPosition bottomRight, final Rectangle worldRect,
        final PixelConverter converter, final int zoom) {
    BoundingBox searchBox;
    try {
        searchBox = createSearchBB(topLeft, bottomRight);
        final BoundingBox verifyBox = searchBox;

        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox second) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);
                    int dx = (int) wpPixel.getX();
                    int dy = (int) wpPixel.getY();

                    worldRect.translate(-dx, -dy);
                    try {
                        Area area = wp.getMarker().getArea(zoom);
                        if (area != null) {
                            return area.containedIn(worldRect);
                        } else {
                            // something that has not been painted yet may
                            // not be selected
                            return false;
                        }
                    } finally {
                        worldRect.translate(dx, dy);
                    }
                } catch (IllegalGeoPositionException e) {
                    log.warn("Could not convert waypoint position to pixel", e);
                    // fall back to simple method
                    return verifyBox.covers(wp.getBoundingBox());
                }
            }

        });

        if (wps == null) {
            return new HashSet<W>();
        } else {
            return wps;
        }
    } catch (IllegalGeoPositionException e) {
        return new HashSet<W>();
    }
}

From source file:org.geopublishing.atlasViewer.swing.ClickInfoDialog.java

/**
 * Update with info-dialog with the new {@link ObjectSelectionEvent}
 *//*from   ww w . ja v  a2 s .c o  m*/
public void setSelectionEvent(final ObjectSelectionEvent<?> objectSelectionEvent) {

    clickInfoPanel.setSelectionEvent(objectSelectionEvent);

    XMapPane source = objectSelectionEvent.getSource();

    // Set the title of the dialog to the translated title the layer
    try {
        String title = objectSelectionEvent.getSourceLayer().getTitle();
        if (atlasConfig != null) {
            setTitle(atlasConfig.getDataPool().get(title).getTitle().toString());
        } else {
            title = StringUtils.right(title, 25);
            setTitle(title);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    XMapPane mapPane = objectSelectionEvent.getSource();
    // If it is a feature, let it blink for a moment
    if (source instanceof XMapPane && objectSelectionEvent instanceof FeatureSelectedEvent) {

        mapPane.blink(((FeatureSelectedEvent) objectSelectionEvent).getSelectionResult());
    } else {
        // Create a fake Feature and let it blink a moment
        final GridCoverageValueSelectedEvent gridSelection = (GridCoverageValueSelectedEvent) objectSelectionEvent;

        // TODO Help Martin, warum kann ich kein feake Feature mit correctem
        // CRS erstellen?
        Point2D selectionPoint = gridSelection.getSelectionPoint();

        CoordinateReferenceSystem crs = mapPane.getMapContext().getCoordinateReferenceSystem();

        SimpleFeatureType fakeFeatureType = FeatureUtil.createFeatureType(Point.class, crs);

        SimpleFeature fakeFeature = FeatureUtil.createFeatureInstance(fakeFeatureType, true,
                "fake raster selection",
                new DirectPosition2D(crs, selectionPoint.getX(), selectionPoint.getY()));

        System.out.println("crs = " + fakeFeature.getFeatureType().getCoordinateReferenceSystem());

        mapPane.blink(fakeFeature);
    }
}

From source file:util.ModSpringLayout2.java

protected void calculateRepulsion() {
    try {// w  w  w . j  av  a2  s  .  c om
        for (V v : getGraph().getVertices()) {
            if (isLocked(v))
                continue;

            SpringVertexData svd = getSpringData(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 distance = vx * vx + vy * vy;
                double distanceSq = p.distanceSq(p2);
                if (distanceSq == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distanceSq < repulsion_range) {// * repulsion_range) {
                    double factor = 1;
                    dx += factor * vx / distanceSq;//Math.pow(distance, 2);
                    dy += factor * vy / distanceSq;//Math.pow(distance, 2);
                }
            }
            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.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

private PixelPos getProductCenter(final Product product) {
    final GeoCoding geoCoding = product.getSceneGeoCoding();
    PixelPos centerPos = null;/*from w  w  w . j a v a 2  s . c  om*/
    if (geoCoding != null) {
        final float pixelX = (float) Math.floor(0.5f * product.getSceneRasterWidth()) + 0.5f;
        final float pixelY = (float) Math.floor(0.5f * product.getSceneRasterHeight()) + 0.5f;
        final GeoPos geoPos = geoCoding.getGeoPos(new PixelPos(pixelX, pixelY), null);
        final AffineTransform transform = layerCanvas.getViewport().getModelToViewTransform();
        final Point2D point2D = transform.transform(new Point2D.Double(geoPos.getLon(), geoPos.getLat()), null);
        centerPos = new PixelPos((float) point2D.getX(), (float) point2D.getY());
    }
    return centerPos;
}

From source file:org.opensha.commons.data.function.EvenlyDiscretizedFunc.java

/** Returns the index of this DataPoint based on it's x any y value
 *  both the x-value and y-values in list should match with that of point
 * returns -1 if there is no such value in the list
 * *//*ww w . j  av a2 s.  c  om*/
public int getIndex(Point2D point) {
    int index = getXIndex(point.getX());
    if (index < 0)
        return -1;
    double y = this.getY(index);
    if (y != point.getY())
        return -1;
    return index;
}

From source file:grafix.telas.MolduraAreaDados.java

private Point2D converterPontoNoPlotParaMoldura_EixoLinear(final Point2D pontoPlot) {
    XYPlot plot = getPlot();/*from   www  .jav  a  2  s .co  m*/
    ValueAxis vAxis = plot.getRangeAxis();
    ValueAxis dAxis = plot.getDomainAxis();
    double dX = dAxis.getUpperBound() - dAxis.getLowerBound();
    double dY = vAxis.getUpperBound() - vAxis.getLowerBound();
    double proporcaoX = this.getWidth() / dX;
    double proporcaoY = this.getHeight() / dY;
    double fracaoX = pontoPlot.getX() - dAxis.getLowerBound();
    double fracaoY = pontoPlot.getY() - vAxis.getLowerBound();
    return new Point2D.Double(fracaoX * proporcaoX, this.getHeight() - (fracaoY * proporcaoY));
}

From source file:org.geoserver.wms.map.QuickTileCache.java

/**
 * Given a tiled request, builds a key that can be used to access the cache looking for a
 * specific meta-tile, and also as a synchronization tool to avoid multiple requests to trigger
 * parallel computation of the same meta-tile
 * //from w ww.  ja  va  2  s .  com
 * @param request
 * @return
 */
public MetaTileKey getMetaTileKey(GetMapRequest request) {
    String mapDefinition = buildMapDefinition(request.getRawKvp());
    ReferencedEnvelope bbox = new ReferencedEnvelope(request.getBbox(), request.getCrs());
    Point2D origin = request.getTilesOrigin();
    if (CRS.getAxisOrder(request.getCrs()) == AxisOrder.NORTH_EAST) {
        try {
            bbox = new ReferencedEnvelope(bbox.getMinY(), bbox.getMaxY(), bbox.getMinX(), bbox.getMaxX(),
                    CRS.decode("EPSG:" + CRS.lookupEpsgCode(request.getCrs(), false)));
            origin = new Point2D.Double(origin.getY(), origin.getX());
        } catch (Exception e) {
            throw new ServiceException("Failed to bring the bbox back in a EN order", e);
        }
    }
    MapKey mapKey = new MapKey(mapDefinition, normalize(bbox.getWidth() / request.getWidth()), origin);
    Point tileCoords = getTileCoordinates(bbox, origin);
    Point metaTileCoords = getMetaTileCoordinates(tileCoords);
    ReferencedEnvelope metaTileEnvelope = getMetaTileEnvelope(bbox, tileCoords, metaTileCoords);
    MetaTileKey key = new MetaTileKey(mapKey, metaTileCoords, metaTileEnvelope);

    // since this will be used for thread synchronization, we have to make
    // sure two thread asking for the same meta tile will get the same key
    // object
    return (MetaTileKey) metaTileKeys.unique(key);
}

From source file:de.fhg.igd.mapviewer.server.ClippingTileProviderDecorator.java

/**
 * Constructor/*from   w  w w  .ja v  a  2 s.  com*/
 * 
 * @param tileProvider the tile provider
 * @param topLeft the top left constraint
 * @param bottomRight the bottom right constraint
 * @param minRange the minimum visible range
 * @param customOverlayColor custom overlay color to use, may be
 *            <code>null</code>
 */
public ClippingTileProviderDecorator(final TileProvider tileProvider, final GeoPosition topLeft,
        final GeoPosition bottomRight, int minRange, Color customOverlayColor) {
    super(tileProvider);

    if (minRange <= 0)
        minRange = 1;

    int zoom = tileProvider.getMinimumZoom();
    boolean tryNextZoom = true;

    // determine valid zoom levels and their tile offsets/ranges
    while (tryNextZoom && zoom <= tileProvider.getMaximumZoom()) {
        try {
            Point2D topLeftPixel = tileProvider.getConverter().geoToPixel(topLeft, zoom);
            Point2D bottomRightPixel = tileProvider.getConverter().geoToPixel(bottomRight, zoom);

            int xMin = ((int) topLeftPixel.getX()) / tileProvider.getTileWidth(zoom);
            int yMin = ((int) topLeftPixel.getY()) / tileProvider.getTileHeight(zoom);
            int xMax = ((int) bottomRightPixel.getX()) / tileProvider.getTileWidth(zoom);
            int yMax = ((int) bottomRightPixel.getY()) / tileProvider.getTileHeight(zoom);

            // check for validity
            if (xMin <= xMax && yMin <= yMax && TileProviderUtils.isValidTile(tileProvider, xMin, yMin, zoom)
                    && TileProviderUtils.isValidTile(tileProvider, xMax, yMax, zoom)) {
                // valid tiles, enter offset and ranges
                xTileOffset.add(xMin);
                xTileRange.add(xMax - xMin + 1);

                yTileOffset.add(yMin);
                yTileRange.add(yMax - yMin + 1);

                this.topLeft.add(new Point((int) topLeftPixel.getX() - xMin * tileProvider.getTileWidth(zoom),
                        (int) topLeftPixel.getY() - yMin * tileProvider.getTileHeight(zoom)));
                this.bottomRight
                        .add(new Point((int) bottomRightPixel.getX() - xMin * tileProvider.getTileWidth(zoom),
                                (int) bottomRightPixel.getY() - yMin * tileProvider.getTileHeight(zoom)));

                if (xMax - xMin + 1 <= minRange || yMax - yMin + 1 <= minRange)
                    tryNextZoom = false; // we reached the max zoom
                else
                    zoom++; // prepare next zoom
            } else {
                // invalid tiles
                tryNextZoom = false;
                zoom--; // previous zoom
            }
        } catch (IllegalGeoPositionException e) {
            // invalid positions or conversion failed
            tryNextZoom = false;
            zoom--; // previous zoom
        }
    }

    if (zoom < getMinimumZoom()) {
        throw new IllegalArgumentException("No zoom levels are valid for clipping"); //$NON-NLS-1$
    } else {
        maxZoom = zoom;

        painter = new ClippingPainter(customOverlayColor);

        log.info("Initialized ClippingTileProviderDecorator with minZoom = " //$NON-NLS-1$
                + tileProvider.getMinimumZoom() + ", maxZoom = " + maxZoom); //$NON-NLS-1$
    }
}