gpt4 book ai didi

java - Rectangle.contains() 方法永远不会返回 true

转载 作者:行者123 更新时间:2023-12-01 19:38:38 24 4
gpt4 key购买 nike

我使用的图表返回一个 org.eclipse.draw2d.geometry.Rectangle ,其坐标为 Rectangle(20.0, 450.0, 0.0, 0.0)。我想检查其中是否存在一个点 (20,450)。

我已经尝试过使用 contains 和 equals 方法。但它不会返回 true。我做错了什么?

if (rectangle.contains(new Point(20, 450)))
{
return true;
}

我除了输出为真之外。我可以更改点的坐标,但不能更改矩形的坐标。

最佳答案

The documentation从字面上解释了这一点。

public boolean contains(double x, double y)

Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.

你的点是右下角。

关于java - Rectangle.contains() 方法永远不会返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56362699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com