Search in sources :

Example 51 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class TrackSegmentXml method store.

/**
     * Default implementation for storing the contents of a TrackSegment
     *
     * @param o Object to store, of type TrackSegment
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    TrackSegment p = (TrackSegment) o;
    // NOI18N
    Element element = new Element("tracksegment");
    // include attributes
    element.setAttribute("ident", p.getID());
    if (p.getBlockName().length() > 0) {
        element.setAttribute("blockname", p.getBlockName());
    }
    element.setAttribute("connect1name", p.getConnect1Name());
    element.setAttribute("type1", "" + p.getType1());
    element.setAttribute("connect2name", p.getConnect2Name());
    element.setAttribute("type2", "" + p.getType2());
    element.setAttribute("dashed", "" + (p.getDashed() ? "yes" : "no"));
    element.setAttribute("mainline", "" + (p.getMainline() ? "yes" : "no"));
    element.setAttribute("hidden", "" + (p.isHidden() ? "yes" : "no"));
    element.setAttribute("arc", "" + (p.getArc() ? "yes" : "no"));
    if (p.getArc()) {
        element.setAttribute("flip", "" + (p.getFlip() ? "yes" : "no"));
        element.setAttribute("circle", "" + (p.getCircle() ? "yes" : "no"));
        if ((p.getCircle()) && (p.getAngle() != 0.0D)) {
            element.setAttribute("angle", "" + (p.getAngle()));
            element.setAttribute("hideConLines", "" + (p.hideConstructionLines() ? "yes" : "no"));
        }
    }
    if (p.getBezier()) {
        element.setAttribute("bezier", "yes");
    }
    element.setAttribute("class", getClass().getName());
    if (p.getBezier()) {
        // add control points
        Element elementControlpoints = new Element("controlpoints");
        for (int i = 0; i < p.getNumberOfBezierControlPoints(); i++) {
            Element elementControlpoint = new Element("controlpoint");
            elementControlpoint.setAttribute("index", "" + i);
            Point2D pt = p.getBezierControlPoint(i);
            elementControlpoint.setAttribute("x", "" + pt.getX());
            elementControlpoint.setAttribute("y", "" + pt.getY());
            elementControlpoints.addContent(elementControlpoint);
        }
        element.addContent(elementControlpoints);
    }
    return element;
}
Also used : Point2D(java.awt.geom.Point2D) Element(org.jdom2.Element) TrackSegment(jmri.jmrit.display.layoutEditor.TrackSegment)

Example 52 with Point2D

use of java.awt.geom.Point2D in project jdk8u_jdk by JetBrains.

the class StandardGlyphVector method getGlyphMetrics.

public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }
    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(), vb.getMinY() - pt.getY(), vb.getWidth(), vb.getHeight());
    Point2D.Float adv = getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y, vb, GlyphMetrics.STANDARD);
    return gm;
}
Also used : Point2D(java.awt.geom.Point2D) GlyphMetrics(java.awt.font.GlyphMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 53 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class DiscretizedLocationOperator method makeLocationList.

private Set<Point2D> makeLocationList() {
    Set<Point2D> uniquePoints = new HashSet<Point2D>();
    for (int i = 0; i < treeModel.getExternalNodeCount(); i++) {
        NodeRef node = treeModel.getExternalNode(i);
        double[] leafTrait = treeModel.getMultivariateNodeTrait(node, traitName);
        Point2D.Double point = new Point2D.Double(leafTrait[0], leafTrait[1]);
        if (!uniquePoints.contains(point)) {
            uniquePoints.add(point);
            savedPt = point;
        }
    }
    return uniquePoints;
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Point2D(java.awt.geom.Point2D)

Example 54 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class DiscretizedLocationOperator method doOperation.

public double doOperation() {
    NodeRef node;
    if (onlyInternalNodes)
        node = treeModel.getInternalNode(MathUtils.nextInt(treeModel.getInternalNodeCount()));
    else
        node = treeModel.getNode(MathUtils.nextInt(treeModel.getNodeCount()));
    double[] trait = treeModel.getMultivariateNodeTrait(node, traitName);
    Point2D currentPt = new Point2D.Double(trait[0], trait[1]);
    List<WeightedPoint2D> neighbors = nearestNeighborMap.get(currentPt);
    if (neighbors == null)
        throw new RuntimeException("Node location outside allowable values: " + currentPt);
    //        Point2D newPt = neighbors.get(MathUtils.nextInt(disk));
    Point2D newPt = neighbors.get(MathUtils.nextInt(convertFromAutoOptimizeValue(autoOptimize)));
    trait[0] = newPt.getX();
    trait[1] = newPt.getY();
    //        treeModel.setMultivariateTrait(node, traitName, trait);
    recursivelySetTrait(node, trait, null);
    return 0;
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Point2D(java.awt.geom.Point2D)

Example 55 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class DiscretizedLocationOperator method makeNearestNeighborMap.

private Map<Point2D, List<WeightedPoint2D>> makeNearestNeighborMap() {
    Map<Point2D, List<WeightedPoint2D>> map = new HashMap<Point2D, List<WeightedPoint2D>>();
    for (Point2D location : allLocations) {
        List<WeightedPoint2D> weightedNeighbors = new ArrayList<WeightedPoint2D>();
        for (Point2D neighbor : allLocations) {
            double distance = location.distance(neighbor);
            if (distance > 0)
                weightedNeighbors.add(new WeightedPoint2D(neighbor.getX(), neighbor.getY(), distance));
        }
        Collections.sort(weightedNeighbors);
        map.put(location, weightedNeighbors);
    }
    return map;
}
Also used : Point2D(java.awt.geom.Point2D)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5