测试如果矩形包含了所有其它的矩形或部分?矩形、它的、部分、测试

2023-09-11 07:25:41 作者:热衷者

我有这个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.

这一切都在文档。