Пример #1
0
        // Move a gap start/stop point to a new location. Return the new gap array. The gap array is NOT simplified.
        public static LegGap[] MoveStartStopPoint(SymPath path, LegGap[] gaps, PointF oldPt, PointF newPt)
        {
            LegGap[] newGaps            = (LegGap[])gaps.Clone();
            float    newLengthAlongPath = path.LengthToPoint(newPt);

            for (int i = 0; i < newGaps.Length; ++i)
            {
                PointF startPt = path.PointAtLength(gaps[i].distanceFromStart);
                PointF endPt   = path.PointAtLength(gaps[i].distanceFromStart + gaps[i].length);

                if (Geometry.Distance(startPt, oldPt) < 0.01)
                {
                    // Moving start point of the gap.
                    newGaps[i].length           -= (newLengthAlongPath - newGaps[i].distanceFromStart);
                    newGaps[i].distanceFromStart = newLengthAlongPath;
                }
                else if (Geometry.Distance(endPt, oldPt) < 0.01)
                {
                    // Moving end point of the gap.
                    newGaps[i].length = newLengthAlongPath - gaps[i].distanceFromStart;
                }
            }

            return(newGaps);
        }
Пример #2
0
        // Add a new gap an an array of gaps. The resulting array is simplified. The original array may be null.
        public static LegGap[] AddGap(SymPath path, LegGap[] original, PointF pt1, PointF pt2)
        {
            float  dist1, dist2;
            LegGap newGap;

            LegGap[] newGaps;

            // map points to closes points on the line.
            path.DistanceFromPoint(pt1, out pt1);
            path.DistanceFromPoint(pt2, out pt2);

            // Map to distances along the line.
            dist1 = path.LengthToPoint(pt1);
            dist2 = path.LengthToPoint(pt2);

            // Create the new gap.
            if (dist1 < dist2)
            {
                newGap = new LegGap(dist1, dist2 - dist1);
            }
            else
            {
                newGap = new LegGap(dist2, dist1 - dist2);
            }

            // Add to the old gaps.
            if (original == null)
            {
                newGaps = new LegGap[1] {
                    newGap
                }
            }
            ;
            else
            {
                newGaps = new LegGap[original.Length + 1];
                Array.Copy(original, newGaps, original.Length);
                newGaps[original.Length] = newGap;
            }

            // Simplify
            return(SimplifyGaps(newGaps, path.Length));
        }
Пример #3
0
        // Transform a gap array to a new path, keeping close gaps in the closest position on the new path. Remove far away gaps.
        public static LegGap[] MoveGapsToNewPath(LegGap[] oldGaps, SymPath oldPath, SymPath newPath)
        {
            oldGaps = SimplifyGaps(oldGaps, oldPath.Length);
            if (oldGaps == null)
            {
                return(null);
            }

            PointF        oldStart, oldEnd, newStart, newEnd; // ends points of the gaps
            float         distanceStart, distanceEnd;         // distance between oldStart and newStart, distance between oldEnd and newEnd.
            List <LegGap> newGaps = new List <LegGap>();

            // Move gap to a new gap by converting start and end to point, finding closest points on new path.
            // If the gap has moved too far, just remove it, else transformit.
            for (int i = 0; i < oldGaps.Length; ++i)
            {
                oldStart      = oldPath.PointAtLength(oldGaps[i].distanceFromStart);
                oldEnd        = oldPath.PointAtLength(oldGaps[i].distanceFromStart + oldGaps[i].length);
                distanceStart = newPath.DistanceFromPoint(oldStart, out newStart);
                distanceEnd   = newPath.DistanceFromPoint(oldEnd, out newEnd);

                // If the new gap is close enough to the old gap, then add the new gap.
                if (distanceStart + distanceEnd <= 2 * oldGaps[i].length)
                {
                    float newDistanceToStart = newPath.LengthToPoint(newStart);
                    float newDistanceToEnd   = newPath.LengthToPoint(newEnd);
                    if (newDistanceToStart < newDistanceToEnd)
                    {
                        newGaps.Add(new LegGap(newDistanceToStart, newDistanceToEnd - newDistanceToStart));
                    }
                    else
                    {
                        newGaps.Add(new LegGap(newDistanceToEnd, newDistanceToStart - newDistanceToEnd));
                    }
                }
            }

            // Simply the new gap array.
            return(SimplifyGaps(newGaps.ToArray(), newPath.Length));
        }
