Sorting without ... improvements

This commit is contained in:
2022-12-21 22:54:50 -07:00
parent 44d8eaf5fb
commit 2da3db7aa5
25 changed files with 353 additions and 358 deletions

View File

@ -1,3 +1,5 @@
using System.Drawing;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
@ -76,29 +78,6 @@ internal abstract class Location
return result;
}
internal static (int?, int?) GetCenterRoundedXY(int bottom, int height, int left, int locationFactor, int right, int top, int width, int zCount)
{
(int?, int?) result;
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
decimal center = 2m;
decimal factor = locationFactor;
decimal xCenterValue = (left + right) / center;
decimal yCenterValue = (top + bottom) / center;
if (xCenterValue < left || xCenterValue > right)
throw new Exception();
if (yCenterValue < top || yCenterValue > bottom)
throw new Exception();
decimal xCenterPercentageFactored = xCenterValue / width * factor;
decimal yCenterPercentageFactored = yCenterValue / height * factor;
int xCenterRounded = (int)Math.Round(xCenterPercentageFactored, 0);
int yCenterRounded = (int)Math.Round(yCenterPercentageFactored, 0);
if (!verified)
result = new(null, null);
else
result = new(xCenterRounded, yCenterRounded);
return result;
}
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
{
int result;
@ -160,4 +139,54 @@ internal abstract class Location
int result = (int)(confidence / rangeFaceConfidence[1] * faceConfidencePercent);
return result;
}
private static Rectangle? GetRectangle(int locationDigits, int height, string normalizedRectangle, int width)
{
Rectangle? result;
int length = (locationDigits - 1) / 4;
string[] segments = new string[]
{
normalizedRectangle[..1],
normalizedRectangle.Substring(1, length),
normalizedRectangle.Substring(3, length),
normalizedRectangle.Substring(5, length),
normalizedRectangle.Substring(7, length)
};
if (string.Join(string.Empty, segments) != normalizedRectangle)
result = null;
else
{
if (!int.TryParse(segments[1], out int xNormalized) || !int.TryParse(segments[2], out int yNormalized) || !int.TryParse(segments[3], out int wNormalized) || !int.TryParse(segments[4], out int hNormalized))
result = null;
else
{
decimal factor = 100;
result = new((int)(xNormalized / factor * width), (int)(yNormalized / factor * height), (int)(wNormalized / factor * width), (int)(hNormalized / factor * height));
}
}
return result;
}
internal static Rectangle GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangleValue, int height, int width, bool useOldWay)
{
Rectangle? result;
string normalizedRectangle = normalizedRectangleValue.ToString();
if (normalizedRectangle.Length != locationDigits)
throw new NotImplementedException();
if (!useOldWay)
{
result = GetRectangle(locationDigits, height, normalizedRectangle, width);
if (result is null)
throw new NullReferenceException(nameof(result));
}
else
{
(int? x, int? y) = GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
if (x is null || y is null)
throw new Exception();
result = new(x.Value - (checkRectangle.Width / 2), y.Value - (checkRectangle.Height / 2), checkRectangle.Width, checkRectangle.Height);
}
return result.Value;
}
}