75 lines
2.3 KiB
C#

using System.Drawing;
using System.Text.Json;
using System.Text.Json.Serialization;
using View_by_Distance.Shared.Models.Methods;
namespace View_by_Distance.Shared.Models;
public class Location : Properties.ILocation, ILocation, IEquatable<Location>
{
protected double _Confidence;
protected int _Bottom;
protected int _Left;
protected int _Right;
protected int _Top;
public double Confidence => _Confidence;
public int Bottom => _Bottom;
public int Left => _Left;
public int Right => _Right;
public int Top => _Top;
[JsonConstructor]
public Location(double confidence, int bottom, int left, int right, int top)
{
_Confidence = confidence;
_Bottom = bottom;
_Left = left;
_Right = right;
_Top = top;
}
public Location(int left, int top, int right, int bottom) :
this(-1.0d, bottom, left, right, top)
{ }
public Location(Rectangle rectangle, double confidence) :
this(-1.0d, rectangle.Bottom, rectangle.Left, rectangle.Right, rectangle.Top)
{ }
public Location(Location location, double confidence) :
this(-1.0d, location.Bottom, location.Left, location.Right, location.Top)
{ }
public override bool Equals(object? obj) => Equals(obj as Location);
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public override int GetHashCode()
{
int hashCode = -773114317;
hashCode = hashCode * -1521134295 + _Bottom.GetHashCode();
hashCode = hashCode * -1521134295 + _Left.GetHashCode();
hashCode = hashCode * -1521134295 + _Right.GetHashCode();
hashCode = hashCode * -1521134295 + _Top.GetHashCode();
return hashCode;
}
public bool Equals(Location? location)
{
return location is not null
&& _Bottom == location.Bottom
&& _Left == location.Left
&& _Right == location.Right
&& _Top == location.Top;
}
public static bool operator ==(Location location1, Location location2) => EqualityComparer<Location>.Default.Equals(location1, location2);
public static bool operator !=(Location location1, Location location2) => !(location1 == location2);
}