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:org.jcurl.model.PathSegmentTest.java

public void testTrafo() throws NoninvertibleTransformException {
    final Point2D x0 = new Point2D.Double(1.5, 2.5);
    // final Point2D x0 = new Point2D.Double(0, 0);
    final Point2D v0 = new Point2D.Double(2, 1);
    // build the trafo
    final AffineTransform rc2wc = new AffineTransform();
    {/* w ww . j a v a  2  s .  co  m*/
        rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / v0.distance(0, 0)), x0.getX(), x0.getY());
        rc2wc.translate(x0.getX(), x0.getY());
    }
    // check some points.
    // wc(x0) -> rc(0,0)
    Point2D tmp = rc2wc.inverseTransform(x0, null);
    assertEquals("", 0, tmp.getX(), 1e-9);
    assertEquals("", 0, tmp.getY(), 1e-9);

    // rc(0,1) -> wc(x0)
    tmp = rc2wc.transform(new Point2D.Double(0, 1), null);
    assertEquals("", x0.getX() + 0.8944271909999, tmp.getX(), 1e-6);
    assertEquals("", x0.getY() + 0.4472135954999, tmp.getY(), 1e-6);
}

From source file:algorithms.quality.ColorDivergenceVariance.java

@Override
public double getQuality(Colormap colormap) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    Iterator<Point2D> ptIt = strategy.getPoints().iterator();

    while (ptIt.hasNext()) {
        Point2D p1 = ptIt.next();

        if (!ptIt.hasNext())
            break;

        Point2D p2 = ptIt.next();

        double dist = p1.distance(p2);

        Color colorA = colormap.getColor(p1.getX(), p1.getY());
        Color colorB = colormap.getColor(p2.getX(), p2.getY());

        // roughly 0-100
        double cdist = MedianDivergenceComputer.colorDiff(colorA, colorB);

        double ratio = cdist / dist;

        stats.addValue(ratio);/*from   w  w w .ja  v  a  2s. c  o  m*/
    }

    return stats.getStandardDeviation();
}

From source file:com.projity.pm.graphic.xbs.XbsLayout.java

protected void updateBounds(int level, Point2D origin, Rectangle2D ref) {//cache in current version isn't a tree
    double y = origin.getY() + ref.getHeight() / 2 + ref.getMaxY() * (level - 1);
    Point2D childCenter, center;/*from  w  w w .j a  v  a2 s .com*/
    double x0, x1;
    GraphicNode node, child;
    boolean hasChild;
    for (ListIterator i = cache.getIterator(); i.hasNext();) {
        node = (GraphicNode) i.next();
        if (node.getLevel() == level) {
            x0 = -1;
            x1 = -1;
            hasChild = false;
            while (i.hasNext()) {
                child = (GraphicNode) i.next();
                if (child.getLevel() <= level) {
                    i.previous();
                    break;
                } else if (child.getLevel() == level + 1) {
                    hasChild = true;
                    childCenter = child.getXbsCenter();
                    if (x0 == -1 || childCenter.getX() < x0)
                        x0 = childCenter.getX();
                    if (x1 == -1 || childCenter.getX() > x1)
                        x1 = childCenter.getX();
                    dependencies.add(new GraphicDependency(node, child, null));
                }
            }
            if (hasChild)
                setShape(node, ref, (x0 + x1) / 2, y);
        }

    }
}

From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.operator.path.construction.CurveToReplicateFinalPoint.java

@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
    try {/*  w w  w . java  2 s.c  o m*/
        PDFPage pdfPage = (PDFPage) context;

        COSNumber x1 = (COSNumber) operands.get(0);
        COSNumber y1 = (COSNumber) operands.get(1);
        COSNumber x3 = (COSNumber) operands.get(2);
        COSNumber y3 = (COSNumber) operands.get(3);

        Point2D p1 = transform(x1.doubleValue(), y1.doubleValue());
        Point2D p3 = transform(x3.doubleValue(), y3.doubleValue());

        pdfPage.getCurrentPath().curveTo((float) p1.getX(), (float) p1.getY(), (float) p3.getX(),
                (float) p3.getY(), (float) p3.getX(), (float) p3.getY());

        if (log.isTraceEnabled()) {
            log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x3:"
                    + p3.getX() + ",y3:" + p3.getY());
        }
    } catch (Exception e) {
        log.warn("Error processing operator 'y'.", e);
    }
}

