get Growing Rectangle - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

get Growing Rectangle

Demo Code


//package com.java2s;

import java.awt.geom.Rectangle2D;

public class Main {
    /**/*w  w w .  j  a v a 2  s. c o  m*/
     * @return
     */
    public static Rectangle2D getGrowingRectangle(Rectangle2D rect,
            double growingSize) {
        Rectangle2D growingRect = rect != null ? (Rectangle2D) rect.clone()
                : null;
        growRectangle(growingRect, growingSize);
        return growingRect;
    }

    /**
     * @param growingSize
     */
    public static void growRectangle(Rectangle2D rect, double growingSize) {
        if (rect == null) {
            return;
        }

        if (growingSize != 0) {
            double newX = rect.getX() - growingSize;
            double newY = rect.getY() - growingSize;
            double newWidth = rect.getWidth() + (2.0 * growingSize);
            double newHeight = rect.getHeight() + (2.0 * growingSize);
            rect.setRect(newX, newY, newWidth, newHeight);
        }
    }
}

Related Tutorials