Java Code Examples for java.awt.geom.Point2D.getY()

The following are Jave code examples for showing how to use getY() of the java.awt.geom.Point2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: imagingbook-common   File: AffineMapping.java   View Source Code Vote up 6 votes
public AffineMapping(Point2D A1, Point2D A2, Point2D A3, Point2D B1, Point2D B2, Point2D B3) {
	super();
	double ax1 = A1.getX(), ax2 = A2.getX(), ax3 = A3.getX();
	double ay1 = A1.getY(), ay2 = A2.getY(), ay3 = A3.getY();
	double bx1 = B1.getX(), bx2 = B2.getX(), bx3 = B3.getX();
	double by1 = B1.getY(), by2 = B2.getY(), by3 = B3.getY();
	
	double S = ax1*(ay3-ay2) + ax2*(ay1-ay3) + ax3*(ay2-ay1); // TODO: check S for zero value and throw exception!
	a00 = (ay1*(bx2-bx3) + ay2*(bx3-bx1) + ay3*(bx1-bx2)) / S;
	a01 = (ax1*(bx3-bx2) + ax2*(bx1-bx3) + ax3*(bx2-bx1)) / S;
	a10 = (ay1*(by2-by3) + ay2*(by3-by1) + ay3*(by1-by2)) / S;
	a11 = (ax1*(by3-by2) + ax2*(by1-by3) + ax3*(by2-by1)) / S;
	a02 = 
			(ax1*(ay3*bx2-ay2*bx3) + ax2*(ay1*bx3-ay3*bx1) + ax3*(ay2*bx1-ay1*bx2)) / S;
	a12 = 
			(ax1*(ay3*by2-ay2*by3) + ax2*(ay1*by3-ay3*by1) + ax3*(ay2*by1-ay1*by2)) / S;
}
 
Example 2
Project: jdk8u-jdk   File: StandardGlyphVector.java   View Source Code Vote up 6 votes
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 3
Project: rapidminer   File: ProcessRendererController.java   View Source Code Vote up 6 votes
/**
 * Returns the closest operator to the left of the given point and process.
 *
 * @param p
 *            looks for an operator to the left of this location
 * @param unit
 *            the process for the location
 * @return the closest operator or {@code null}
 */
Operator getClosestLeftNeighbour(final Point2D p, final ExecutionUnit unit) {
	Operator closest = null;
	double minDist = Double.POSITIVE_INFINITY;
	for (Operator op : unit.getOperators()) {
		Rectangle2D rect = model.getOperatorRect(op);
		if (rect.getMaxX() >= p.getX()) {
			continue;
		}
		double dx = rect.getMaxX() - p.getX();
		double dy = rect.getMaxY() - p.getY();
		double dist = dx * dx + dy * dy;
		if (dist < minDist) {
			minDist = dist;
			closest = op;
		}
	}
	return closest;
}
 
Example 4
Project: jdk8u-jdk   File: LayoutPathImpl.java   View Source Code Vote up 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 5
Project: JavaGraph   File: JEdgeView.java   View Source Code Vote up 5 votes
/** Returns the perimeter point where the end of this edge has to connect.
 * @param vertex the end vertex
 * @param source if {@code true}, we're computing this for the edge source,
 * otherwise for the edge target
 */
private Point2D getEndPoint(CellView vertex, boolean source) {
    JVertexView vertexView = (JVertexView) vertex;
    Point2D center = getCenterPoint(vertex);
    Point2D nextPoint = getNearestPoint(source);
    // adjust the centre and next point depending on the number of
    // parallel edges, as determined by the parameter rank
    Point2D adjustedCenter;
    Point2D adjustedNextPoint;
    int parRank = source ? getParRank() : -getParRank();
    if (parRank == 0) {
        adjustedCenter = center;
        adjustedNextPoint = nextPoint;
    } else {
        // direction of the next point
        double dx = nextPoint.getX() - center.getX();
        double dy = nextPoint.getY() - center.getY();
        // direction for the offset, perpendicular to the next point
        double offDirX = dy;
        double offDirY = -dx;
        double offDist = center.distance(nextPoint);
        // calculate vertex radius in the specified direction
        Rectangle2D bounds = vertex.getBounds();
        double offMax = vertexView.getCellVisuals()
            .getNodeShape()
            .getRadius(bounds, offDirX, offDirY);
        // calculate actual offset
        double offset =
            Math.signum(parRank) * Math.min(PAR_EDGES_DISTANCE * Math.abs(parRank), offMax);
        double offX = offset * offDirX / offDist;
        double offY = offset * offDirY / offDist;
        adjustedCenter = new Point2D.Double(center.getX() + offX, center.getY() + offY);
        adjustedNextPoint =
            new Point2D.Double(nextPoint.getX() + offX, nextPoint.getY() + offY);
    }
    return vertexView.getPerimeterPoint(this, adjustedCenter, adjustedNextPoint);
}
 
