public Edge GetEdge(BendyLayer layer)
        {
            if (_from == null || _to == null)
            {
                return(null);
            }
            if (_edgeCache != null && _edgeCache.Graph == layer && _edgeCache.InScene)
            {
                return(_edgeCache);
            }
            var fromNode = layer.GetNode(_from.Value);

            if (fromNode == null)
            {
                return(null);
            }
            var toNode = layer.GetNode(_to.Value);

            if (toNode == null)
            {
                return(null);
            }
            return(_edgeCache = layer.GetEdge(fromNode, toNode));
        }
        public static void AnnotateNodes(BendyLayer layer, IList <AnnotatedNode> nodes)
        {
            for (var i = 0; i < nodes.Count; i++)
            {
                var here = layer?.GetNode(nodes[i].Position);
                var tmp  = nodes[i];
                tmp.Position = here?.Position ?? nodes[i].Position;
                tmp.Existing = here;
                tmp.Up       = here?.Up ?? nodes[i].Up;
                nodes[i]     = tmp;
            }

            for (var i = 0; i < nodes.Count; i++)
            {
                var a       = nodes[i];
                var tanHere = Vector3.Zero;
                if (a.Existing != null)
                {
                    tanHere = a.Existing.Tangent * a.Existing.Neighbors.Count();
                }

                if (i > 0 && (nodes[i - 1].Existing == null || a.Existing?.ConnectionTo(nodes[i - 1].Existing) == null))
                {
                    var tP = Vector3.Normalize(nodes[i - 1].Position - a.Position);
                    if (tP.Dot(tanHere) < 0)
                    {
                        tP = -tP;
                    }
                    tanHere += tP;
                }

                // ReSharper disable once InvertIf
                if (i + 1 < nodes.Count && (nodes[i + 1].Existing == null || a.Existing?.ConnectionTo(nodes[i + 1].Existing) == null))
                {
                    var tP = Vector3.Normalize(nodes[i + 1].Position - a.Position);
                    if (tP.Dot(tanHere) < 0)
                    {
                        tP = -tP;
                    }
                    tanHere += tP;
                }

                a.Tangent = Vector3.Normalize(tanHere.LengthSquared() > 0 ? tanHere : Vector3.CalculatePerpendicularVector(nodes[i].Up));
                nodes[i]  = a;
            }
        }