protected void UpdateEdgeDirection(object sender, EventArgs e)
{
// Parent coordinates.
var to = _to.Position;
var from = _from.Position;
if (to.IsNaN() || from.IsNaN())
{
this.Visibility = System.Windows.Visibility.Collapsed;
return;
}
var direction = to.Subtract(from);
var length = direction.Magnitude();
Debug.Assert(!double.IsNaN(length));
if (length == 0)
{
this.Visibility = System.Windows.Visibility.Collapsed;
return;
}
this.Visibility = System.Windows.Visibility.Visible;
// Trim according to radii.
var directionUnit = direction.Multiply(1.0 / length);
var fromRadius = _from.ActualRadius * _from.GetRenderScale().Item1;
var toRadius = _to.ActualRadius * _from.GetRenderScale().Item1;
from = from.Add(directionUnit.Multiply(fromRadius));
to = to.Subtract(directionUnit.Multiply(toRadius));
length = Math.Max(length - fromRadius - toRadius, 0.0);
// Resize this arrow.
this.Length = length;
// Position tip.
Canvas.SetLeft(this, to.X);
Canvas.SetTop(this, to.Y);
// Rotate arrow.
double angle = Math.Atan2(direction.Y, direction.X);
RotateTransform transform = (RotateTransform)this.RenderTransform;
transform.Angle = angle * 180.0 / (Math.PI) + 90;
}