Tinkr2/4.2/AphelionCore/AphelionCore/Core/TypeDef.cs
/// <summary>
/// Returns the intersection of two rectangles
/// </summary>
/// <param name="region1">Rectangle 1</param>
/// <param name="region2">Rectangle 2</param>
/// <returns>Intersected rectangle</returns>
Returns the intersection of two rectangles
Returns the intersection of two rectangles
public static rect Intersect(rect region1, rect region2)
      {
         if (!region1.Intersects(region2))
         {
            return new rect(0, 0, 0, 0);
         }
         var rct = new rect
         {
            X = (region1.X > region2.X) ? region1.X : region2.X,
            Y = (region1.Y > region2.Y) ? region1.Y : region2.Y
         };
         int r1V2 = region1.X + region1.Width;
         int r2V2 = region2.X + region2.Width;
         rct.Width = (r1V2 < r2V2) ? r1V2 - rct.X : r2V2 - rct.X;
         r1V2 = region1.Y + region1.Height;
         r2V2 = region2.Y + region2.Height;
         rct.Height = (r1V2 < r2V2) ? r1V2 - rct.Y : r2V2 - rct.Y;
         return rct;
      }
public static rect Intersect ( rect region1 , rect region2 ) { if ( ! region1 . Intersects ( region2 ) ) { return new rect ( 0 , 0 , 0 , 0 ) ; } var rct = new rect { X = ( region1 . X > region2 . X ) ? region1 . X : region2 . X , Y = ( region1 . Y > region2 . Y ) ? region1 . Y : region2 . Y } ; int r1V2 = region1 . X + region1 . Width ; int r2V2 = region2 . X + region2 . Width ; rct . Width = ( r1V2 < r2V2 ) ? r1V2 - rct . X : r2V2 - rct . X ; r1V2 = region1 . Y + region1 . Height ; r2V2 = region2 . Y + region2 . Height ; rct . Height = ( r1V2 < r2V2 ) ? r1V2 - rct . Y : r2V2 - rct . Y ; return rct ; }
Returns the intersection of two rectangles
Returns the intersection of two rectangles
// For X1 & Y1 we'll want the highest value // For X2 & Y2 we'll want the lowest value
None
region1
rect
None
region2
rect
None