当前位置: 首页>>代码示例>>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;未经允许,请勿转载。