Example 6
Project: jdk8u-jdk   File: MultiGradientTest.java   View Source Code Vote up 5 votes
private void updatePoints(int x, int y) {
    Point2D inv = new Point2D.Double(x, y);

    try {
        inv = transform.inverseTransform(inv, null);
    } catch (NoninvertibleTransformException e) {
        e.printStackTrace();
    }

    x = (int)inv.getX();
    y = (int)inv.getY();

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        // pick the closest point to move
        if (inv.distance(startX, startY) < inv.distance(endX, endY)) {
            startX = x;
            startY = y;
        } else {
            endX = x;
            endY = y;
        }
        break;

    case RADIAL:
        // pick the closest point to move
        if (inv.distance(ctrX, ctrY) < inv.distance(focusX, focusY)) {
            ctrX = x;
            ctrY = y;
        } else {
            focusX = x;
            focusY = y;
        }
        break;
    }

    updatePaint();
}
 
Example 7
Project: OpenJSharp   File: CTrayIcon.java   View Source Code Vote up 5 votes
private void showMessageDialog() {

        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        Point2D iconLoc = nativeGetIconLocation(getModel());

        int dialogY = (int)iconLoc.getY();
        int dialogX = (int)iconLoc.getX();
        if (dialogX + messageDialog.getWidth() > screenSize.width) {
            dialogX = screenSize.width - messageDialog.getWidth();
        }

        messageDialog.setLocation(dialogX, dialogY);
        messageDialog.setVisible(true);
    }
 
Example 8
Project: geomapapp   File: PolarStereo.java   View Source Code Vote up 5 votes
public PolarStereo(Point2D poleXY, double refLon, double scale, 
			int hemisphere, int ellipsoid) {
	poleX = poleXY.getX();
	poleY = poleXY.getY();
	this.refLon = refLon + 90;
	if( hemisphere==SOUTH ) this.refLon -= 180;
	this.scale = scale;
	this.hemisphere = hemisphere;
	this.ellipsoid = ellipsoid;
	init();
}
 
Example 9
Project: geomapapp   File: XMap.java   View Source Code Vote up 5 votes
/**
 	Zoom by factor and center on point p.
 	@param p point to center on.
 	@param factor Factor to zoom by.
 */
public void doZoom( Point2D p, double factor ) {
	AffineTransform ATrans = new AffineTransform();
	ATrans.scale( zoom, zoom );
	Insets insets = getInsets();
	Rectangle rect = getVisibleRect();
	Dimension dim = getParent().getSize();
	if( dim.width>rect.width) rect.width = dim.width;
	if( dim.height>rect.height) rect.height = dim.height;
	rect.width -= insets.left + insets.right;
	rect.height -= insets.top + insets.bottom;
	double nX = (p.getX() - insets.left - (rect.width/(2.*factor)));
	double nY = ( p.getY() - insets.top - rect.height/(2.*factor));
	Point2D newP = null;
	try {
		newP = ATrans.inverseTransform( new Point2D.Double(nX, nY), null );
	} catch (Exception ex ) {
		return;
	}
	ATrans.scale( factor, factor );
	zoom *= factor;
	newP = ATrans.transform( newP, null );
	int newX = (int)newP.getX(); // + insets.left;
	int newY = (int)newP.getY(); // + insets.top;
	invalidate();
	scrollPane.validate();
	JScrollBar sb = scrollPane.getHorizontalScrollBar();
	sb.setValue(newX);
	sb = scrollPane.getVerticalScrollBar();
	sb.setValue(newY);
	revalidate();

	//If this is MapApp Auto Focus
	if (app instanceof MapApp) {
		((MapApp) app).autoFocus();
	}
}
 
