當前位置: 首頁>>代碼示例>>C#>>正文


C# Rectangle.Area方法代碼示例

本文整理匯總了C#中System.Drawing.Rectangle.Area方法的典型用法代碼示例。如果您正苦於以下問題:C# Rectangle.Area方法的具體用法?C# Rectangle.Area怎麽用?C# Rectangle.Area使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Rectangle的用法示例。


在下文中一共展示了Rectangle.Area方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Overlap

 /// <summary>
 /// Two cells overlap if their bounding rectangle overlap by more than 50% of their area.
 /// </summary>
 /// <param name="rectangle1">The bounding rectangle of the first cell</param>
 /// <param name="rectangle2">The bounding rectangle of the second cell</param>
 /// <returns>Returns true if either rectangle overlaps the other by more than 50% of its surface.</returns>
 protected override bool Overlap(Rectangle rectangle1, Rectangle rectangle2)
 {
     // The rationale is that we want to provide a rectangular view over
     // cells of various shape, that might be embedded in a same square.
     Decimal overlapArea = rectangle1.Overlap(rectangle2);
     return Math.Max((overlapArea / rectangle1.Area()), (overlapArea / rectangle2.Area())) >= (decimal)0.5;
 }
開發者ID:fpicalausa,項目名稱:mangareader,代碼行數:13,代碼來源:CellsView.cs

示例2: AreaChangeAsPercent

        /// <summary>
        /// Determines the area change from the first rectangle to the second.
        /// </summary>
        /// <param name="r1">The first rectangle.</param>
        /// <param name="r2">The second rectangle.</param>
        /// <returns>A percentage indicating area change.</returns>
        public static decimal AreaChangeAsPercent(Rectangle r1, Rectangle r2)
        {
            var minWidth = Math.Min(r1.Width, r2.Width);
            var minHeight = Math.Min(r1.Height, r2.Height);
            var maxWidth = Math.Max(r1.Width, r2.Width);
            var maxHeight = Math.Max(r1.Height, r2.Height);
            var startingArea = r1.Area();

            long areaDelta = 0;
            if (r1.Width != r2.Width) areaDelta += ((maxWidth - minWidth) * minHeight);
            if (r1.Height != r2.Height) areaDelta += ((maxHeight - minHeight) * minWidth);
            if ((r1.Height > r2.Height && r1.Width > r2.Width) ||
                (r2.Height > r1.Height && r2.Width > r1.Width)) areaDelta += ((maxHeight - minHeight) * (maxWidth - minWidth));

            return areaDelta == 0 ? 0 : ((decimal)areaDelta / startingArea) * 100;
        }
開發者ID:Ancestry,項目名稱:quality-bot,代碼行數:22,代碼來源:RectangleUtil.cs

示例3: GetLocationChanges

        /// <summary>
        /// Returns the difference between two rectangles as a string description.
        /// </summary>
        /// <param name="r1">The first rectangle.</param>
        /// <param name="r2">The second rectangle.</param>
        /// <param name="percentageChange">The change as a percentage.</param>
        /// <returns>A string description.</returns>
        private static string GetLocationChanges(Rectangle r1, Rectangle r2, out decimal percentageChange)
        {
            var sb = new System.Text.StringBuilder();

            if (r1.Width != r2.Width)
            {
                sb.AppendLine(string.Format("Element width {0} by {1} pixels", r1.Width > r2.Width ? "decreased" : "increased", Math.Abs(r1.Width - r2.Width)));
            }

            if (r1.Height != r2.Height)
            {
                sb.AppendLine(string.Format("Element height {0} by {1} pixels", r1.Height > r2.Height ? "decreased" : "increased", Math.Abs(r1.Height - r2.Height)));
            }

            if (r1.X != r2.X)
            {
                sb.AppendLine(string.Format("Element moved {0} {1} pixels", r1.X > r2.X ? "left" : "right", Math.Abs(r1.X - r2.X)));
            }

            if (r1.Y != r2.Y)
            {
                sb.AppendLine(string.Format("Element moved {0} {1} pixels", r1.Y > r2.Y ? "up" : "down", Math.Abs(r1.Y - r2.Y)));
            }

            var commonArea = Rectangle.Intersect(r1, r2).Area();
            percentageChange = commonArea > 0 ? (commonArea / (decimal)r1.Area()) * 100 : 100;

            return sb.ToString();
        }
開發者ID:Ancestry,項目名稱:quality-bot,代碼行數:36,代碼來源:Comparer.cs

示例4: AreaDifferenceBetweenRectangles

 /// <summary>
 /// Calculates the area difference between two rectangles.
 /// </summary>
 /// <param name="r1">The first rectangle.</param>
 /// <param name="r2">The second rectangle.</param>
 /// <returns>A long value.</returns>
 public static long AreaDifferenceBetweenRectangles(Rectangle r1, Rectangle r2)
 {
     return Math.Abs(r1.Area() - r2.Area());
 }
開發者ID:Ancestry,項目名稱:quality-bot,代碼行數:10,代碼來源:RectangleUtil.cs


注:本文中的System.Drawing.Rectangle.Area方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。