コード例 #1
0
ファイル: LRect.cs プロジェクト: yabos/SaveTheQueen
        public static LRect Join(LRect lhs, LRect rhs)
        {
            LPoint start = new LPoint(Math.Min(lhs.left, rhs.left), Math.Min(lhs.top, rhs.top));
            LPoint end   = new LPoint(Math.Max(lhs.Right, rhs.Right), Math.Max(lhs.Bottom, rhs.Bottom));

            return(new LRect(start, end));
        }
コード例 #2
0
ファイル: LRect.cs プロジェクト: yabos/SaveTheQueen
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string) && value is LPoint)
     {
         LRect rt = (LRect)value;
         return(rt.Left + "," + rt.Top + rt.Right + "," + rt.Bottom);
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
コード例 #3
0
ファイル: LRect.cs プロジェクト: yabos/SaveTheQueen
        public bool Include(LRect rect)
        {
            if ((rect.left >= Right) || (rect.Right <= left))
            {
                return(false);
            }

            if ((rect.Bottom <= top) || (rect.top >= Bottom))
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
ファイル: LRect.cs プロジェクト: yabos/SaveTheQueen
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value is string)
     {
         try
         {
             string s = (string)value;
             return(LRect.Parse(s));
         }
         catch { }
         throw new ArgumentException("Can not convert '" + (string)value + "' to type Person");
     }
     return(base.ConvertFrom(context, culture, value));
 }
コード例 #5
0
ファイル: LRect.cs プロジェクト: yabos/SaveTheQueen
        /// Creates a new rectangle that is the intersection of [a] and [b].
        ///
        ///     .----------.
        ///     | a        |
        ///     | .--------+----.
        ///     | | result |  b |
        ///     | |        |    |
        ///     '-+--------'    |
        ///       |             |
        ///       '-------------'
        public static LRect Intersect(LRect lhs, LRect rhs)
        {
            int left  = Math.Max(lhs.left, rhs.left);
            int right = Math.Min(lhs.Right, rhs.Right);

            int top    = Math.Max(lhs.top, rhs.top);
            int bottom = Math.Min(lhs.Bottom, rhs.Bottom);

            //             if (left >= right) return new LRect(0, 0, 0, 0);
            //             if (top >= bottom) return new LRect(0, 0, 0, 0);

            int width  = Math.Max(0, right - left);
            int height = Math.Max(0, bottom - top);

            return(new LRect(new LPoint(left, top), width, height));
        }