Пример #4
0
        // Add a new gap an an array of gaps. The resulting array is simplified. The original array may be null.
        public static LegGap[] AddGap(SymPath path, LegGap[] original, PointF pt1, PointF pt2)
        {
            float dist1, dist2;
            LegGap newGap;
            LegGap[] newGaps;

            // map points to closes points on the line.
            path.DistanceFromPoint(pt1, out pt1);
            path.DistanceFromPoint(pt2, out pt2);

            // Map to distances along the line.
            dist1 = path.LengthToPoint(pt1);
            dist2 = path.LengthToPoint(pt2);

            // Create the new gap.
            if (dist1 < dist2)
                newGap = new LegGap(dist1, dist2 - dist1);
            else
                newGap = new LegGap(dist2, dist1 - dist2);

            // Add to the old gaps.
            if (original == null)
                newGaps = new LegGap[1] { newGap };
            else {
                newGaps = new LegGap[original.Length + 1];
                Array.Copy(original, newGaps, original.Length);
                newGaps[original.Length] = newGap;
            }

            // Simplify
            return SimplifyGaps(newGaps, path.Length);
        }
Пример #5
0
        // Move a gap start/stop point to a new location. Return the new gap array. The gap array is NOT simplified.
        public static LegGap[] MoveStartStopPoint(SymPath path, LegGap[] gaps, PointF oldPt, PointF newPt)
        {
            LegGap[] newGaps = (LegGap[]) gaps.Clone();
            float newLengthAlongPath = path.LengthToPoint(newPt);

            for (int i = 0; i < newGaps.Length; ++i) {
                PointF startPt = path.PointAtLength(gaps[i].distanceFromStart);
                PointF endPt = path.PointAtLength(gaps[i].distanceFromStart + gaps[i].length);

                if (Geometry.Distance(startPt, oldPt) < 0.01) {
                    // Moving start point of the gap.
                    newGaps[i].length -= (newLengthAlongPath - newGaps[i].distanceFromStart);
                    newGaps[i].distanceFromStart = newLengthAlongPath;
                }
                else if (Geometry.Distance(endPt, oldPt) < 0.01) {
                    // Moving end point of the gap.
                    newGaps[i].length = newLengthAlongPath - gaps[i].distanceFromStart;
                }
            }

            return newGaps;
        }
Пример #6
0
        // Transform a gap array to a new path, keeping close gaps in the closest position on the new path. Remove far away gaps.
        public static LegGap[] MoveGapsToNewPath(LegGap[] oldGaps, SymPath oldPath, SymPath newPath)
        {
            oldGaps = SimplifyGaps(oldGaps, oldPath.Length);
            if (oldGaps == null)
                return null;

            PointF oldStart, oldEnd, newStart, newEnd;  // ends points of the gaps
            float distanceStart, distanceEnd;  // distance between oldStart and newStart, distance between oldEnd and newEnd.
            List<LegGap> newGaps = new List<LegGap>();

            // Move gap to a new gap by converting start and end to point, finding closest points on new path.
            // If the gap has moved too far, just remove it, else transformit.
            for (int i = 0; i < oldGaps.Length; ++i) {
                oldStart = oldPath.PointAtLength(oldGaps[i].distanceFromStart);
                oldEnd = oldPath.PointAtLength(oldGaps[i].distanceFromStart + oldGaps[i].length);
                distanceStart = newPath.DistanceFromPoint(oldStart, out newStart);
                distanceEnd = newPath.DistanceFromPoint(oldEnd, out newEnd);

                // If the new gap is close enough to the old gap, then add the new gap.
                if (distanceStart + distanceEnd <= 2 * oldGaps[i].length) {
                    float newDistanceToStart = newPath.LengthToPoint(newStart);
                    float newDistanceToEnd = newPath.LengthToPoint(newEnd);
                    if (newDistanceToStart < newDistanceToEnd)
                        newGaps.Add(new LegGap(newDistanceToStart, newDistanceToEnd - newDistanceToStart));
                    else
                        newGaps.Add(new LegGap(newDistanceToEnd, newDistanceToStart - newDistanceToEnd));
                }
            }

            // Simply the new gap array.
            return SimplifyGaps(newGaps.ToArray(), newPath.Length);
        }