Functions for computing the distance between a Point and a Rectangle

This commit is contained in:
Tim Conkling
2011-12-16 12:35:25 -08:00
parent 060ff1b877
commit d2bebff736
2 changed files with 57 additions and 0 deletions
@@ -0,0 +1,22 @@
//
// Pythagoras - a collection of geometry classes
// http://github.com/samskivert/pythagoras
package pythagoras.f;
import org.junit.*;
import static org.junit.Assert.*;
public class RectangleTest
{
@Test public void testPointRectDistance () {
testPointRectDistance(0, new Rectangle(0, 0, 10, 10), new Point(0, 0)); // edge
testPointRectDistance(0, new Rectangle(0, 0, 10, 10), new Point(5, 5)); // interior
testPointRectDistance(5, new Rectangle(0, 0, 10, 10), new Point(5, 15)); // exterior
}
protected void testPointRectDistance (float expected, IRectangle r, Point p) {
assertEquals(expected, Rectangles.pointRectDistance(r, p), MathUtil.EPSILON);
}
}