List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:com.wasteofplastic.beaconz.Register.java
public void saveRegister() { // Save the beacons File beaconzFile = new File(getBeaconzPlugin().getDataFolder(), "beaconz.yml"); YamlConfiguration beaconzYml = new YamlConfiguration(); // Backup the beacons file just in case if (beaconzFile.exists()) { File backup = new File(getBeaconzPlugin().getDataFolder(), "beaconz.old"); beaconzFile.renameTo(backup);/*from ww w .j a v a 2 s. c om*/ } int count = 0; for (BeaconObj beacon : beaconRegister.values()) { String owner = "unowned"; if (beacon.getOwnership() != null) { owner = beacon.getOwnership().getName(); } beaconzYml.set("beacon." + count + ".location", beacon.getX() + ":" + beacon.getY() + ":" + beacon.getZ() + ":" + owner); List<String> beaconLinks = new ArrayList<String>(); for (BeaconObj linkedBeacon : beacon.getLinks()) { beaconLinks.add(linkedBeacon.getX() + ":" + linkedBeacon.getZ()); } beaconzYml.set("beacon." + count + ".links", beaconLinks); if (beacon.getId() != null) { beaconzYml.set("beacon." + count + ".id", beacon.getId()); } // Save defense blocks List<String> defenseBlocks = new ArrayList<String>(); for (Point2D point : defenseBlocksInverse.get(beacon)) { defenseBlocks.add((int) point.getX() + ":" + (int) point.getY()); } beaconzYml.set("beacon." + count + ".defenseblocks", defenseBlocks); count++; } try { beaconzYml.save(beaconzFile); } catch (IOException e) { getLogger().severe("Problem saving beacons file!"); e.printStackTrace(); } }
From source file:org.jcurl.core.base.CurveTransformedTest.java
/** * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5) * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a * Point rc(5,1.3) = wc(8,2.5)./* www . j a v a 2s. co m*/ * * @see CurveTransformed#createRc2Wc(AffineTransform, Point2D, Point2D) */ public void testCreateRc2Wc() { final Point2D p0_wc = new Point2D.Double(3, 3.5); final Rock v0_wc = new RockDouble(2, 4.2, 0.3); final AffineTransform at = CurveTransformed.createRc2Wc(null, p0_wc, v0_wc); assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION, at.getType()); assertEquals(1.0, at.getDeterminant()); assertEquals(0.9028605188239303, at.getScaleX()); assertEquals(at.getScaleX(), at.getScaleY()); assertEquals(0.42993358039234775, at.getShearX()); assertEquals(-at.getShearX(), at.getShearY()); assertEquals(p0_wc.getX(), at.getTranslateX()); assertEquals(p0_wc.getY(), at.getTranslateY()); final Point2D rc = new Point2D.Double(5, 1.3); final Point2D wc = at.transform(rc, null); assertEquals("Point2D.Double[8.073216248629704, 2.524050772509371]", wc.toString()); // angle in rc: double ang = Math.atan2(rc.getY(), rc.getX()); assertEquals(14.574216198038739, rad2deg(ang)); // wc rotation: ang = Math.atan2(at.getShearY(), at.getScaleY()); assertEquals(-25.463345061871614, rad2deg(ang)); final double[] d = new double[6]; at.getMatrix(d); ang = Math.atan2(-d[2], d[3]); assertEquals(-25.463345061871614, rad2deg(ang)); // angle in wc: ang = Math.atan2(wc.getY(), wc.getX()); assertEquals(17.36159358309492, rad2deg(ang)); }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
public void paintIcons(Graphics2D g, StateRenderer2D renderer) { for (AssetTrack track : assets.values()) { AssetPosition p = track.getLatest(newestTimestampSelection); if (p == null || hiddenPosTypes.contains(p.getType())) continue; if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Point2D pt = renderer.getScreenPosition(p.getLoc()); //TODO paint icon here Image img = getIcon(p);/*from w ww . ja v a 2 s . c om*/ if (img != null) { g.drawImage(img, (int) (pt.getX() - 8), (int) (pt.getY() - 8), (int) (pt.getX() + 8), (int) (pt.getY() + 8), 0, 0, img.getWidth(null), img.getHeight(null), null); } } }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Transform the tree layout so that it fits nicely in the given image * dimensions/*w ww . j a v a2s . co m*/ * @param treeLayout * the layout to transform * @param imageWidth * the image width * @param imageHeight * the image height */ private void transformTreeLayout(VisualTreeNode treeLayout, int imageWidth, int imageHeight, FontRenderContext frc) { Dimension2D maximalNodeLabelDimension = this.calculateMaximalNodeDimension(treeLayout, frc); double widthBuffer = maximalNodeLabelDimension.getWidth() + BORDER_WHITE_SPACE; double heightBuffer = maximalNodeLabelDimension.getHeight() + BORDER_WHITE_SPACE; // perform rotation to improve the use of space { // center around 0, 0 VisualTreeNode[] mostDistantPair = this.getMostDistantNodePair(treeLayout); Point2D distantPoint1 = mostDistantPair[0].getPosition(); Point2D distantPoint2 = mostDistantPair[1].getPosition(); double xDiff = distantPoint1.getX() - distantPoint2.getX(); double yDiff = distantPoint1.getY() - distantPoint2.getY(); this.translateTreeLayout(treeLayout, (xDiff / 2.0) - distantPoint1.getX(), (yDiff / 2.0) - distantPoint2.getY()); // rotate double thetaRadians = Math.atan2(yDiff, xDiff); if (imageWidth >= imageHeight) { this.rotateTreeLayout(treeLayout, -thetaRadians); } else { this.rotateTreeLayout(treeLayout, (Math.PI / 2.0 - thetaRadians)); } } Rectangle2D boundingRectangle = this.calculateBounds(treeLayout, null); // center around the middle of the display area this.translateTreeLayout(treeLayout, -boundingRectangle.getX(), -boundingRectangle.getY()); // grow the image to fill a larger area double xScale = (imageWidth - widthBuffer) / boundingRectangle.getWidth(); double yScale = (imageHeight - heightBuffer) / boundingRectangle.getHeight(); double smallerScale = Math.min(xScale, yScale); this.scaleTreeLayout(treeLayout, smallerScale); // center around the middle of the display area boundingRectangle = this.calculateBounds(treeLayout, null); this.translateTreeLayout(treeLayout, ((imageWidth - boundingRectangle.getWidth()) / 2.0) - boundingRectangle.getX(), ((imageHeight - boundingRectangle.getHeight()) / 2.0) - boundingRectangle.getY()); }
From source file:org.opennms.features.topology.app.internal.jung.TopoFRLayout.java
protected synchronized void calcPositions(V v) { FRVertexData fvd = getFRData(v);/* ww w . ja v a 2s. c o m*/ if (fvd == null) return; Point2D xyd = transform(v); double deltaLength = fvd.norm(); if (deltaLength <= 0.005) return; double newXDisp = fvd.getX() * percentage() / deltaLength * Math.min(deltaLength, temperature); if (Double.isNaN(newXDisp)) { throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [xdisp]"); } double newYDisp = fvd.getY() * percentage() / deltaLength * Math.min(deltaLength, temperature); xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp); double borderWidth = getSize().getWidth() / 50.0; double newXPos = xyd.getX(); if (newXPos < borderWidth) { newXPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newXPos > (getSize().getWidth() - borderWidth)) { newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0; } double newYPos = xyd.getY(); if (newYPos < borderWidth) { newYPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newYPos > (getSize().getHeight() - borderWidth)) { newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0; } xyd.setLocation(newXPos, newYPos); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
@Override public void mousePressed(MouseEvent e) { trackingChartMouseDrag = true;//from w ww. j ava2 s .c o m if (silenceUpdate) return; Point2D chartCoordinates = getChartCoordinates(e); if (chartCoordinates == null) { return; } double distanceToIntervalLeft = Math.abs(chartCoordinates.getX() - currentValue0); double distanceToIntervalRight = Math.abs(chartCoordinates.getX() - currentValue1); markerIntervalEdgeSelected = (distanceToIntervalLeft < distanceToIntervalRight) ? 0 : 1; moveIntervalEdgeToMousePosition(e); updateDisplayAndParameter(true, true); }
From source file:Polygon2D.java
public void addPoint(Point2D p) { addPoint((float) p.getX(), (float) p.getY()); }
From source file:Polygon2D.java
/** * Tests if a specified {@link Point2D} is inside the boundary of this * <code>Polygon</code>.//from w w w . j a va 2 s . com * @param p a specified <code>Point2D</code> * @return <code>true</code> if this <code>Polygon</code> contains the * specified <code>Point2D</code>; <code>false</code> * otherwise. * @see #contains(double, double) */ public boolean contains(Point2D p) { return contains(p.getX(), p.getY()); }
From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java
private boolean paintHistory(Graphics2D g, StateRenderer2D renderer) { boolean paintedToRender = false; Long endMark = dataDateEnd.getTime(); Long timeMark = dataDateStart.getTime(); CtdData dataPoint;/*from w ww . j av a2 s .c om*/ // double tempMaxTemp, tempMinTemp; // timeMark = ctdHistory.higherKey(timeMark); // if (timeMark != null) { // dataPoint = ctdHistory.get(timeMark); // tempMaxTemp = dataPoint.temperature; // tempMinTemp = dataPoint.temperature; // } // else { // tempMaxTemp = maxTemp; // tempMinTemp = minTemp; // } Color color; Graphics2D gt; Point2D pt; int width = (renderer.getZoom() > 1) ? (int) (5 * renderer.getZoom()) : 5; if (renderer.getZoom() < 0.002) { timeMark = ctdHistory.higherKey(timeMark); if (timeMark != null && timeMark <= endMark) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (isVisibleInRender(pt, renderer)) { gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), 10, 10); gt.dispose(); paintedToRender = true; } } } else { try { timeMark = ctdHistory.higherKey(timeMark); // TODO avoid for in case of being too far from location shown on map for (timeMark = ctdHistory.higherKey(timeMark); timeMark != null && timeMark <= endMark; timeMark = ctdHistory.higherKey(timeMark + 1)) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (!isVisibleInRender(pt, renderer)) { continue; } // check if it is visible gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), width, width); gt.dispose(); paintedToRender = true; } } catch (NullPointerException e) { System.out.println("timeMark"); } } return paintedToRender; }
From source file:com.projity.pm.graphic.pert.PertLayout.java
public void updateBounds() { dependencyGraph.updatePertLevels();// ww w . j a v a 2 s .co m GraphicConfiguration config = GraphicConfiguration.getInstance(); Point2D origin = new Point2D.Double(config.getPertXOffset(), config.getPertYOffset()); Rectangle2D ref = new Rectangle2D.Double(config.getPertXOffset(), config.getPertYOffset(), config.getPertCellWidth(), config.getPertCellHeight()); int row = 0; int col = -1; setEmpty(); for (Iterator i = cache.getIterator(); i.hasNext();) { GraphicNode current = (GraphicNode) i.next(); int currentCol = cache.getPertLevel(current) - 1; if (currentCol <= col) row++; col = currentCol; TexturedShape texturedShape = findShape(current); if (texturedShape == null) continue; double centerX = origin.getX() + ref.getMaxX() * col + ref.getWidth() / 2; double centerY = origin.getY() + ref.getMaxY() * row + ref.getHeight() / 2; //System.out.println(centerX+"/"+centerY); GeneralPath shape = texturedShape.toGeneralPath(ref.getWidth(), ref.getHeight(), centerX - ref.getWidth() / 2, centerY, null); current.setPertShape(shape, centerX, centerY); Rectangle cellBounds = network.scale(shape.getBounds()); if (isEmpty()) bounds.setBounds(cellBounds); else Rectangle.union(bounds, cellBounds, bounds); } fireLayoutChanged(); }