如何获得 Java 中两点之间的尺寸
How to get the dimension between two points in Java
给定两个 Point
s,是否有比这更自然的解决方案来获取它们之间的区域?
new Dimension(one.x - other.x, one.y - other.y);
我想到的是这样的
Dimension a = new Dimension(one, other);
Dimension b = one.towards(other);
语法有点奇怪,但这里是:
static Dimension sizeBetween(Point from, Point to) {
Rectangle box = new Rectangle(from);
box.add(to);
return box.getSize();
}
给定两个 Point
s,是否有比这更自然的解决方案来获取它们之间的区域?
new Dimension(one.x - other.x, one.y - other.y);
我想到的是这样的
Dimension a = new Dimension(one, other);
Dimension b = one.towards(other);
语法有点奇怪,但这里是:
static Dimension sizeBetween(Point from, Point to) {
Rectangle box = new Rectangle(from);
box.add(to);
return box.getSize();
}