Java Rectangle Grow shrink(Rectangle r, int h, int v, boolean clone)

Here you can find the source of shrink(Rectangle r, int h, int v, boolean clone)

Description

shrinks a Rectangle, the center is kept constant

License

Open Source License

Parameter

Parameter Description
r the source Rectangle
h the horizonal shrink
v the vertical shrink
clone determines if the source rectangle is shrinked or a cloned object is returned

Return

the shrinked Rectangle

Declaration

public static Rectangle shrink(Rectangle r, int h, int v, boolean clone) 

Method Source Code


//package com.java2s;
/* *****************************************************************************
 * NightLabs Editor2D - Graphical editor framework                             *
 * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org                    *
 *                                                                             *
 * This library is free software; you can redistribute it and/or               *
 * modify it under the terms of the GNU Lesser General Public                  *
 * License as published by the Free Software Foundation; either                *
 * version 2.1 of the License, or (at your option) any later version.          *
 *                                                                             *
 * This library is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           *
 * Lesser General Public License for more details.                             *
 *                                                                             *
 * You should have received a copy of the GNU Lesser General Public            *
 * License along with this library; if not, write to the                       *
 *     Free Software Foundation, Inc.,                                         *
 *     51 Franklin St, Fifth Floor,                                            *
 *     Boston, MA  02110-1301  USA                                             *
 *                                                                             *
 * Or get it online :                                                          *
 *     http://www.gnu.org/copyleft/lesser.html                                 *
 *                                                                             *
 *                                                                             *
 ******************************************************************************/

import java.awt.Rectangle;

public class Main {
    /**//from  www .  ja  va  2s . c  o  m
     * 
     * shrinks a Rectangle, the center is kept constant
     * @param r the source Rectangle
     * @param h the horizonal shrink
     * @param v the vertical shrink
     * @param clone determines if the source rectangle is shrinked or a cloned object is returned
     * @return the shrinked Rectangle
     */
    public static Rectangle shrink(Rectangle r, int h, int v, boolean clone) {
        if (!clone) {
            r.x = r.x + v;
            r.width = r.width - v;
            r.y = r.y + h;
            r.height = r.height - h;
            return r;
        } else {
            return new Rectangle(r.x + v, r.width - v, r.y + h, r.height - h);
        }
    }
}

Related

  1. growRect(Rectangle2D rect, double d)
  2. growRectangle(Rectangle2D rec, double amount_x, double amount_y)
  3. growRectByRelativeSize(Rectangle2D rect, double top, double right, double bottom, double left)
  4. growRectInPlace(Rectangle2D rect, double top, double right, double bottom, double left)
  5. growTheRect(Rectangle rect, int factor)
  6. shrinkSize(Rectangle r, Insets insets)