Example 10
Project: cuttlefish   File: NetworkRenderer.java   View Source Code Vote up 5 votes
/**
 * This method finds the location of the graph relative to the viewer and
 * shifts is so that it appears in the center of JUNG's VisualizationViewer.
 */
public void centerNetwork() {
	double top = Double.MAX_VALUE;
	double bottom = Double.MAX_VALUE;
	double left = Double.MAX_VALUE;
	double right = Double.MAX_VALUE;

	for (Vertex v : getVertices()) {
		Point2D p = v.getPosition();

		if (top < p.getY() || top == Double.MAX_VALUE)
			top = p.getY();
		if (bottom > p.getY() || bottom == Double.MAX_VALUE)
			bottom = p.getY();
		if (left > p.getX() || left == Double.MAX_VALUE)
			left = p.getX();
		if (right < p.getX() || right == Double.MAX_VALUE)
			right = p.getX();
	}

	double deltaX = this.getCenter().getX() - (right + left) / 2;
	double deltaY = this.getCenter().getY() - (top + bottom) / 2;
	double zoom = height / (top - bottom + RENDER_MARGIN);

	if (!Double.isInfinite(deltaX) && !Double.isInfinite(deltaY)
			&& !Double.isNaN(deltaX) && !Double.isNaN(deltaY)) {

		translate(deltaX, deltaY);
		scale(zoom, getCenter());

		graphMouse.setZoomFactor(zoom);
		graphMouse.setZoomPosition(getCenter());
	}
}
 
Example 11
Project: jdk8u-jdk   File: StandardGlyphVector.java   View Source Code Vote up 5 votes
public void setGlyphPosition(int ix, Point2D pos) {
    initPositions();

    int ix2 = ix << 1;
    positions[ix2] = (float)pos.getX();
    positions[ix2 + 1] = (float)pos.getY();

    clearCaches(ix);
    addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
}
 
Example 12
Project: qupath-tracking-extension   File: ExtendedViewTrackerPlayback.java   View Source Code Vote up 5 votes
private static void setViewerForFrame(QuPathViewer viewer, ViewRecordingFrame frame) {
    resizeViewer(viewer, frame.getSize());
    Rectangle imageBounds = frame.getImageBounds();
    Dimension canvasSize = frame.getSize();
    double downsampleX = (double)imageBounds.width / (double)canvasSize.width;
    double downsampleY = (double)imageBounds.height / (double)canvasSize.height;
    double downsample = 0.5D * (downsampleX + downsampleY);
    viewer.setDownsampleFactor(downsample);
    viewer.setCenterPixelLocation(
            (double)imageBounds.x + (double)imageBounds.width * 0.5D,
            (double)imageBounds.y + (double)imageBounds.height * 0.5D);

    playbackOverlay.updateIconLocations(frame);

    Point2D p2d;
    if (frame.hasCursorPosition()) {
        p2d = viewer.imagePointToComponentPoint(
                frame.getCursorPosition(),
                null,
                false);
        new Point((int)(p2d.getX() + 0.5D), (int)(p2d.getY() + 0.5D));
    }

    if (frame.hasEyePosition()) {
        p2d = frame.getEyePosition();
        PointsROI point = new PointsROI(p2d.getX(), p2d.getY());
        PathObject pathObject = new PathAnnotationObject(point);
        pathObject.setName("Eye tracking position");
        viewer.setSelectedObject(pathObject);
        logger.debug("Eye position: " + p2d);
    }
}
 
Example 13
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 5 votes
/**
 * Gets the connecting lines.
 *
 * @return the connecting lines
 */
public static Line2D[] getConnectingLines(final Point2D point, final Point2D[] rectPoints) {
  final Line2D[] lines = new Line2D[rectPoints.length];

  for (int i = 0; i < rectPoints.length; i++) {
    lines[i] = new Line2D.Double(point.getX(), point.getY(), rectPoints[i].getX(), rectPoints[i].getY());
  }

  return lines;
}
 
Example 14
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 5 votes
public static Point2D getMidPoint(final Point2D p1, final Point2D p2) {
  final Point2D mid = new Point2D.Double();
  final double x = (p1.getX() + p2.getX()) / 2;
  final double y = (p1.getY() + p2.getY()) / 2;
  mid.setLocation(x, y);
  return mid;

}
 
