Java Code Examples for java.awt.geom.Point2D#getX()
The following examples show how to use
java.awt.geom.Point2D#getX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayoutPathImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Return the location of the point passed in result as mapped to the * line indicated by index. If doExtend is true, extend the * x value without pinning to the ends of the line. * this assumes that index is valid and references a line that has * non-zero length. */ private void calcoffset(int index, boolean doExtend, Point2D result) { double bx = data[index-3]; double by = data[index-2]; double px = result.getX() - bx; double py = result.getY() - by; double dx = data[index] - bx; double dy = data[index+1] - by; double l = data[index+2] - data[index - 1]; // rx = A dot B / |B| // ry = A dot invB / |B| double rx = (px * dx + py * dy) / l; double ry = (px * -dy + py * dx) / l; if (!doExtend) { if (rx < 0) rx = 0; else if (rx > l) rx = l; } rx += data[index-1]; result.setLocation(rx, ry); }
Example 2
Source File: MaxFeretDiameterPlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private Roi createDiametersRoi(PointPair2D pointPair, Calibration calib) { if (pointPair == null) { return null; } Point2D p1 = calibToPixel(pointPair.p1, calib); Point2D p2 = calibToPixel(pointPair.p2, calib); // Convert to Polyline ROI float[] x = new float[2]; float[] y = new float[2]; x[0] = (float) p1.getX(); y[0] = (float) p1.getY(); x[1] = (float) p2.getX(); y[1] = (float) p2.getY(); return new PolygonRoi(x, y, 2, Roi.POLYLINE); }
Example 3
Source File: LabeledLocationFigure.java From openAGV with Apache License 2.0 | 6 votes |
@Override public void scaleModel(EventObject event) { Origin origin = get(FigureConstants.ORIGIN); if (origin != null) { LocationFigure lf = getPresentationFigure(); Point2D exact = origin.calculatePixelPositionExactly(lf.getModel().getPropertyLayoutPositionX(), lf.getModel().getPropertyLayoutPositionY()); Point2D.Double anchor = new Point2D.Double(exact.getX(), exact.getY()); setBounds(anchor, anchor); } invalidate(); // Auch das Label aktualisieren fireFigureChanged(); }
Example 4
Source File: clsUtilityCPOF.java From mil-sym-java with Apache License 2.0 | 6 votes |
/** * * @param ptLatLong * @param converter * @return */ private static POINT2 PointLatLongToPixels(POINT2 ptLatLong, IPointConversion converter) { POINT2 pt = new POINT2(); try { double x = ptLatLong.x; double y = ptLatLong.y; //Point2D pt2dGeo=new Point2D.Double(x,y); Point2D ptPixels = converter.GeoToPixels(new Point2D.Double(x, y)); pt.x = ptPixels.getX(); pt.y = ptPixels.getY(); pt.style = ptLatLong.style; } catch (Exception exc) { ErrorLogger.LogException(_className, "PointLatLongToPixels", new RendererException("Failed inside PointLatLongToPixels", exc)); } return pt; }
Example 5
Source File: PerspectiveTransform.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
/** * Transforms the specified ptSrc and stores the result in ptDst. * If ptDst is null, a new Point2D object will be allocated before * storing. In either case, ptDst containing the transformed point * is returned for convenience. * Note that ptSrc and ptDst can the same. In this case, the input * point will be overwritten with the transformed point. * * @param ptSrc The array containing the source point objects. * @param ptDst The array where the transform point objects are returned. * @throws IllegalArgumentException if ptSrc is null */ public Point2D transform(Point2D ptSrc, Point2D ptDst) { if (ptSrc == null) { throw new IllegalArgumentException(JaiI18N.getString("Generic0")); } if (ptDst == null) { if (ptSrc instanceof Point2D.Double) { ptDst = new Point2D.Double(); } else { ptDst = new Point2D.Float(); } } double x = ptSrc.getX(); double y = ptSrc.getY(); double w = m20 * x + m21 * y + m22; ptDst.setLocation((m00 * x + m01 * y + m02) / w, (m10 * x + m11 * y + m12) / w); return ptDst; }
Example 6
Source File: PShapeSVG.java From CPE552-Java with GNU General Public License v3.0 | 6 votes |
public LinearGradient(PShapeSVG parent, XML properties) { super(parent, properties); this.x1 = getFloatWithUnit(properties, "x1", svgWidth); this.y1 = getFloatWithUnit(properties, "y1", svgHeight); this.x2 = getFloatWithUnit(properties, "x2", svgWidth); this.y2 = getFloatWithUnit(properties, "y2", svgHeight); String transformStr = properties.getString("gradientTransform"); if (transformStr != null) { float t[] = parseTransform(transformStr).get(null); this.transform = new AffineTransform(t[0], t[3], t[1], t[4], t[2], t[5]); Point2D t1 = transform.transform(new Point2D.Float(x1, y1), null); Point2D t2 = transform.transform(new Point2D.Float(x2, y2), null); this.x1 = (float) t1.getX(); this.y1 = (float) t1.getY(); this.x2 = (float) t2.getX(); this.y2 = (float) t2.getY(); } }
Example 7
Source File: Polyline.java From workcraft with MIT License | 6 votes |
private Rectangle2D getSegmentBoundsWithThreshold(Line2D segment) { Point2D pt1 = segment.getP1(); Point2D pt2 = segment.getP2(); Rectangle2D bb = new Rectangle2D.Double(pt1.getX(), pt1.getY(), 0, 0); bb.add(pt2); Point2D lineVec = new Point2D.Double(pt2.getX() - pt1.getX(), pt2.getY() - pt1.getY()); double mag = lineVec.distance(0, 0); if (mag != 0) { lineVec.setLocation(lineVec.getY() * VisualConnection.HIT_THRESHOLD / mag, -lineVec.getX() * VisualConnection.HIT_THRESHOLD / mag); bb.add(pt1.getX() + lineVec.getX(), pt1.getY() + lineVec.getY()); bb.add(pt2.getX() + lineVec.getX(), pt2.getY() + lineVec.getY()); bb.add(pt1.getX() - lineVec.getX(), pt1.getY() - lineVec.getY()); bb.add(pt2.getX() - lineVec.getX(), pt2.getY() - lineVec.getY()); } return bb; }
Example 8
Source File: Chart_14_CategoryPlot_s.java From coming with MIT License | 6 votes |
/** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. * @param useAnchor a flag that controls whether or not the source point * is used for the zoom anchor. * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // perform the zoom on each range axis for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = (ValueAxis) this.rangeAxes.get(i); if (rangeAxis != null) { if (useAnchor) { // get the relevant source coordinate given the plot // orientation double sourceY = source.getY(); if (this.orientation == PlotOrientation.HORIZONTAL) { sourceY = source.getX(); } double anchorY = rangeAxis.java2DToValue(sourceY, info.getDataArea(), getRangeAxisEdge()); rangeAxis.resizeRange(factor, anchorY); } else { rangeAxis.resizeRange(factor); } } } }
Example 9
Source File: CategoryCrosshairState.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Updates only the crosshair row and column keys (this is for the case * where the range crosshair does NOT lock onto the nearest data value). * * @param rowKey the row key. * @param columnKey the column key. * @param datasetIndex the dataset axis index. * @param transX the translated x-value. * @param orientation the plot orientation. */ public void updateCrosshairX(Comparable rowKey, Comparable columnKey, int datasetIndex, double transX, PlotOrientation orientation) { Point2D anchor = getAnchor(); if (anchor != null) { double anchorX = anchor.getX(); if (orientation == PlotOrientation.HORIZONTAL) { anchorX = anchor.getY(); } double d = Math.abs(transX - anchorX); if (d < getCrosshairDistance()) { this.rowKey = rowKey; this.columnKey = columnKey; setDatasetIndex(datasetIndex); setCrosshairDistance(d); } } }
Example 10
Source File: LayoutPathImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public boolean pointToPath(Point2D pt, Point2D result) { result.setLocation(pt); if (tx != null) { try { tx.inverseTransform(pt, result); } catch (NoninvertibleTransformException ex) { } } return result.getX() > 0; }
Example 11
Source File: WalkOutside.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Optimizes a path by removing unnecessary locations. * * @param initialPath the initial path to optimize. * @return optimized path. */ private List<Point2D> optimizePath(List<Point2D> initialPath) { List<Point2D> optimizedPath = new ArrayList<Point2D>(initialPath); Iterator<Point2D> i = optimizedPath.iterator(); while (i.hasNext()) { Point2D loc = i.next(); int locIndex = optimizedPath.indexOf(loc); if ((locIndex > 0) && (locIndex < (optimizedPath.size() - 1))) { Point2D prevLoc = optimizedPath.get(locIndex - 1); Point2D nextLoc = optimizedPath.get(locIndex + 1); // If clear path between previous and next location, // remove this location from path. Line2D line = new Line2D.Double(prevLoc.getX(), prevLoc.getY(), nextLoc.getX(), nextLoc.getY()); if (person != null) { if (LocalAreaUtil.checkLinePathCollision(line, person.getCoordinates(), true)) { i.remove(); } } else if (robot != null) { if (LocalAreaUtil.checkLinePathCollision(line, robot.getCoordinates(), true)) { i.remove(); } } } } return optimizedPath; }
Example 12
Source File: GradientPaint.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a simple acyclic <code>GradientPaint</code> object. * @param pt1 the first specified <code>Point</code> in user space * @param color1 <code>Color</code> at the first specified * <code>Point</code> * @param pt2 the second specified <code>Point</code> in user space * @param color2 <code>Color</code> at the second specified * <code>Point</code> * @throws NullPointerException if either one of colors or points * is null */ public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2) { if ((color1 == null) || (color2 == null) || (pt1 == null) || (pt2 == null)) { throw new NullPointerException("Colors and points should be non-null"); } p1 = new Point2D.Float((float)pt1.getX(), (float)pt1.getY()); p2 = new Point2D.Float((float)pt2.getX(), (float)pt2.getY()); this.color1 = color1; this.color2 = color2; }
Example 13
Source File: SVGEmitter.java From maze-harvester with GNU General Public License v3.0 | 5 votes |
void computeBounds(Rectangle2D bbMazeCoords) { // Scale the bounding box up to add borders. Rectangle2D scaledBBox = bbMazeCoords; // Rotate the paper if the maze doesn't have the same aspect ratio. boolean paperIsTall = paperSizePixels.getX() < paperSizePixels.getY(); boolean mazeIsTall = scaledBBox.getWidth() < scaledBBox.getHeight(); if (paperIsTall != mazeIsTall) { this.paperSizePixels = new Point2D.Double(paperSizePixels.getY(), paperSizePixels.getX()); } // Account for the margins. double marginPixels = paperOptions.getMarginInches() * pixelsPerInch; Point2D availablePaperPixels = new Point2D.Double( paperSizePixels.getX() - marginPixels, paperSizePixels.getY() - marginPixels); scalePixelsPerRoom = Math.min( availablePaperPixels.getX() / scaledBBox.getWidth(), availablePaperPixels.getY() / scaledBBox.getHeight()); double marginRooms = marginPixels / scalePixelsPerRoom; Point2D paperRooms = new Point2D.Double( paperSizePixels.getX() / scalePixelsPerRoom, paperSizePixels.getY() / scalePixelsPerRoom); pageOffsetRooms = new Point2D.Double( scaledBBox.getX() - 0.5*(paperRooms.getX()-scaledBBox.getWidth()), scaledBBox.getY() - 0.5*(paperRooms.getY()-scaledBBox.getHeight())); }
Example 14
Source File: EffectsPanel.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
private void initDropShadowPanel(AreaEffects effects) { boolean enable = false; Color color = BLACK; int distance = 10; double angle = 0.7; double spread = 10; if (effects != null) { var effect = effects.getDropShadow(); if (effect != null) { enable = true; color = effect.getBrushColor(); Point2D offset = effect.getOffset(); double x = offset.getX(); double y = offset.getY(); distance = (int) Math.sqrt(x * x + y * y); angle = Math.atan2(y, x); spread = effect.getEffectWidth(); } } if (dropShadowPanel == null) { // first initialization dropShadowPanel = new DropShadowPanel( enable, color, distance, angle, spread); } else { dropShadowPanel.setTabEnabled(enable); dropShadowPanel.setBrushWidth(spread); dropShadowPanel.setColor(color, false); dropShadowPanel.setAngle(angle); dropShadowPanel.setDistance(distance); } }
Example 15
Source File: StackedBarRenderer3D.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Creates an array of shapes representing the six sides of a block in a * vertical stack. * * @param x0 left edge of bar (in Java2D space). * @param width the width of the bar (in Java2D units). * @param y0 the base of the block (in Java2D space). * @param y1 the top of the block (in Java2D space). * @param inverted a flag indicating whether or not the block is inverted * (this changes the order of the faces of the block). * * @return The sides of the block. */ private Shape[] createVerticalBlock(double x0, double width, double y0, double y1, boolean inverted) { Shape[] result = new Shape[6]; Point2D p00 = new Point2D.Double(x0, y0); Point2D p01 = new Point2D.Double(x0 + width, y0); Point2D p02 = new Point2D.Double(p01.getX() + getXOffset(), p01.getY() - getYOffset()); Point2D p03 = new Point2D.Double(p00.getX() + getXOffset(), p00.getY() - getYOffset()); Point2D p0 = new Point2D.Double(x0, y1); Point2D p1 = new Point2D.Double(x0 + width, y1); Point2D p2 = new Point2D.Double(p1.getX() + getXOffset(), p1.getY() - getYOffset()); Point2D p3 = new Point2D.Double(p0.getX() + getXOffset(), p0.getY() - getYOffset()); GeneralPath right = new GeneralPath(); right.moveTo((float) p1.getX(), (float) p1.getY()); right.lineTo((float) p01.getX(), (float) p01.getY()); right.lineTo((float) p02.getX(), (float) p02.getY()); right.lineTo((float) p2.getX(), (float) p2.getY()); right.closePath(); GeneralPath left = new GeneralPath(); left.moveTo((float) p0.getX(), (float) p0.getY()); left.lineTo((float) p00.getX(), (float) p00.getY()); left.lineTo((float) p03.getX(), (float) p03.getY()); left.lineTo((float) p3.getX(), (float) p3.getY()); left.closePath(); GeneralPath back = new GeneralPath(); back.moveTo((float) p2.getX(), (float) p2.getY()); back.lineTo((float) p02.getX(), (float) p02.getY()); back.lineTo((float) p03.getX(), (float) p03.getY()); back.lineTo((float) p3.getX(), (float) p3.getY()); back.closePath(); GeneralPath front = new GeneralPath(); front.moveTo((float) p0.getX(), (float) p0.getY()); front.lineTo((float) p1.getX(), (float) p1.getY()); front.lineTo((float) p01.getX(), (float) p01.getY()); front.lineTo((float) p00.getX(), (float) p00.getY()); front.closePath(); GeneralPath top = new GeneralPath(); top.moveTo((float) p0.getX(), (float) p0.getY()); top.lineTo((float) p1.getX(), (float) p1.getY()); top.lineTo((float) p2.getX(), (float) p2.getY()); top.lineTo((float) p3.getX(), (float) p3.getY()); top.closePath(); GeneralPath bottom = new GeneralPath(); bottom.moveTo((float) p00.getX(), (float) p00.getY()); bottom.lineTo((float) p01.getX(), (float) p01.getY()); bottom.lineTo((float) p02.getX(), (float) p02.getY()); bottom.lineTo((float) p03.getX(), (float) p03.getY()); bottom.closePath(); result[0] = bottom; result[1] = back; result[2] = left; result[3] = right; result[4] = top; result[5] = front; if (inverted) { result[0] = top; result[4] = bottom; } return result; }
Example 16
Source File: PanTool.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public static void pan(GeometryEditPanel panel, Point2D source, Point2D destination ) { double xDisplacement = destination.getX() - source.getX(); double yDisplacement = destination.getY() - source.getY(); panel.zoomPan(xDisplacement, yDisplacement); }
Example 17
Source File: CrosshairOverlay.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 18
Source File: Line.java From Algorithms with MIT License | 4 votes |
public Line(Point2D p1, Point2D p2) { this(p1.getX(), p1.getY(), p2.getX(), p2.getY()); }
Example 19
Source File: DialPointer.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws the pointer. * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(Color.blue); g2.setStroke(new BasicStroke(1.0f)); Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.widthRadius, this.widthRadius); double value = plot.getValue(this.datasetIndex); DialScale scale = plot.getScaleForDataset(this.datasetIndex); double angle = scale.valueToAngle(value); Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN); Point2D pt1 = arc1.getEndPoint(); Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN); Point2D pt2 = arc2.getStartPoint(); Point2D pt3 = arc2.getEndPoint(); Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN); Point2D pt4 = arc3.getStartPoint(); GeneralPath gp = new GeneralPath(); gp.moveTo((float) pt1.getX(), (float) pt1.getY()); gp.lineTo((float) pt2.getX(), (float) pt2.getY()); gp.lineTo((float) pt4.getX(), (float) pt4.getY()); gp.lineTo((float) pt3.getX(), (float) pt3.getY()); gp.closePath(); g2.setPaint(this.fillPaint); g2.fill(gp); g2.setPaint(this.outlinePaint); Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY()); g2.draw(line); line.setLine(pt2, pt3); g2.draw(line); line.setLine(pt3, pt1); g2.draw(line); line.setLine(pt2, pt1); g2.draw(line); line.setLine(pt2, pt4); g2.draw(line); line.setLine(pt3, pt4); g2.draw(line); }
Example 20
Source File: XYBoxAndWhiskerRenderer.java From buffer_bci with GNU General Public License v3.0 | 2 votes |
/** * Draws an ellipse to represent an outlier. * * @param point the location. * @param oRadius the radius. * @param g2 the graphics device. */ protected void drawEllipse(Point2D point, double oRadius, Graphics2D g2) { Ellipse2D.Double dot = new Ellipse2D.Double(point.getX() + oRadius / 2, point.getY(), oRadius, oRadius); g2.draw(dot); }