From source file:ddf.catalog.transformer.input.pdf.GeoPdfParser.java

/**
 * Convert a Point2d into WKT Lat/Lon//from w w w  . java2s .  co  m
 *
 * @param point2D
 * @return a String representation of a WKT Lat/Lon pair
 */
private String point2dToWkt(Point2D point2D) {
    return point2D.getX() + " " + point2D.getY();
}

From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java

/**
 * Returns a regular <code>num_sides</code>-sided 
 * <code>Polygon</code> whose bounding 
 * box's width and height are defined by this instance's size and
 * aspect ratio functions for this vertex.
 * @param num_sides the number of sides of the polygon; must be >= 3.
 *//*from   w  w w. ja  va2  s. c  o  m*/
public Shape getRegularPolygon(V v, int num_sides) {
    if (num_sides < 3)
        throw new IllegalArgumentException("Number of sides must be >= 3");
    Rectangle2D frame = getRectangle(v);
    float width = (float) frame.getWidth();
    float height = (float) frame.getHeight();

    // generate coordinates
    double angle = 0;
    thePolygon.reset();
    thePolygon.moveTo(0, 0);
    thePolygon.lineTo(width, 0);
    double theta = (2 * Math.PI) / num_sides;
    for (int i = 2; i < num_sides; i++) {
        angle -= theta;
        float delta_x = (float) (width * Math.cos(angle));
        float delta_y = (float) (width * Math.sin(angle));
        Point2D prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    }
    thePolygon.closePath();

    // scale polygon to be right size, translate to center at (0,0)
    Rectangle2D r = thePolygon.getBounds2D();
    double scale_x = width / r.getWidth();
    double scale_y = height / r.getHeight();
    float translationX = (float) (r.getMinX() + r.getWidth() / 2);
    float translationY = (float) (r.getMinY() + r.getHeight() / 2);

    AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y);
    at.translate(-translationX, -translationY);

    Shape shape = at.createTransformedShape(thePolygon);
    return shape;
}

From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java

/**
 * Returns a regular <code>Polygon</code> of <code>num_points</code>
 * points whose bounding //from w  w  w  .ja v  a2  s  . c  om
 * box's width and height are defined by this instance's size and
 * aspect ratio functions for this vertex.
 * @param num_points the number of points of the polygon; must be >= 5.
 */
public Shape getRegularStar(V v, int num_points) {
    if (num_points < 5)
        throw new IllegalArgumentException("Number of sides must be >= 5");
    Rectangle2D frame = getRectangle(v);
    float width = (float) frame.getWidth();
    float height = (float) frame.getHeight();

    // generate coordinates
    double theta = (2 * Math.PI) / num_points;
    double angle = -theta / 2;
    thePolygon.reset();
    thePolygon.moveTo(0, 0);
    float delta_x = width * (float) Math.cos(angle);
    float delta_y = width * (float) Math.sin(angle);
    Point2D prev = thePolygon.getCurrentPoint();
    thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    for (int i = 1; i < num_points; i++) {
        angle += theta;
        delta_x = width * (float) Math.cos(angle);
        delta_y = width * (float) Math.sin(angle);
        prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
        angle -= theta * 2;
        delta_x = width * (float) Math.cos(angle);
        delta_y = width * (float) Math.sin(angle);
        prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    }
    thePolygon.closePath();

    // scale polygon to be right size, translate to center at (0,0)
    Rectangle2D r = thePolygon.getBounds2D();
    double scale_x = width / r.getWidth();
    double scale_y = height / r.getHeight();

    float translationX = (float) (r.getMinX() + r.getWidth() / 2);
    float translationY = (float) (r.getMinY() + r.getHeight() / 2);

    AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y);
    at.translate(-translationX, -translationY);

    Shape shape = at.createTransformedShape(thePolygon);
    return shape;
}

From source file:net.roboconf.doc.generator.internal.transformers.HierarchicalTransformer.java

/**
 * Constructor./*from w  w  w.  j a va 2 s.c om*/
 * @param component the component whose hierarchy must be displayed
 * @param ancestors its ancestors
 * @param children its children
 * @param maxPerLine the maximum number of vertices per line
 */
