Java 检查两个矩形是否在任何一点重叠 [英] Java check if two rectangles overlap at any point

查看:35
本文介绍了Java 检查两个矩形是否在任何一点重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个矩形和一个特殊的矩形:选择矩形.我想检查每个矩形是否包含至少一个位于选择矩形内的点.为了清楚起见,这是一张图片:

I have multiple rectangles and one special rectangle: the selection rect. I want to check for each rectangle if the rectangle contains at least one point which is inside the selection rectangle. Here is an image for clarity:

推荐答案

这将查找矩形是否与另一个矩形重叠:

This will find if the rectangle is overlapping another rectangle:

public boolean overlaps (Rectangle r) {
    return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y;
}

这篇关于Java 检查两个矩形是否在任何一点重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