get Scaled Rectangle - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

get Scaled Rectangle

Demo Code


//package com.java2s;

import java.awt.geom.Rectangle2D;

public class Main {
    /**// w  w  w. j a  va 2 s  .c o  m
     * @return
     */
    public static Rectangle2D getScaledRectangle(final Rectangle2D rect,
            double scalingFactor) {
        Rectangle2D newRect = null;

        if (rect != null && scalingFactor != 1) {
            double resizedWidth = rect.getWidth() * scalingFactor;
            double resizedHeight = rect.getHeight() * scalingFactor;

            newRect = (Rectangle2D) rect.clone();
            newRect.setRect(rect.getX(), rect.getY(), resizedWidth,
                    resizedHeight);
        }

        return newRect;
    }
}

Related Tutorials