Beispiel #1
0
 public static Rectanglef Intersect(Rectanglef rect1, Rectanglef rect2)
 {
     Rectanglef result;
     if (rect1.Contains(rect2))
         result = new Rectanglef(rect2);
     else if (rect2.Contains(rect1))
         result = new Rectanglef(rect1);
     else if (!rect1.Intersects(rect2))
         result = new Rectanglef();
     else
     {
         result = new Rectanglef(
             Math.Max(rect1.X, rect2.X),
             Math.Max(rect1.Y, rect2.Y),
             Math.Min(rect1.Right, rect2.Right) - Math.Max(rect1.Left, rect2.Left),
             Math.Min(rect1.Bottom, rect2.Bottom) - Math.Max(rect1.Top, rect2.Top));
     }
     return result;
 }
Beispiel #2
0
 public static void Intersect(ref Rectanglef rect1, ref Rectanglef rect2, out Rectanglef result)
 {
     if (rect1.Contains(rect2))
         result = new Rectanglef(rect2);
     else if (rect2.Contains(rect1))
         result = new Rectanglef(rect1);
     else if (!rect1.Intersects(rect2))
         result = new Rectanglef();
     else
     {
         result = new Rectanglef(
             Math.Max(rect1.X, rect2.X),
             Math.Max(rect1.Y, rect2.Y),
             Math.Min(rect1.Right, rect2.Right) - Math.Max(rect1.Left, rect2.Left),
             Math.Min(rect1.Bottom, rect2.Bottom) - Math.Max(rect1.Top, rect2.Top));
     }
 }