算法题: how to determine rectangle is inside the another rectangle?

标签 algorithm

给定一个元组列表(包括 x, y, width, height 这四个值以二维坐标定义一个矩形)。 目标是在原始列表中检查一个矩形是否在另一个矩形内部(如果是,则只取较小的,较大的丢弃)

最佳答案

如果不是太慢,最明显的解决方案是将 rect1.contains(rect2) 定义为:

rect1.x <= rect2.x && rect1.y <= rect2.y && rect1.x + rect1.width >= rect2.x + rect2.width && rect1.y + rect1.height >= rect2.y + rect2.height

然后检查列表中的每个矩形,看看它是否包含任何其他矩形。 (不过,不要检查它本身!)

关于算法题: how to determine rectangle is inside the another rectangle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38531331/

相关文章:

algorithm - 使用小波变换去除基线信号

c++ - 将结构与模式集匹配

algorithm - 伪代码解释器?

java - 在 Java 中使用给定数量的 1 创建所有可能的二进制排列

python - Python 中的合并排序 - `int` 对象不可迭代

algorithm - 是否有最佳算法来查找行的子集,其总和位于指定的间隔内?

algorithm - 我正在尝试将整数 N/2 转换为 double,以便 floor() 函数可以使用它,但输出始终是垃圾值

java - 作业 - Java - 在我创建的双链表上进行选择排序

algorithm - 如何找到最佳 split 点集

sql - 填充槽的算法