78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System.Drawing;
|
|
|
|
namespace View_by_Distance.Shared.Models.Stateless;
|
|
|
|
internal abstract class Location
|
|
{
|
|
|
|
internal static bool Check(int bottom, int left, int right, int top, int zCount, bool throwException)
|
|
{
|
|
bool result = true;
|
|
if (left < 0)
|
|
result = false;
|
|
if (right < 0)
|
|
result = false;
|
|
if (right < left)
|
|
result = false;
|
|
if (top < 0)
|
|
result = false;
|
|
if (bottom < 0)
|
|
result = false;
|
|
if (bottom < top)
|
|
result = false;
|
|
if (zCount < 0)
|
|
result = false;
|
|
if (throwException && !result)
|
|
throw new Exception();
|
|
return result;
|
|
}
|
|
|
|
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)
|
|
result = false;
|
|
if (left > width)
|
|
result = false;
|
|
if (right > width)
|
|
result = false;
|
|
if (top > height)
|
|
result = false;
|
|
if (zCount < 0)
|
|
result = false;
|
|
if (result)
|
|
result = Check(bottom, left, right, top, zCount, throwException);
|
|
if (throwException && !result)
|
|
throw new Exception();
|
|
return result;
|
|
}
|
|
|
|
internal static RectangleF? GetPercentagesRectangle(DistanceSettings distanceSettings, int wholePercentages)
|
|
{
|
|
RectangleF? result;
|
|
string wp = wholePercentages.ToString();
|
|
int length = (distanceSettings.LocationDigits - 1) / 4;
|
|
string[] segments =
|
|
[
|
|
wp[..1],
|
|
wp.Substring(1, length),
|
|
wp.Substring(3, length),
|
|
wp.Substring(5, length),
|
|
wp.Substring(7, length)
|
|
];
|
|
if (string.Join(string.Empty, segments) != wp)
|
|
result = null;
|
|
else
|
|
{
|
|
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
|
|
{
|
|
float factor = 100;
|
|
result = new(xWholePercent / factor, yWholePercent / factor, wWholePercent / factor, hWholePercent / factor);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} |