VPet/VPet.Solution/Utils/ObservablePoint.cs

182 lines
3.8 KiB
C#
Raw Normal View History

2023-12-30 14:54:49 +00:00
using System.Diagnostics;
using System.Windows;
namespace HKW.HKWUtils;
2023-12-18 14:53:56 +00:00
/// <summary>
/// 可观察地点
/// </summary>
2023-12-30 14:54:49 +00:00
[DebuggerDisplay("X = {X}, Y = {Y}")]
public class ObservablePoint : ObservableClass<ObservablePoint>, IEquatable<ObservablePoint>
2023-12-18 14:53:56 +00:00
{
2023-12-30 14:54:49 +00:00
private double _x;
public double X
2023-12-18 14:53:56 +00:00
{
get => _x;
set => SetProperty(ref _x, value);
}
2023-12-30 14:54:49 +00:00
private double _y;
public double Y
2023-12-18 14:53:56 +00:00
{
get => _y;
set => SetProperty(ref _y, value);
}
public ObservablePoint() { }
2023-12-30 14:54:49 +00:00
public ObservablePoint(double x, double y)
2023-12-18 14:53:56 +00:00
{
X = x;
Y = y;
}
/// <summary>
/// 复制一个新的对象
/// </summary>
/// <returns>新对象</returns>
2023-12-30 14:54:49 +00:00
public ObservablePoint Copy()
2023-12-18 14:53:56 +00:00
{
return new(X, Y);
}
2024-01-09 15:22:25 +00:00
public Point ToPoint()
{
return new Point(X, Y);
}
2023-12-18 14:53:56 +00:00
#region Other
/// <inheritdoc/>
public override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
/// <inheritdoc/>
public override bool Equals(object? obj)
{
2023-12-30 14:54:49 +00:00
return obj is ObservablePoint temp
&& EqualityComparer<double>.Default.Equals(X, temp.X)
&& EqualityComparer<double>.Default.Equals(Y, temp.Y);
2023-12-18 14:53:56 +00:00
}
/// <inheritdoc/>
2023-12-30 14:54:49 +00:00
public bool Equals(ObservablePoint? other)
2023-12-18 14:53:56 +00:00
{
return Equals(obj: other);
}
/// <inheritdoc/>
2023-12-30 14:54:49 +00:00
public static bool operator ==(ObservablePoint a, ObservablePoint b)
2023-12-18 14:53:56 +00:00
{
return Equals(a, b);
}
/// <inheritdoc/>
2023-12-30 14:54:49 +00:00
public static bool operator !=(ObservablePoint a, ObservablePoint b)
2023-12-18 14:53:56 +00:00
{
return Equals(a, b) is not true;
}
#endregion
}
2023-12-30 14:54:49 +00:00
2024-01-10 13:37:17 +00:00
public class ObservablePointToPointConverter : ReflectionConverterBase<ObservablePoint, Point>
{
public override Point Convert(ObservablePoint sourceValue)
{
return new(sourceValue.X, sourceValue.Y);
}
public override ObservablePoint ConvertBack(Point targetValue)
{
return new(targetValue.X, targetValue.Y);
}
}
2023-12-30 14:54:49 +00:00
///// <summary>
///// 可观察地点
///// </summary>
///// <typeparam name="T">类型</typeparam>
//public class ObservablePoint<T>
// : ObservableClass<ObservablePoint<T>>,
// IEquatable<ObservablePoint<T>>
//{
// private T _x;
// public T X
// {
// get => _x;
// set => SetProperty(ref _x, value);
// }
// private T _y;
// public T Y
// {
// get => _y;
// set => SetProperty(ref _y, value);
// }
// public ObservablePoint() { }
// public ObservablePoint(T x, T y)
// {
// X = x;
// Y = y;
// }
// /// <summary>
// /// 复制一个新的对象
// /// </summary>
// /// <returns>新对象</returns>
// public ObservablePoint<T> Copy()
// {
// return new(X, Y);
// }
// #region Create
// public static ObservablePoint<double> Create(Point point)
// {
// return new(point.X, point.Y);
// }
// #endregion
// #region Other
// /// <inheritdoc/>
// public override int GetHashCode()
// {
// return HashCode.Combine(X, Y);
// }
// /// <inheritdoc/>
// public override bool Equals(object? obj)
// {
// return obj is ObservablePoint<T> temp
// && EqualityComparer<T>.Default.Equals(X, temp.X)
// && EqualityComparer<T>.Default.Equals(Y, temp.Y);
// }
// /// <inheritdoc/>
// public bool Equals(ObservablePoint<T>? other)
// {
// return Equals(obj: other);
// }
// /// <inheritdoc/>
// public static bool operator ==(ObservablePoint<T> a, ObservablePoint<T> b)
// {
// return Equals(a, b);
// }
// /// <inheritdoc/>
// public static bool operator !=(ObservablePoint<T> a, ObservablePoint<T> b)
// {
// return Equals(a, b) is not true;
// }
// #endregion
//}