📄 rectutil.cs
字号:
// Disclaimer and Copyright Information
// RectUtil.cs :
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 1.0
//
// Distribute freely, except: don't remove our name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// softomatix@CommonComponent.com
///////////////////////////////////////////////////////////////////////////////
//
using System;
using System.Drawing;
namespace CommonComponent.CommonChart
{
/// <summary>
/// Summary description for RectUtil.
/// </summary>
public class RectUtil
{
internal RectUtil()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///
/// </summary>
/// <param name="pts"></param>
/// <returns></returns>
internal static Rectangle CalculateBoundingRectanle(Point[] pts)
{
if (pts == null || pts.Length == 0)
{
throw new ArgumentException("Invalid points collection supplied", "pts");
}
int maxX = pts[0].X;
int maxY = pts[0].Y;
int minX = pts[0].X;
int minY = pts[0].Y;
for (int i = 0; i < pts.Length; i++)
{
if (pts[i].X > maxX)
{
maxX = pts[i].X;
}
if (pts[i].X < minX)
{
minX = pts[i].X;
}
if (pts[i].Y > maxY)
{
maxY = pts[i].Y;
}
if (pts[i].Y < minY)
{
minY = pts[i].Y;
}
}
Rectangle rect = new Rectangle();
rect.X = minX;
rect.Y = maxY;
rect.Width = maxX - minY;
rect.Height = maxY - minY;
return rect;
}
/// <summary>
///
/// </summary>
/// <param name="pts"></param>
/// <returns></returns>
internal static RectangleF CalculateBoundingRectanle(PointF[] pts)
{
if (pts == null || pts.Length == 0)
{
throw new ArgumentException("Invalid points collection supplied", "pts");
}
float maxX = pts[0].X;
float maxY = pts[0].Y;
float minX = pts[0].X;
float minY = pts[0].Y;
for (int i = 0; i < pts.Length; i++)
{
if (pts[i].X > maxX)
{
maxX = pts[i].X;
}
if (pts[i].X < minX)
{
minX = pts[i].X;
}
if (pts[i].Y > maxY)
{
maxY = pts[i].Y;
}
if (pts[i].Y < minY)
{
minY = pts[i].Y;
}
}
RectangleF rect = new RectangleF();
rect.X = minX;
rect.Y = maxY;
rect.Width = maxX - minY;
rect.Height = maxY - minY;
return rect;
}
/// <summary>
/// This method is used to return a Rectangle constructed from
/// RectangleF object.
/// </summary>
/// <param name="srcRect"></param>
/// <returns></returns>
internal static Rectangle ConvertToRectangle(RectangleF srcRect)
{
return new Rectangle((int)srcRect.X, (int)srcRect.Y,
(int)srcRect.Width, (int)srcRect.Height);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -