Package java.awt.geom

Examples of java.awt.geom.Point2D


        paint(g, rect, text);
    }

    static void paint(Graphics2D g, Rectangle2D rect, String text) {
        // Find where the text baseline starts
        Point2D textOrigin = getTextOrigin(rect, g, text);

        // Find the text bounds
        FontMetrics metrics = g.getFontMetrics();
        Rectangle2D textBounds = metrics.getStringBounds(text, g);

        // Translate the text bounds to the place where text will be rendered
        double x = textOrigin.getX();
        double y = textOrigin.getY();
        textBounds = new Rectangle2D.Double(
            x + textBounds.getX(),
            y + textBounds.getY(),
            textBounds.getWidth(),
            textBounds.getHeight()
View Full Code Here


    // Get coordinates where the text origin should go.
    // This is the start of the basline, suitable for g.drawString().
    private static Point2D getTextOrigin(
        Rectangle2D rect, Graphics2D g, String text
    ) {
        Point2D lr = getLowerRight(rect);
        FontMetrics metrics = g.getFontMetrics();
        Rectangle2D bounds = metrics.getStringBounds(text, g);
        double x = lr.getX() - bounds.getWidth() - bounds.getX();
        double y = lr.getY() - bounds.getHeight() - bounds.getY();
        return new Point2D.Double(x, y);
    }
View Full Code Here

        double wtRight  = destPt.getX() - (int)destPt.getX();
        double wtLeft   = 1.0 - wtRight;
        double wtBottom = destPt.getY() - (int)destPt.getY();
        double wtTop    = 1.0 - wtBottom;

        Point2D pt = (Point2D)destPt.clone();
        pt.setLocation((sxy[0]*wtLeft + sxy[2]*wtRight)*wtTop +
                       (sxy[4]*wtLeft + sxy[6]*wtRight)*wtBottom,
                       (sxy[1]*wtLeft + sxy[3]*wtRight)*wtTop +
                       (sxy[5]*wtLeft + sxy[7]*wtRight)*wtBottom);

        return pt;
View Full Code Here

        double y2 = y1*y1;

        double x = c1 + c2*x1 + c3*y1 + c4*x2 + c5*x1*y1 + c6*y2;
        double y = c7 + c8*x1 + c9*y1 + c10*x2 + c11*x1*y1 + c12*y2;

        Point2D pt = (Point2D)destPt.clone();
        pt.setLocation(x*postScaleX - 0.5, y*postScaleY - 0.5);

        return pt;
    }
View Full Code Here

            double xMax = -Double.MAX_VALUE;
            double yMin = Double.MAX_VALUE;
            double yMax = -Double.MAX_VALUE;

            for(int i = 0; i < 4; i++) {
                Point2D destPt = warp.mapSourcePoint(srcPts[i]);
                if(destPt == null) {
                    verticesMapped = false;
                    break;
                }

                double x = destPt.getX();
                double y = destPt.getY();
                if(x < xMin) {
                    xMin = x;
                }
                if(x > xMax) {
                    xMax = x;
                }
                if(y < yMin) {
                    yMin = y;
                }
                if(y > yMax) {
                    yMax = y;
                }
            }

            // If all vertices mapped, compute the bounds.
            if(verticesMapped) {
                destBounds = new Rectangle();
                destBounds.x = (int)Math.floor(xMin);
                destBounds.y = (int)Math.floor(yMin);
                destBounds.width = (int)Math.ceil(xMax - destBounds.x);
                destBounds.height = (int)Math.ceil(yMax - destBounds.y);
            }
        }

        // If bounds still not computed, approximate the destination bounds
        // by the source bounds, compute an approximate forward mapping,
        // and use it to compute the destination bounds. If the warp is
        // a WarpAffine then skip it as mapSourceRect() already failed.
        if(destBounds == null && !(warp instanceof WarpAffine)) {
            Point[] destPts = new Point[] {
                new Point(sourceBounds.x,
                          sourceBounds.y),
                new Point(sourceBounds.x + sourceBounds.width,
                          sourceBounds.y),
                new Point(sourceBounds.x,
                          sourceBounds.y + sourceBounds.height),
                new Point(sourceBounds.x + sourceBounds.width,
                          sourceBounds.y + sourceBounds.height)};

            float[] sourceCoords = new float[8];
            float[] destCoords = new float[8];
            int offset = 0;

            for(int i = 0; i < 4; i++) {
                Point2D dstPt = destPts[i];
                Point2D srcPt = warp.mapDestPoint(destPts[i]);
                destCoords[offset] = (float)dstPt.getX();
                destCoords[offset+1] = (float)dstPt.getY();
                sourceCoords[offset] = (float)srcPt.getX();
                sourceCoords[offset+1] = (float)srcPt.getY();
                offset += 2;
            }

            // Guaranteed to be a WarpAffine as the degree is 1.
            WarpAffine wa =
View Full Code Here

            pageFormat.getImageableX(),
            pageFormat.getImageableY(),
            pageFormat.getImageableWidth(),
            pageFormat.getImageableHeight()
        );
        Point2D center = getPaperCenter();
        double minHalfWidth = Math.min(
            center.getX() - imageableRect.getX(),
            imageableRect.getX() + imageableRect.getWidth() - center.getX()
        );
        double minHalfHeight = Math.min(
            center.getY() - imageableRect.getY(),
            imageableRect.getY() + imageableRect.getHeight() - center.getY()
        );
        Rectangle2D fitRect = new Rectangle2D.Double(
            center.getX() - minHalfWidth,
            center.getY() - minHalfHeight,
            2 * minHalfWidth,
            2 * minHalfHeight
        );
        // Find the correct image bounds within this rectangle:
        imageRect = PreviewComponent.getImageBounds(fitRect, aspectRatio);
