Re-Write without checking mapped

This commit is contained in:
2022-09-14 19:00:57 -07:00
parent 73de1070b8
commit ad28ab2d38
70 changed files with 1596 additions and 2342 deletions

View File

@ -28,16 +28,16 @@ public class Location : Properties.ILocation, IEquatable<Location>
_NormalizedPixelPercentage = normalizedPixelPercentage;
_Right = right;
_Top = top;
Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
Stateless.Methods.Location.Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
}
public Location(double confidence, int height, Location location, int width, int zCount) :
this(location.Bottom, confidence, location.Left, GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
this(location.Bottom, confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
Stateless.Methods.Location.Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
public Location(int bottom, double confidence, int height, int left, int right, int top, int width, int zCount) :
this(bottom, confidence, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
this(bottom, confidence, left, Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
Stateless.Methods.Location.Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
public Location(double confidence, int factor, int height, Location location, int width, int zCount)
{
@ -47,8 +47,8 @@ public class Location : Properties.ILocation, IEquatable<Location>
int left = Math.Max(location.Left - x, 0);
int right = Math.Min(location.Right + x, width);
int top = Math.Max(location.Top - y, 0);
int normalizedPixelPercentage = GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
int normalizedPixelPercentage = Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
Stateless.Methods.Location.Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
_Confidence = confidence;
_Bottom = bottom;
_Left = left;
@ -65,53 +65,6 @@ public class Location : Properties.ILocation, IEquatable<Location>
return result;
}
private static void Check(int bottom, int left, int right, int top, int zCount)
{
if (left < 0)
throw new Exception();
if (right < 0)
throw new Exception();
if (right < left)
throw new Exception();
if (top < 0)
throw new Exception();
if (bottom < 0)
throw new Exception();
if (bottom < top)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
private static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
{
if (bottom > height)
throw new Exception();
if (left > width)
throw new Exception();
if (right > width)
throw new Exception();
if (top > height)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
private static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
{
Check(bottom, left, right, top, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
private static void Check(int bottom, int height, int left, int? normalizedPixelPercentage, int right, int top, int width, int zCount)
{
Check(bottom, left, right, top, zCount);
Check(bottom, height, left, right, top, width, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
public override int GetHashCode()
{
int hashCode = -773114317;
@ -122,22 +75,6 @@ public class Location : Properties.ILocation, IEquatable<Location>
return hashCode;
}
public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount)
{
int result;
double value;
double total = width * height;
Check(bottom, left, right, top, zCount);
double xCenter = left + ((right - left) / 2);
double yCenter = top + ((bottom - top) / 2);
double at = ((yCenter - 1) * width) + xCenter;
value = at / total;
if (value < 0)
value = 3;
result = (int)(Math.Round(value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor);
return result;
}
public bool Equals(Location? location)
{
return location is not null