Check if a specified point is inside a specified rectangle. - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

Check if a specified point is inside a specified rectangle.

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//www  . j av  a  2  s  .  c o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;

public class Main {


    /**
     * Check if a specified point is inside a specified rectangle.
     * 
     * @param x0
     *            , y0, x1, y1 Upper left and lower right corner of rectangle
     *            (inclusive)
     * @param x
     *            ,y Point to check.
     * @return True if the point is inside the rectangle,
     *         false otherwise.
     */
    public static boolean isPointInsideRectangle(float x0, float y0,
            float x1, float y1, float x, float y) {
        return (x >= x0) && (x < x1) && (y >= y0) && (y < y1);
    }
}

Related Tutorials