WholePercentages

This commit is contained in:
2023-06-21 07:24:32 -07:00
parent 8863fd763f
commit 1d0506d74c
22 changed files with 254 additions and 255 deletions

View File

@ -78,7 +78,7 @@ internal abstract class Location
return result;
}
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
internal static int GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
{
int result;
string check;
@ -114,34 +114,37 @@ internal abstract class Location
return result;
}
internal static Rectangle? GetNormalizedRectangle(int locationDigits, string normalizedRectangle)
internal static Rectangle? GetWholePercentages(int locationDigits, string wholePercentages)
{
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)
wholePercentages[..1],
wholePercentages.Substring(1, length),
wholePercentages.Substring(3, length),
wholePercentages.Substring(5, length),
wholePercentages.Substring(7, length)
};
if (string.Join(string.Empty, segments) != normalizedRectangle)
if (string.Join(string.Empty, segments) != wholePercentages)
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))
if (!int.TryParse(segments[1], out int xWholePercent) || !int.TryParse(segments[2], out int yWholePercent) || !int.TryParse(segments[3], out int wWholePercent) || !int.TryParse(segments[4], out int hWholePercent))
result = null;
else
result = new(xNormalized, yNormalized, wNormalized, hNormalized);
result = new(xWholePercent, yWholePercent, wWholePercent, hWholePercent);
}
return result;
}
internal static Rectangle? GetRectangle(int height, int locationDigits, string normalizedRectangle, int width)
internal static Rectangle? GetRectangle(int locationDigits, Models.OutputResolution outputResolution, string wholePercentages)
{
Rectangle? result;
Rectangle? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle);
if (wholePercentages.Length != locationDigits || wholePercentages[0] is not '4' and not '8')
throw new NotSupportedException("Old way has been removed!");
(int width, int height) = OutputResolution.Get(outputResolution);
Rectangle? rectangle = GetWholePercentages(locationDigits, wholePercentages);
if (rectangle is null)
result = null;
else
@ -149,16 +152,6 @@ internal abstract class Location
decimal factor = 100;
result = new((int)(rectangle.Value.X / factor * width), (int)(rectangle.Value.Y / factor * height), (int)(rectangle.Value.Width / factor * width), (int)(rectangle.Value.Height / factor * height));
}
return result;
}
internal static Rectangle? GetRectangle(int locationDigits, string normalizedRectangle, Models.OutputResolution outputResolution)
{
Rectangle? result;
if (normalizedRectangle.Length != locationDigits || normalizedRectangle[0] is not '4' and not '8')
throw new NotSupportedException("Old way has been removed!");
(int width, int height) = OutputResolution.Get(outputResolution);
result = GetRectangle(height, locationDigits, normalizedRectangle, width);
if (result is null)
throw new NullReferenceException(nameof(result));
return result;
@ -290,7 +283,12 @@ internal abstract class Location
return results;
}
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum)
// private static double GP(OutputResolution outputResolution,Location location, ){
// double result;
// return result;
// }
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages)
{
List<Models.Face> results = new();
double? percent;
@ -302,7 +300,7 @@ internal abstract class Location
if (face.Location is null || face.OutputResolution is null)
continue;
checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
sourceRectangle = GetRectangle(Stateless.ILocation.Digits, normalizedRectangle.ToString(), face.OutputResolution);
sourceRectangle = GetRectangle(Stateless.ILocation.Digits, face.OutputResolution, wholePercentages.ToString());
if (sourceRectangle is null)
continue;
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);