Esempio n. 1
0
        // Split a path into multiple paths based on an array of LegGaps.  The gaps might extend beyond the end of the
        // or the beginning of the path. The gaps array need not be in simplified form.
        public static SymPath[] SplitPathWithGaps(SymPath pathInitial, LegGap[] gaps)
        {
            // Get the length of the path.
            float pathLength = pathInitial.Length;

            // Simply and sort the gaps.
            gaps = SimplifyGaps(gaps, pathLength);

            // If no gaps length, the entire path is correct.
            if (gaps == null)
            {
                return new SymPath[1] {
                           pathInitial
                }
            }
            ;

            // Transform into start/stop distances from beginning of path.
            float[] starts = new float[gaps.Length + 1];
            float[] ends   = new float[gaps.Length + 1];
            starts[0]         = 0;
            ends[gaps.Length] = pathLength;
            for (int i = 0; i < gaps.Length; ++i)
            {
                ends[i]       = gaps[i].distanceFromStart;
                starts[i + 1] = gaps[i].distanceFromStart + gaps[i].length;
            }

            // Each 2 points is a new path.
            List <SymPath> list = new List <SymPath>(starts.Length);

            for (int i = 0; i < starts.Length; ++i)
            {
                SymPath p = pathInitial.Segment(pathInitial.PointAtLength(starts[i]), pathInitial.PointAtLength(ends[i]));
                if (p != null)
                {
                    list.Add(p);
                }
            }

            return(list.ToArray());
        }
Esempio n. 2
0
        // Split a path into multiple paths based on an array of LegGaps.  The gaps might extend beyond the end of the
        // or the beginning of the path. The gaps array need not be in simplified form.
        public static SymPath[] SplitPathWithGaps(SymPath pathInitial, LegGap[] gaps)
        {
            // Get the length of the path.
            float pathLength = pathInitial.Length;

            // Simply and sort the gaps.
            gaps = SimplifyGaps(gaps, pathLength);

            // If no gaps length, the entire path is correct.
            if (gaps == null)
                return new SymPath[1] { pathInitial };

            // Transform into start/stop distances from beginning of path.
            float[] starts = new float[gaps.Length + 1];
            float[] ends = new float[gaps.Length + 1];
            starts[0] = 0;
            ends[gaps.Length] = pathLength;
            for (int i = 0; i < gaps.Length; ++i) {
                ends[i] = gaps[i].distanceFromStart;
                starts[i + 1] = gaps[i].distanceFromStart + gaps[i].length;
            }

            // Each 2 points is a new path.
            List<SymPath> list = new List<SymPath>(starts.Length);
            for (int i = 0; i < starts.Length; ++i) {
                SymPath p = pathInitial.Segment(pathInitial.PointAtLength(starts[i]), pathInitial.PointAtLength(ends[i]));
                if (p != null)
                    list.Add(p);
            }

            return list.ToArray();
        }