public HierarchicalTransformer(Component component, Collection<AbstractType> ancestors,
        Collection<AbstractType> children, int maxPerLine) {

    // Store fields
    this.component = component;
    this.maxPerLine = maxPerLine;
    this.typeToLocation = new HashMap<AbstractType, Point2D>();
    this.aloneOnRow = new ArrayList<AbstractType>();

    // Compute the effective horizontal margin for this graph
    this.hMargin = computeHMargin(component);
    for (AbstractType t : ancestors)
        this.hMargin = Math.max(this.hMargin, computeHMargin(t));

    for (AbstractType t : children)
        this.hMargin = Math.max(this.hMargin, computeHMargin(t));

    // Builds the graph
    this.graph = new DirectedOrderedSparseMultigraph<AbstractType, String>();
    int cpt = 1;

    for (AbstractType t : ancestors)
        this.graph.addVertex(t);

    this.graph.addVertex(component);
    for (AbstractType t : ancestors)
        this.graph.addEdge("can contain" + cpt++, t, component);

    for (AbstractType t : children) {
        this.graph.addVertex(t);
        this.graph.addEdge("can contain" + cpt++, component, t);
    }

    // In these first steps, vertices are aligned on the left
    if (!ancestors.isEmpty()) {
        dealWithOthers(ancestors);
        this.currentHeigth += V_PADDING;
    }

    dealWithMainComponent();

    if (!children.isEmpty()) {
        this.currentHeigth += V_PADDING;
        dealWithOthers(children);
    }

    this.currentHeigth += V_MARGIN;

    // Center alone vertices
    for (AbstractType t : this.aloneOnRow) {
        int width = GraphUtils.computeShapeWidth(t);
        int newX = (this.maxRowWidth - width) / 2;

        if (newX > this.hMargin) {
            Point2D p = transform(t);
            p.setLocation(newX, p.getY());
        }
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java

@Override
public void draw(Graphics2D g2, Rectangle2D area) {

    area = trimMargin(area);//from  ww w .  j a v a2s .c  om
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (isLineVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());
        Shape aLine = ShapeUtilities.createTranslatedShape(getLine(), getShapeAnchor(), location.getX(),
                location.getY());
        g2.setPaint(getLinePaint());
        g2.setStroke(getLineStroke());
        g2.draw(aLine);
    }

    if (isShapeVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());

        Shape s = ShapeUtilities.createTranslatedShape(getShape(), getShapeAnchor(), location.getX(),
                location.getY());
        if (isShapeFilled()) {
            Paint p = getFillPaint();
            if (p instanceof GradientPaint) {
                GradientPaint gp = (GradientPaint) getFillPaint();
                p = getFillPaintTransformer().transform(gp, s);
            } else if (p instanceof LinearGradientPaint) {
                LinearGradientPaint gradient = (LinearGradientPaint) p;
                Rectangle2D bounds = s.getBounds2D();
                p = getTranslatedLinearGradientPaint(gradient,
                        new Point2D.Double(bounds.getMinX(), bounds.getMinY()),
                        new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), false);
            }
            g2.setPaint(p);
            g2.fill(s);
        }
        if (isShapeOutlineVisible()) {
            g2.setPaint(getOutlinePaint());
            g2.setStroke(getOutlineStroke());
            g2.draw(s);
        }
    }

}

From source file:lu.lippmann.cdb.graph.GraphUtil.java

/**
 * /*from  ww w .  ja v  a2  s  .c o  m*/
 * @param layout
 * @return
 */
public static Point2D getCenter(Set<CNode> picked, Layout<CNode, CEdge> layout) {
    double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE,
            maxY = Integer.MIN_VALUE;

    for (final CNode n : picked) {
        final Point2D point = layout.transform(n); // center of the node
        if (point.getX() < minX) {
            minX = point.getX();
        }
        if (point.getX() > maxX) {
            maxX = point.getX();
        }
        if (point.getY() < minY) {
            minY = point.getY();
        }
        if (point.getY() > maxY) {
            maxY = point.getY();
        }
    }

    final int graphWidth = (int) (maxX - minX);
    final int graphHeigth = (int) (maxY - minY);

    return new Point2D.Double(minX + graphWidth / 2.0f, minY + graphHeigth / 2.0f);
}