public void testRayCast() { // Static RayCast tests Assert.AreEqual(double.PositiveInfinity, testRect.rayCast(new Ray2D(1.0d, 1.0d, -7.0d, -8.0d)), 0.000005d); Assert.AreEqual(System.Math.Sqrt(2), testRect.rayCast(new Ray2D(2.0d, 3.0d, 3.0d, 4.0d)), 0.000005d); // Serial RayCast tests Rect2D randomRect; Line2D currentSide; Point2D randomPointOnSide; Point2D randomPoint; int i = 100; do { randomRect = new Rect2D(Util.generateRandomDoubleBetween(-1000.0d, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, 1000.0d)); int j = 50; do { currentSide = new Line2D(randomRect.getUpperLeft(), randomRect.getUpperRight()); randomPointOnSide = currentSide.randomPoint(); randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, 1000.0d), Util.generateRandomDoubleBetween(randomPointOnSide.getY(), 1000.0d)); Assert.AreEqual(randomPoint.distance(randomPointOnSide), randomRect.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnSide))), 0.000005d); currentSide = new Line2D(randomRect.getLowerLeft(), randomRect.getLowerRight()); randomPointOnSide = currentSide.randomPoint(); randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, randomPointOnSide.getY())); Assert.AreEqual(randomPoint.distance(randomPointOnSide), randomRect.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnSide))), 0.000005d); currentSide = new Line2D(randomRect.getLowerLeft(), randomRect.getUpperLeft()); randomPointOnSide = currentSide.randomPoint(); randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, randomPointOnSide.getX()), Util.generateRandomDoubleBetween(-1000.0d, 1000.0d)); Assert.AreEqual(randomPoint.distance(randomPointOnSide), randomRect.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnSide))), 0.000005d); currentSide = new Line2D(randomRect.getLowerRight(), randomRect.getUpperRight()); randomPointOnSide = currentSide.randomPoint(); randomPoint = new Point2D(Util.generateRandomDoubleBetween(randomPointOnSide.getX(), 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, 1000.0d)); Assert.AreEqual(randomPoint.distance(randomPointOnSide), randomRect.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnSide))), 0.000005d); j -= 1; } while (j > 0); i -= 1; } while (i > 0); }