Here you can find the source of newRectangle(int x1, int y1, int x2, int y2)
Parameter | Description |
---|---|
x1 | x coordinate of first point |
y1 | y coordinate of first point |
x2 | x coordinate of second point |
y2 | y coordinate of second point |
public static Rectangle newRectangle(int x1, int y1, int x2, int y2)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.awt.Point; import java.awt.Rectangle; public class Main { /**/*from ww w .j a va 2 s. c om*/ * creates a rectangle out of two points. * @param x1 x coordinate of first point * @param y1 y coordinate of first point * @param x2 x coordinate of second point * @param y2 y coordinate of second point * @return the smallest Rectangle containing both points */ public static Rectangle newRectangle(int x1, int y1, int x2, int y2) { final int x = Math.min(x1, x2); final int y = Math.min(y1, y2); final int w = Math.abs(x1 - x2 + 1); final int h = Math.abs(y1 - y2 + 1); return new Rectangle(x, y, w, h); } /** * creates a rectangle out of two points. * @param p1 first point * @param p2 second point * @return the smallest Rectangle containing both points */ public static Rectangle newRectangle(Point p1, Point p2) { return newRectangle(p1.x, p1.y, p2.x, p2.y); } }