62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System.Drawing;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace View_by_Distance.Shared.Models;
|
|
|
|
public class FacePoint : Properties.IFacePoint
|
|
{
|
|
|
|
protected int _Index;
|
|
protected int _X;
|
|
protected int _Y;
|
|
public int Index => _Index;
|
|
public int X => _X;
|
|
public int Y => _Y;
|
|
|
|
private readonly Point _Point;
|
|
|
|
[JsonConstructor]
|
|
public FacePoint(int index, int x, int y)
|
|
{
|
|
_Index = index;
|
|
_X = x;
|
|
_Y = y;
|
|
_Point = new(x, y);
|
|
}
|
|
|
|
public FacePoint(Point point, int index) :
|
|
this(index, point.X, point.Y)
|
|
{ }
|
|
|
|
public override bool Equals(object? obj) => obj is FacePoint point && Equals(point);
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
|
|
#pragma warning disable IDE0070
|
|
public override int GetHashCode()
|
|
#pragma warning restore IDE0070
|
|
{
|
|
int hashCode = 1861411795;
|
|
hashCode = hashCode * -1521134295 + _Point.GetHashCode();
|
|
hashCode = hashCode * -1521134295 + _Index.GetHashCode();
|
|
return hashCode;
|
|
}
|
|
|
|
public bool Equals(FacePoint? facePoint)
|
|
{
|
|
return facePoint is not null
|
|
&& _X == facePoint.X
|
|
&& _Y == facePoint.Y
|
|
&& _Index == facePoint.Index;
|
|
}
|
|
|
|
public static bool operator ==(FacePoint point1, FacePoint point2) => point1.Equals(point2);
|
|
|
|
public static bool operator !=(FacePoint point1, FacePoint point2) => !(point1 == point2);
|
|
|
|
} |