本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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());
}