Example 15
Project: Pogamut3   File: A.java   View Source Code Vote up 4 votes
public static Point2D rotate(Point2D point, double rad){
	  // R(q) = ( cos q   sin q)
      //        (-sin q   cos q)
	return new Point2D.Double( Math.cos(rad)*point.getX() - Math.sin(rad)*point.getY(),
		  			           Math.sin(rad)*point.getX() + Math.cos(rad)*point.getY());
}
 
Example 16
Project: cuttlefish   File: TikzExporter.java   View Source Code Vote up 4 votes
/**
 * Prints the necessary information to display a vertex in the tikz output
 * 
 * @param vertex
 * @throws IOException
 */
private void exportVertex(Vertex vertex) throws IOException {
	Point2D coordinates = null;
	// if the size is fixed we have to scale the coordinates
	if (fixedSize) {
		Point2D origCoordinates = vertex.getPosition();
		coordinates = new Point2D.Double(alpha
				* (origCoordinates.getX() - xmin), beta
				* (origCoordinates.getY() - ymin));
		s = Math.max(alpha, beta);
	} else {
		coordinates = vertex.getPosition();
		s = 1;
	}

	writer.append("\\node at ("
			+ formatter.format(coordinates.getX()
					* (coordinateFactor / 10.0))
			+ ","
			+ formatter.format((maxY - coordinates.getY())
					* (coordinateFactor / 10.0)) + ") [");
	if (vertex != null) {
		writer.append(vertex.getShape()).append(",");
	}
	writer.append(" line width=" + formatter.format(vertex.getWidth() * s)
			+ ",");

	if ((vertex.getBorderColor() != null) && (vertex.getWidth() > 0))
		writer.append(" draw=" + colors.get(vertex.getBorderColor()) + ",");
	if (vertex.getFillColor() != null)
		writer.append(" fill=" + colors.get(vertex.getFillColor()) + ",");
	writer.append(" inner sep=0pt,");
	writer.append(" minimum size = "
			+ formatter.format((vertex.getSize()) * nodeSizeFactor * s)
			+ "pt,");

	if ((vertex.getLabel() != null) && (!hideVertexLabels)) {
		writer.append(" label={[label distance=0]" +
		// calculateAngle(vertex)
				"315" + ":" + escapeChars(vertex.getLabel()) + "}");
	}
	if (nodeStyle.compareToIgnoreCase("ball") == 0) {
		writer.append(", shading=ball,");
		if (vertex.getFillColor() != null) // The color reappears in the
											// shading
			writer.append(" ball color="
					+ colors.get(vertex.getFillColor()));
		else
			writer.append(" ball color=black");
	}

	writer.append("] (" + vertex.getId() + ") {};\n");
}
 
Example 17
Project: JavaGraph   File: GraphToTikz.java   View Source Code Vote up 4 votes
/** Appends the given point. */
private void appendPoint(Point2D point) {
    double x = point.getX();
    double y = point.getY();
    appendPoint(x, y, true, this.result);
}
 
Example 18
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 4 votes
public static Point2D getPointOnCircle(final Point2D center, final double radius, final double angle) {
  final double x = center.getX() + radius * Math.cos(Math.toRadians(angle));
  final double y = center.getY() + radius * Math.sin(Math.toRadians(angle));

  return new Point2D.Double(x, y);
}
 
Example 19
Project: WordnetLoom   File: ViwnNode.java   View Source Code Vote up 2 votes
/**
 * Transform an absolute screen point to relative vertex point.
 *
 * @param ps
 * @param v
 * @param vv
 * @return Point2D --- vertex relative point.
 */
public static Point absToVertexRel(Point ps, ViwnNode v, VisualizationViewer<ViwnNode, ViwnEdge> vv) {
    Point2D p = vv.getGraphLayout().transform(v);
    Point2D ps2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(ps);
    return new Point((int) (ps2.getX() - p.getX()), (int) (ps2.getY() - p.getY()));
}
 
Example 20
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 2 votes
/**
 * Contains.
 *
 * @param rectangle
 *          the rectangle
 * @param p
 *          the p
 * @return true, if successful
 */
public static boolean contains(final Rectangle2D rectangle, final Point2D p) {
  return rectangle.getX() <= p.getX() && rectangle.getY() <= p.getY() && rectangle.getX() + rectangle.getWidth() >= p.getX() && rectangle.getY() + rectangle.getHeight() >= p.getY();
}