Snap line to every 45 degrees

This commit is contained in:
Jaex 2016-05-24 01:30:23 +03:00
parent 9f7f66d56e
commit 13bde6b875
2 changed files with 18 additions and 1 deletions

View file

@ -282,6 +282,16 @@ public static Point ProportionalPosition(Point pos, Point pos2)
return newPosition;
}
public static Point SnapPositionToDegree(Point pos, Point pos2, float degree, float startDegree)
{
float angle = MathHelpers.LookAtRadian(pos, pos2);
float startAngle = MathHelpers.DegreeToRadian(startDegree);
float snapAngle = MathHelpers.DegreeToRadian(degree);
float newAngle = (float)Math.Round((angle + startAngle) / snapAngle) * snapAngle - startAngle;
float distance = MathHelpers.Distance(pos, pos2);
return (Point)(pos + MathHelpers.RadianToVector2(newAngle, distance));
}
public static Point CalculateNewPosition(Point posOnClick, Point posCurrent, Size size)
{
if (posCurrent.X > posOnClick.X)

View file

@ -935,7 +935,14 @@ public void Update()
if (IsProportionalResizing)
{
newPosition = CaptureHelpers.ProportionalPosition(PositionOnClick, CurrentPosition);
if (shape.NodeType == NodeType.Rectangle)
{
newPosition = CaptureHelpers.SnapPositionToDegree(PositionOnClick, CurrentPosition, 90, 45);
}
else if (shape.NodeType == NodeType.Line)
{
newPosition = CaptureHelpers.SnapPositionToDegree(PositionOnClick, CurrentPosition, 45, 0);
}
}
if (IsSnapResizing)