如果我在画布上有两个System.Drawing.Rectangle
对象和一个Point
,那么计算哪个Rectangle
(不仅仅是其Location
Point
)最接近该Point
的最佳方法是什么?
以下是一个单元测试示例:
Rectangle one = new Rectangle (0, 0, 10, 10);
Rectangle two = new Rectangle (20, 20, 10, 10);
Point point = new Point(14, 14);
Rectangle actual = ClosestToPoint(point, one, two);
// should be closer to one since one's bottom right is at (10, 10)
Assert.That(actual, Is.SameAs(one));
// method to write
public Rectangle ClosestToPoint(Point p, params Rectangle[] rectangles) { }