Mass push
This commit is contained in:
.vscode
Compare
Date-Group
Delete-By-Relative
.vscode
Delete-By-Relative.csprojDeleteByRelative.csModels
Program.csappsettings.Development.jsonappsettings.jsonDistance
Drag-Drop
Duplicate-Search
.vscode
Duplicate-Search.csprojDuplicateSearch.csModels
Program.csappsettings.Development.jsonappsettings.jsonFace
FaceParts
FaceRecognitionDotNet
Instance
DlibDotNet.csInstance.csproj
Models
Program.csappsettings.Development.jsonappsettings.Staging.jsonappsettings.jsonMap
Metadata
Not-Copy-Copy
PrepareForOld
Property-Compare
Property
Models
Property.csprojResize
Shared
Models
FaceDistance.csFileHolder.csItem.csLocation.csMapping.csMarker.csMarkerWith.cs
View-by-Distance.Shared.csprojProperties
IFaceDistance.csIItem.csIMapping.csIProperty.csIPropertyConfiguration.csIRelativeLocation.csISorting.cs
Property.csRelativeLocation.csSorting.csSortingContainer.csStateless
Tests
Models
Tests.csprojUnitTestCalculations.csUnitTestExample.csUnitTestIsEnvironment.csUnitTestResize.csTestsWithFaceRecognitionDotNet
View-by-Distance-MKLink-Console.sln@ -3,37 +3,46 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract class Location
|
||||
{
|
||||
|
||||
internal static void Check(int bottom, int left, int right, int top, int zCount)
|
||||
internal static bool Check(int bottom, int left, int right, int top, int zCount, bool throwException)
|
||||
{
|
||||
bool result = true;
|
||||
if (left < 0)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (right < 0)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (right < left)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (top < 0)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (bottom < 0)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (bottom < top)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (zCount < 0)
|
||||
result = false;
|
||||
if (throwException && !result)
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
|
||||
internal static bool Check(int bottom, int height, int left, int right, int top, int width, int zCount, bool throwException)
|
||||
{
|
||||
bool result = true;
|
||||
if (bottom > height)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (left > width)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (right > width)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (top > height)
|
||||
throw new Exception();
|
||||
result = false;
|
||||
if (zCount < 0)
|
||||
result = false;
|
||||
if (result)
|
||||
result = Check(bottom, left, right, top, zCount, throwException);
|
||||
if (throwException && !result)
|
||||
throw new Exception();
|
||||
Check(bottom, left, right, top, zCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetLeftPadded(int locationDigits, string value)
|
||||
@ -48,54 +57,89 @@ internal abstract class Location
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
|
||||
internal static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(int bottom, int height, int left, int right, int top, int width, int zCount)
|
||||
{
|
||||
int result;
|
||||
Check(bottom, height, left, right, top, width, zCount);
|
||||
long check;
|
||||
int checksum;
|
||||
(decimal?, decimal?, decimal?, decimal?) result;
|
||||
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
|
||||
decimal t = top;
|
||||
decimal l = left;
|
||||
decimal w = right - l;
|
||||
decimal h = bottom - t;
|
||||
decimal xHeightPercentageFactored = h / height;
|
||||
decimal xLeftPercentageFactored = l / width;
|
||||
decimal xTopPercentageFactored = t / height;
|
||||
decimal xWidthPercentageFactored = w / width;
|
||||
if (!verified)
|
||||
result = new(null, null, null, null);
|
||||
else
|
||||
result = new(xHeightPercentageFactored, xLeftPercentageFactored, xTopPercentageFactored, xWidthPercentageFactored);
|
||||
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;
|
||||
string yCenterPadded;
|
||||
decimal factor = locationFactor;
|
||||
// int.MaxPercentage = 21 4748 3647;
|
||||
int length = (locationDigits - 1) / 2;
|
||||
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
|
||||
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 (yCenterRounded != factor)
|
||||
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded);
|
||||
if (!verified)
|
||||
result = new(null, null);
|
||||
else
|
||||
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded - 1);
|
||||
if (xCenterRounded != factor)
|
||||
check = long.Parse(string.Concat(xCenterRounded, yCenterPadded, checksum));
|
||||
else
|
||||
check = long.Parse(string.Concat(xCenterRounded - 1, yCenterPadded, checksum));
|
||||
if (check > int.MaxValue)
|
||||
throw new Exception();
|
||||
result = (int)check;
|
||||
result = new(xCenterRounded, yCenterRounded);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage)
|
||||
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
|
||||
{
|
||||
int result;
|
||||
string check;
|
||||
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
|
||||
int checksum = left > top ? 4 : 8;
|
||||
if (!verified)
|
||||
check = string.Concat(checksum, new string('0', locationDigits - 1));
|
||||
else
|
||||
{
|
||||
decimal factor = 100;
|
||||
int factorMinusOne = (int)factor - 1;
|
||||
// int.MaxPercentage = 21 47 48 36 47;
|
||||
int length = (locationDigits - 1) / 4;
|
||||
// Rectangle rectangle=new(x, y, width, h);
|
||||
decimal x = left / (decimal)width * factor;
|
||||
decimal y = top / (decimal)height * factor;
|
||||
decimal w = (right - left) / (decimal)width * factor;
|
||||
decimal h = (bottom - top) / (decimal)height * factor;
|
||||
string xPadded = x < factor ? ILocation.GetLeftPadded(length, (int)x) : ILocation.GetLeftPadded(length, factorMinusOne);
|
||||
string yPadded = y < factor ? ILocation.GetLeftPadded(length, (int)y) : ILocation.GetLeftPadded(length, factorMinusOne);
|
||||
string widthPadded = w < factor ? ILocation.GetLeftPadded(length, (int)w) : ILocation.GetLeftPadded(length, factorMinusOne);
|
||||
string heightPadded = h < factor ? ILocation.GetLeftPadded(length, (int)h) : ILocation.GetLeftPadded(length, factorMinusOne);
|
||||
check = string.Concat(checksum, xPadded, yPadded, widthPadded, heightPadded);
|
||||
}
|
||||
long value = long.Parse(check);
|
||||
if (value > int.MaxValue)
|
||||
throw new Exception();
|
||||
result = (int)value;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle)
|
||||
{
|
||||
int? x;
|
||||
int? y;
|
||||
int center = 2;
|
||||
decimal factor = locationFactor;
|
||||
int each = (locationDigits - 1) / center;
|
||||
string segmentA = normalizedPixelPercentage[..each];
|
||||
string segmentB = normalizedPixelPercentage[each..^1];
|
||||
string segmentA = normalizedRectangle[..each];
|
||||
string segmentB = normalizedRectangle[each..^1];
|
||||
if (!int.TryParse(segmentA, out int xNormalized) || !int.TryParse(segmentB, out int yNormalized))
|
||||
{
|
||||
x = null;
|
||||
|
Reference in New Issue
Block a user