Create geometry for a rectangle. - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

Create geometry for a rectangle.

Demo Code

/*//from  ww  w. ja va 2s .c om
 * (C) 2004 - Geotechnical Software Services
 * 
 * This code 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 code 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 program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
 * MA  02111-1307, USA.
 */
//package com.java2s;

public class Main {
    /**
     * Create geometry for a rectangle. Returns a closed polygon; first
     * and last points matches. Integer domain.
     * 
     * @param x0      X corner of rectangle.
     * @param y0      Y corner of rectangle.   
     * @param width   Width (may be negative to indicate leftwards direction)
     * @param height  Height (may be negative to indicaten upwards direction)
     */
    public static int[] createRectangle(int x0, int y0, int width,
            int height) {
        return new int[] { x0, y0, x0 + (width - 1), y0, x0 + (width - 1),
                y0 + (height - 1), x0, y0 + (height - 1), x0, y0 };
    }

    /**
     * Create geometry for a rectangle. Returns a closed polygon; first
     * and last points matches. Floating point domain.
     * 
     * @param x0      X corner of rectangle.
     * @param y0      Y corner of rectangle.   
     * @param width   Width (may be negative to indicate leftwards direction)
     * @param height  Height (may be negative to indicaten upwards direction)
     */
    public static double[] createRectangle(double x0, double y0,
            double width, double height) {
        return new double[] { x0, y0, x0 + width, y0, x0 + width,
                y0 + height, x0, y0 + height, x0, y0 };
    }
}

Related Tutorials