Exemple #1
0
        // Helper method for compiting the bounds of a set of points.  The given point
        // is added to the bounds of the given Rect3D.  The point/bounds are both passed 
        // by reference for perf.  Only the bounds may be modified.
        private static void AddPointToBounds(ref Point3D point, ref Rect3D bounds) 
        { 
            Debug.Assert(!bounds.IsEmpty,
                "Caller should construct the Rect3D from the first point before calling this method."); 

            if (point.X < bounds.X)
            {
                bounds.SizeX += (bounds.X - point.X); 
                bounds.X = point.X;
            } 
            else if (point.X > (bounds.X + bounds.SizeX)) 
            {
                bounds.SizeX = point.X - bounds.X; 
            }

            if (point.Y < bounds.Y)
            { 
                bounds.SizeY += (bounds.Y - point.Y);
                bounds.Y = point.Y; 
            } 
            else if (point.Y > (bounds.Y + bounds.SizeY))
            { 
                bounds.SizeY = point.Y - bounds.Y;
            }

            if (point.Z < bounds.Z) 
            {
                bounds.SizeZ += (bounds.Z - point.Z); 
                bounds.Z = point.Z; 
            }
            else if (point.Z > (bounds.Z + bounds.SizeZ)) 
            {
                bounds.SizeZ = point.Z - bounds.Z;
            }
 
#if NEVER
            // Because we do not store rectangles as TLRB (+ another dimension in 3D) 
            // we need to compute SizeX/Y/Z which involves subtraction and introduces 
            // cancelation so this assert isn't accurate.
            Debug.Assert(bounds.Contains(point), 
                "Error detect - bounds did not contain point on exit.");
#endif
        }
 /// <summary>
 /// Returns true if either rectangle is inside the other or touching
 /// </summary>
 public static bool OverlapsWith(this Rect3D thisRect, Rect3D rect)
 {
     return thisRect.IntersectsWith(rect) || thisRect.Contains(rect) || rect.Contains(thisRect);
 }