Proper way to check snap distance

This commit is contained in:
Jaex 2016-06-25 10:44:39 +03:00
parent e7723e48f6
commit b166fe2ef6

View file

@ -1275,26 +1275,27 @@ private void OpenOptionsMenu()
private Point SnapPosition(Point posOnClick, Point posCurrent)
{
Rectangle currentRect = CaptureHelpers.CreateRectangle(posOnClick, posCurrent);
Point newPosition = posCurrent;
Size currentSize = CaptureHelpers.CreateRectangle(posOnClick, posCurrent).Size;
Vector2 vector = new Vector2(currentSize.Width, currentSize.Height);
foreach (SnapSize size in Config.SnapSizes)
SnapSize snapSize = (from size in Config.SnapSizes
let distance = MathHelpers.Distance(vector, new Vector2(size.Width, size.Height))
where distance > 0 && distance < Config.SnapDistance
orderby distance
select size).FirstOrDefault();
if (snapSize != null)
{
if (currentRect.Width.IsBetween(size.Width - Config.SnapDistance, size.Width + Config.SnapDistance) ||
currentRect.Height.IsBetween(size.Height - Config.SnapDistance, size.Height + Config.SnapDistance))
Point posNew = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, snapSize);
Rectangle newRect = CaptureHelpers.CreateRectangle(posOnClick, posNew);
if (form.ScreenRectangle0Based.Contains(newRect))
{
newPosition = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, size);
break;
return posNew;
}
}
Rectangle newRect = CaptureHelpers.CreateRectangle(posOnClick, newPosition);
if (form.ScreenRectangle0Based.Contains(newRect))
{
return newPosition;
}
return posCurrent;
}