public void TestRaycastRectangle() { // lines Vector2[][] lines = { new[] { new Vector2(37.39518f, 27.87007f), new Vector2(32.02394f, 22.17816f) }, new[] { new Vector2(32.02394f, 22.17816f), new Vector2(37.39518f, 27.87007f) }, new[] { new Vector2(40.66259f, 1.94544f), new Vector2(5.58571f, 33.33002f) } }; Vector2[] intrDot = { new Vector2(34.6901f, 25.0f), new Vector2(34.6901f, 25.0f), new Vector2(31.66f, 10.0013f) }; // True fraction data float[] trueFraction = { 0.5039476f, 0.4960526f, 0.256666f }; //Create circle obj RectangleShape rectShape = new RectangleShape(Vector2.Zero, 30.0f, 15.0f); Collision.Transform rectTransform = new Collision.Transform(new Vector2(25.03758f, 17.48668f), 0 * Mathf.Deg2Rad); for (var obj = 0; obj < lines.Length; obj++) { float fraction; Vector2 normal; bool rayCast = rectShape.RayCast(rectTransform, lines[obj][0], lines[obj][1], out fraction, out normal); Assert.That(rayCast, "RayCast to Rectangle test failed. Result {0} is incorrect", obj); var point = lines[obj][0] + (lines[obj][1] - lines[obj][0]) * fraction; string err = String.Format( "RayCast to Rectangle test failed; Intersect: trueFraction {0} (testFraction: {1}), intrPoint({2}), testPoint {3}, normal {4}", trueFraction[obj], fraction, intrDot[obj], point, normal); Assert.That(Mathf.FloatEquals(fraction, trueFraction[obj], 0.005f), err); } }