测试如果矩形包含了所有其它的矩形或部分? [英] Test if rectangle contains all or part of another rectangle?

查看:169
本文介绍了测试如果矩形包含了所有其它的矩形或部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code:

graphicsContext.setCanvas(canvas);
graphicsContext.clear();
camera.applyTransform(graphicsContext);
RectF screen = camera.getCamRect(getWidth(), getHeight());

for(Road r : roads) {
  if(screen.contains(r.getRect())) {
    r.draw(graphicsContext);
  }
}

for(Intersection i : intersections) {
  if(screen.contains(i.getRect())) {
    i.draw(graphicsContext);
  }
}

唯一的问题是包含方法必须全部4 verticies B,在对返回true。 什么类型的算法,我可以使用,因为顶部,左,下,右,检查B是的一部分或全部内湾

The only problem is the contains method must have all 4 verticies of B in A to return true. What type of algorithm could I use, given top, left, bottom, right to check if B is either part or completely inside B.

感谢

推荐答案

只需使用 RectF.contains()与每个形状要测试的顶路口

Just use RectF.contains() with each of the vertices of the shape you want to test for intersection

甚至更容易, RectF.intersects()将处理所有的你。

or even easier, RectF.intersects() will handle all that for you.

这一切都在文档

这篇关于测试如果矩形包含了所有其它的矩形或部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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