using System.Diagnostics; using System.Windows; namespace HKW.HKWUtils; /// /// 可观察地点 /// [DebuggerDisplay("X = {X}, Y = {Y}")] public class ObservablePoint : ObservableClass, IEquatable { private double _x; public double X { get => _x; set => SetProperty(ref _x, value); } private double _y; public double Y { get => _y; set => SetProperty(ref _y, value); } public ObservablePoint() { } public ObservablePoint(double x, double y) { X = x; Y = y; } /// /// 复制一个新的对象 /// /// 新对象 public ObservablePoint Copy() { return new(X, Y); } public Point ToPoint() { return new Point(X, Y); } #region Other /// public override int GetHashCode() { return HashCode.Combine(X, Y); } /// public override bool Equals(object? obj) { return obj is ObservablePoint temp && EqualityComparer.Default.Equals(X, temp.X) && EqualityComparer.Default.Equals(Y, temp.Y); } /// public bool Equals(ObservablePoint? other) { return Equals(obj: other); } /// public static bool operator ==(ObservablePoint a, ObservablePoint b) { return Equals(a, b); } /// public static bool operator !=(ObservablePoint a, ObservablePoint b) { return Equals(a, b) is not true; } #endregion } public class ObservablePointToPointConverter : ReflectionConverterBase { public override Point Convert(ObservablePoint sourceValue) { return new(sourceValue.X, sourceValue.Y); } public override ObservablePoint ConvertBack(Point targetValue) { return new(targetValue.X, targetValue.Y); } } ///// ///// 可观察地点 ///// ///// 类型 //public class ObservablePoint // : ObservableClass>, // IEquatable> //{ // 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; // } // /// // /// 复制一个新的对象 // /// // /// 新对象 // public ObservablePoint Copy() // { // return new(X, Y); // } // #region Create // public static ObservablePoint Create(Point point) // { // return new(point.X, point.Y); // } // #endregion // #region Other // /// // public override int GetHashCode() // { // return HashCode.Combine(X, Y); // } // /// // public override bool Equals(object? obj) // { // return obj is ObservablePoint temp // && EqualityComparer.Default.Equals(X, temp.X) // && EqualityComparer.Default.Equals(Y, temp.Y); // } // /// // public bool Equals(ObservablePoint? other) // { // return Equals(obj: other); // } // /// // public static bool operator ==(ObservablePoint a, ObservablePoint b) // { // return Equals(a, b); // } // /// // public static bool operator !=(ObservablePoint a, ObservablePoint b) // { // return Equals(a, b) is not true; // } // #endregion //}