Adds the target rectangle to the bounds of the source rectangle. - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

Adds the target rectangle to the bounds of the source rectangle.

Demo Code

// Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;
import static com.threerings.geom.Log.log;

public class Main{
    /**//  w ww  . j  a v  a 2  s  .com
     * Adds the target rectangle to the bounds of the source rectangle. If the source rectangle is
     * null, a new rectangle is created that is the size of the target rectangle.
     *
     * @return the source rectangle.
     */
    public static Rectangle grow(Rectangle source, Rectangle target) {
        if (target == null) {
            log.warning("Can't grow with null rectangle [src=" + source
                    + ", tgt=" + target + "].", new Exception());
        } else if (source == null) {
            source = new Rectangle(target);
        } else {
            source.add(target);
        }
        return source;
    }
}

Related Tutorials