Get Unable to Match Count and Rename Matches
This commit is contained in:
@ -33,26 +33,25 @@ internal abstract class Location
|
||||
throw new Exception();
|
||||
if (zCount < 0)
|
||||
throw new Exception();
|
||||
Check(bottom, left, right, top, zCount);
|
||||
}
|
||||
|
||||
internal static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
|
||||
internal static string GetLeftPadded(int locationDigits, string value)
|
||||
{
|
||||
Check(bottom, left, right, top, zCount);
|
||||
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
internal 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();
|
||||
string result;
|
||||
if (value.Length == locationDigits)
|
||||
result = value;
|
||||
else if (value.Length > locationDigits)
|
||||
result = value[..locationDigits];
|
||||
else
|
||||
result = value.PadLeft(locationDigits, '0');
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
|
||||
{
|
||||
int result;
|
||||
Check(bottom, height, left, right, top, width, zCount);
|
||||
int checksum;
|
||||
decimal center = 2m;
|
||||
string xCenterPadded;
|
||||
@ -60,10 +59,12 @@ internal abstract class Location
|
||||
decimal factor = locationFactor;
|
||||
// int.MaxPercentage = 21 4748 3647;
|
||||
int length = (locationDigits - 1) / 2;
|
||||
Check(bottom, left, right, top, zCount);
|
||||
Check(bottom, height, left, right, top, width, zCount);
|
||||
decimal xCenterValue = left + ((right - left) / center);
|
||||
decimal yCenterValue = top + ((bottom - top) / center);
|
||||
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();
|
||||
if (xCenterValue > yCenterValue)
|
||||
checksum = 1;
|
||||
else
|
||||
@ -87,4 +88,28 @@ internal abstract class Location
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage)
|
||||
{
|
||||
int? x;
|
||||
int? y;
|
||||
int center = 2;
|
||||
decimal factor = locationFactor;
|
||||
int each = (locationDigits - 1) / center;
|
||||
string segmentA = normalizedPixelPercentage[..each];
|
||||
string segmentB = normalizedPixelPercentage[each..^1];
|
||||
if (!int.TryParse(segmentA, out int xNormalized) || !int.TryParse(segmentB, out int yNormalized))
|
||||
{
|
||||
x = null;
|
||||
y = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
decimal xValue = xNormalized / factor * width;
|
||||
decimal yValue = yNormalized / factor * height;
|
||||
x = (int)Math.Round(xValue, 0);
|
||||
y = (int)Math.Round(yValue, 0);
|
||||
}
|
||||
return new(x, y);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user