Exemple #1
0
    /// <summary>
    /// Receive an absolute distance along the Path. Returns the Stretch where it lands and
    /// adjust the distance relative to the start of that Stretch. Also reverses d
    /// depending on the Forward value of the Stretch
    /// </summary>
    /// <param name="d"></param>
    /// <returns></returns>
    private int GetStretchAtDistance(ref float d)
    {
        d = Mathf.Clamp(d, 0f, TotalLength);
        float previousStretchesTotalLength = 0f;

        for (int i = 0; i < NStretches; i++)
        {
            Stretch st = GetNStretch(i);
            if (st.GetLength() >= d)
            {
                d -= previousStretchesTotalLength;
                if (!IsStretchNForward(i))
                {
                    d = st.GetLength() - d;
                }
                return(i);
            }
            else
            {
                previousStretchesTotalLength += st.GetLength();
            }
        }

        return(NStretches - 1);
    }
Exemple #2
0
 private static void UpdateDistances(NodeNetCreator net, DijkstraNode current)
 {
     foreach (var dn in dNodes)
     {
         Stretch st = net.GetStretch(current.node, dn.node);
         if (st != null && !dn.visited)
         {
             float possibleNewDistance = current.distance + st.GetLength();
             if (possibleNewDistance < dn.distance)
             {
                 dn.distance = possibleNewDistance;
                 dn.parent   = current;
             }
         }
     }
     current.visited = true;
 }