namespace Yw.WinFrmUI.Phart
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class Point2dComparer
|
{
|
/// <summary>
|
/// 排序类型
|
/// </summary>
|
public enum eSortType
|
{
|
X,
|
Y
|
}
|
|
/// <summary>
|
/// 相等类型
|
/// </summary>
|
public enum eEqualType
|
{
|
X,
|
Y,
|
ALL
|
}
|
|
/// <summary>
|
/// 排序比较
|
/// </summary>
|
public class Sort : IComparer<Yw.Geometry.Point2d>
|
{
|
public Sort(eSortType sortType)
|
{
|
_sortType = sortType;
|
}
|
|
private const double _ignore = 0.0001;
|
private eSortType _sortType;
|
|
int IComparer<Yw.Geometry.Point2d>.Compare(Yw.Geometry.Point2d obj1, Yw.Geometry.Point2d obj2)
|
{
|
if (_sortType == eSortType.X)
|
{
|
if (Math.Abs(obj1.X - obj2.X) < _ignore)
|
{
|
return 0;
|
}
|
else if (obj1.X > obj2.X)
|
{
|
return 1;
|
}
|
else
|
{
|
return -1;
|
}
|
}
|
else
|
{
|
if (Math.Abs(obj1.Y - obj2.Y) < _ignore)
|
{
|
return 0;
|
}
|
else if (obj1.Y > obj2.Y)
|
{
|
return 1;
|
}
|
else
|
{
|
return -1;
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 相等比较
|
/// </summary>
|
public class Equal : IEqualityComparer<Yw.Geometry.Point2d>
|
{
|
public Equal()
|
{
|
|
}
|
public Equal(double ignore, eEqualType equipualType)
|
{
|
this._ignore = ignore;
|
this._equipualType = equipualType;
|
}
|
|
private double _ignore = 0.001;
|
private eEqualType _equipualType = eEqualType.X;
|
|
public bool Equals(Yw.Geometry.Point2d lhs, Yw.Geometry.Point2d rhs)
|
{
|
switch (_equipualType)
|
{
|
case eEqualType.X:
|
if (Math.Abs(lhs.X - rhs.X) < _ignore)
|
return true;
|
break;
|
case eEqualType.Y:
|
if (Math.Abs(lhs.Y - rhs.Y) < _ignore)
|
return true;
|
break;
|
case eEqualType.ALL:
|
if (Math.Abs(lhs.X - rhs.X) < _ignore && Math.Abs(lhs.Y - rhs.Y) < _ignore)
|
return true;
|
break;
|
}
|
return false;
|
}
|
|
public int GetHashCode(Yw.Geometry.Point2d obj)
|
{
|
return 0;
|
}
|
|
}
|
}
|
}
|