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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations