Java Rectangle Intersect intersects(Rectangle rect1, Rectangle rect2, boolean vertical)

Here you can find the source of intersects(Rectangle rect1, Rectangle rect2, boolean vertical)

Description

intersects

License

LGPL

Declaration

private static boolean intersects(Rectangle rect1, Rectangle rect2, boolean vertical) 

Method Source Code


//package com.java2s;
/*/*from ww  w .ja v  a 2  s  .  com*/
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
    
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
    
Contact info: info@xamjwg.org
*/

import java.awt.*;

public class Main {
    private static boolean intersects(Rectangle rect1, Rectangle rect2, boolean vertical) {
        if (vertical) {
            return !((rect1.y > rect2.y + rect2.height) || (rect2.y > rect1.y + rect1.height));
        } else {
            return !((rect1.x > rect2.x + rect2.width) || (rect2.x > rect1.x + rect1.width));
        }
    }
}

Related

  1. intersects(final Rectangle elementRect, final Rectangle viewportRect)
  2. intersects(final Rectangle2D a, final Rectangle2D b)
  3. intersects(float cx, float cy, float radius, float left, float top, float right, float bottom)
  4. intersects(Point p1, Point p2, Rectangle rect)
  5. intersects(Rectangle aRectangle, Line2D aLine)
  6. intersects(Rectangle2D r, Object o)
  7. intersects(Rectangle2D rect1, Rectangle2D rect2)
  8. intersectsOutline(Rectangle2D r, Shape s)
  9. intersectsRectangle(final double checkMinX, final double checkMinY, final double checkMaxX, final double checkMaxY, final double againstMinX, final double againstMinY, final double againstMaxX, final double againstMaxY)