View Full Code Here

        double centerY = height / 2;
        return new Point2D.Double(centerX, centerY);
    }

    private void centerByTranslation() {
        Point2D center = getPaperCenter();

        double x = center.getX() - imageRect.getWidth() / 2;
        double y = center.getY() - imageRect.getHeight() / 2;

        setImageXSilent(x);
        setImageYSilent(y);
    }
View Full Code Here

        AffineTransform scaling =
            AffineTransform.getScaleInstance(factor, factor);

        double angle = crop.getAngle();

        Point2D center = crop.getCenter();

        AffineTransform rotation = AffineTransform.getRotateInstance(
            - angle, center.getX(), center.getY()
        );
        double x = center.getX() - crop.getWidth() / 2;
        double y = center.getY() - crop.getHeight() / 2;

        AffineTransform translation = AffineTransform.getTranslateInstance(
            -x, -y
        );
        xform = compose(translation, compose(rotation, scaling));
View Full Code Here

        width = crop.getWidth();
        height = crop.getHeight();
    }

    private static CropBounds getScaledCrop(CropBounds crop, Scale scale) {
        Point2D center = crop.getCenter();
        double width = crop.getWidth();
        double height = crop.getHeight();
        double angle = crop.getAngle();

        double factor = scale.getFactor();

        center = new Point2D.Double(
            factor * center.getX(), factor * center.getY()
        );
        width *= factor;
        height *= factor;

        return new CropBounds(center, width, height, angle);
View Full Code Here

        if (crop != null) {

            Graphics2D g = (Graphics2D) graphics;
            g.setColor(Color.orange);

            Point2D ul = crop.getUpperLeft();
            Point2D ur = crop.getUpperRight();
            Point2D ll = crop.getLowerLeft();
            Point2D lr = crop.getLowerRight();

            GeneralPath path = new GeneralPath();
            path.moveTo((float) ul.getX(), (float) ul.getY());
            path.lineTo((float) ur.getX(), (float) ur.getY());
            path.lineTo((float) lr.getX(), (float) lr.getY());
            path.lineTo((float) ll.getX(), (float) ll.getY());
            path.closePath();

            g.draw(path);
        }
View Full Code Here

TOP

Related Classes of java.awt.geom.Point2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.