Beispiel #1
0
 /**
  * Determine whether this rectangle intersects the passed rectangle
  *
  * @param r The rectangle that might intersect this rectangle
  *
  * @return true if the rectangles intersect, false if they do not intersect
  */
 internal bool intersects(Rectangle r)
 {
     // Every dimension must intersect. If any dimension
     // does not intersect, return false immediately.
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (max[i] < r.min[i] || min[i] > r.max[i])
         {
             return false;
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Computes the union of this rectangle and the passed rectangle, storing
  * the result in this rectangle.
  *
  * @param r Rectangle to add to this rectangle
  */
 internal void add(Rectangle r)
 {
 for (int i = 0; i < DIMENSIONS; i++)
 {
     if (r.min[i] < min[i])
     {
         min[i] = r.min[i];
     }
     if (r.max[i] > max[i])
     {
         max[i] = r.max[i];
     }
 }
 }
Beispiel #3
0
 /**
  * Find the the union of this rectangle and the passed rectangle.
  * Neither rectangle is altered
  *
  * @param r The rectangle to union with this rectangle
  */
 internal Rectangle union(Rectangle r)
 {
 Rectangle union = this.copy();
 union.add(r);
 return union;
 }
Beispiel #4
0
            /**
             * Calculate the area by which this rectangle would be enlarged if
             * added to the passed rectangle. Neither rectangle is altered.
             *
             * @param r Rectangle to union with this rectangle, in order to
             *          compute the difference in area of the union and the
             *          original rectangle
             */
            internal double enlargement(Rectangle r)
            {
             double enlargedArea = (Math.Max(max[0], r.max[0]) - Math.Min(min[0], r.min[0])) *
                                 (Math.Max(max[1], r.max[1]) - Math.Min(min[1], r.min[1]));

            return enlargedArea - area();
            }
Beispiel #5
0
        /**
         * Return the furthst possible distance between this rectangle and
         * the passed rectangle.
         *
         * Find the distance between this rectangle and each corner of the
         * passed rectangle, and use the maximum.
         *
         */
        internal double furthestDistance(Rectangle r)
        {
            double distanceSquared = 0;

            for (int i = 0; i < DIMENSIONS; i++)
            {
                distanceSquared += Math.Max(r.min[i], r.max[i]);
            #warning possible didn't convert properly
                //distanceSquared += Math.Max(distanceSquared(i, r.min[i]), distanceSquared(i, r.max[i]));
            }

            return (double)Math.Sqrt(distanceSquared);
            }
Beispiel #6
0
 /**
  * Determine whether an edge of this rectangle overlies the equivalent
  * edge of the passed rectangle
  */
 internal bool edgeOverlaps(Rectangle r)
 {
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (min[i] == r.min[i] || max[i] == r.max[i])
         {
             return true;
         }
     }
     return false;
 }
Beispiel #7
0
 /**
  * Return the distance between this rectangle and the passed rectangle.
  * If the rectangles overlap, the distance is zero.
  *
  * @param r Rectangle to find the distance to
  *
  * @return distance between this rectangle and the passed rectangle
  */
 internal double distance(Rectangle r)
 {
     double distanceSquared = 0;
     for (int i = 0; i < DIMENSIONS; i++)
     {
     double greatestMin = Math.Max(min[i], r.min[i]);
     double leastMax = Math.Min(max[i], r.max[i]);
         if (greatestMin > leastMax)
         {
             distanceSquared += ((greatestMin - leastMax) * (greatestMin - leastMax));
         }
     }
     return (double)Math.Sqrt(distanceSquared);
 }
Beispiel #8
0
 /**
  * Determine whether this rectangle contains the passed rectangle
  *
  * @param r The rectangle that might be contained by this rectangle
  *
  * @return true if this rectangle contains the passed rectangle, false if
  *         it does not
  */
 internal bool contains(Rectangle r)
 {
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (max[i] < r.max[i] || min[i] > r.min[i])
         {
             return false;
         }
     }
     return true;
 }