Change to the Normalized Pixel Percentage Formula

This commit is contained in:
2022-09-22 23:39:58 -07:00
parent 192d2ad776
commit fb1c68e1f5
27 changed files with 426 additions and 451 deletions

@ -3,25 +3,6 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
{
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, 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, locationDigits) * locationFactor);
string rightPadded = ILocation.GetRightPadded(locationDigits, result);
if (result.ToString() != rightPadded)
result = int.Parse(rightPadded);
return result;
}
internal static void Check(int bottom, int left, int right, int top, int zCount)
{
if (left < 0)
@ -69,4 +50,41 @@ internal abstract class Location
throw new Exception();
}
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
{
int result;
int checksum;
decimal center = 2m;
string xCenterPadded;
string yCenterPadded;
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);
if (xCenterValue > yCenterValue)
checksum = 1;
else
checksum = 2;
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 (xCenterRounded != factor)
xCenterPadded = ILocation.GetLeftPadded(length, xCenterRounded);
else
xCenterPadded = ILocation.GetLeftPadded(length, xCenterRounded - 1);
if (yCenterRounded != factor)
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded);
else
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded - 1);
long check = long.Parse(string.Concat(xCenterPadded, yCenterPadded, checksum));
if (check > int.MaxValue)
throw new Exception();
result = (int)check;
return result;
}
}