示例#1
0
 public void testRandomPoint()
 {
     for (int i = 0; i < 1000; ++i)
     {
         Assert.IsTrue(testRect.isInsideBorder(testRect.randomPoint()));
     }
 }
示例#2
0
        /**
         * Calculates the length of a ray until it intersects with a shape.<br/>
         * As this class uses the set maximum ray range to speed up this ray casting,<br/>
         * this function may return {@code double.PositiveInfinity} for a ray that intersects with an obstacle that is further away than the rayRange from the given starting point.
         * @param ray the ray to be used for ray casting.
         * @return the length of the ray.
         */
        public double rayCast(Ray2D ray)
        {
            double result      = double.PositiveInfinity;
            Rect2D rayBounding = new Rect2D(ray.getStart().getX() - rayRange, ray.getStart().getY() - rayRange, ray.getStart().getX() + rayRange, ray.getStart().getY() + rayRange);

            for (int i = 0; i < shapes.Size(); ++i)
            {
                Rect2D bounding = boundaries.Get(i);
                if (rayBounding.isInsideBorder(bounding.getLowerLeft()) ||
                    rayBounding.isInsideBorder(bounding.getUpperLeft()) ||
                    rayBounding.isInsideBorder(bounding.getLowerRight()) ||
                    rayBounding.isInsideBorder(bounding.getUpperRight()))
                {
                    double tmp = shapes.Get(i).rayCast(ray);
                    result = tmp < result ? tmp : result;
                }
            }
            return(result);
        }