Exemple #1
0
        public LinePath RemoveBetween(PointOnPath start, PointOnPath end)
        {
            // remove all the points between start and end (non-inclusive)

            // nothing to remove if they are the same index
            if (start.Index == end.Index)
            {
                return(new LinePath(this));
            }

            int endIndex = end.DistFraction == 1 ? end.Index + 2 : end.Index + 1;

            LinePath ret = new LinePath();

            for (int i = 0; i <= start.Index; i++)
            {
                ret.Add(this[i]);
            }

            // if the start is not at a point, add it
            if (start.DistFraction != 0)
            {
                ret.Add(start.Location);
            }

            // add the end point
            ret.Add(end.Location);

            for (int i = endIndex; i < this.Count; i++)
            {
                ret.Add(this[i]);
            }

            return(ret);
        }
Exemple #2
0
        public LinePath Resample(double spacing)
        {
            LinePath    ret = new LinePath();
            PointOnPath pt  = StartPoint;

            while (pt != EndPoint)
            {
                ret.Add(GetPoint(pt));
                pt = AdvancePoint(pt, spacing);
            }

            ret.Add(GetPoint(EndPoint));

            return(ret);
        }
Exemple #3
0
        public LinePath Resample(PointOnPath start, PointOnPath end, double spacing)
        {
            LinePath    ret = new LinePath();
            PointOnPath pt  = start;

            while (pt < end)
            {
                ret.Add(GetPoint(pt));
                pt = AdvancePoint(pt, spacing);
            }

            ret.Add(GetPoint(end));

            return(ret);
        }
Exemple #4
0
        public LinePath RemoveZeroLengthSegments()
        {
            LinePath ret = new LinePath(this.Count);

            ret.Add(this[0]);
            for (int i = 1; i < this.Count; i++)
            {
                if (!this[i].ApproxEquals(this[i - 1], 1e-10))
                {
                    ret.Add(this[i]);
                }
            }

            return(ret);
        }
Exemple #5
0
        public LinePath ApplyMovingAverageSmooth(int iterations, int k_max)
        {
            LinePath smoothed = new LinePath(this.Count);
            LinePath source   = this;

            for (int iter = 0; iter < iterations; iter++)
            {
                for (int i = 0; i < Count; i++)
                {
                    int k_lower = Math.Min(k_max, i);
                    int k_upper = Math.Min(k_max, Count - i - 1);
                    int k       = Math.Min(k_lower, k_upper);

                    Coordinates sum = Coordinates.Zero;
                    for (int j = i - k; j <= i + k; j++)
                    {
                        sum += source[j];
                    }

                    smoothed.Add(sum / (2.0 * k + 1.0));
                }

                source   = smoothed;
                smoothed = new LinePath(source.Count);
            }

            return(source);
        }
Exemple #6
0
        public LinePath RemoveAfter(PointOnPath pt)
        {
            LinePath ret = new LinePath(pt.Index + 2);

            for (int i = 0; i < pt.Index; i++)
            {
                ret.Add(this[i]);
            }

            if (pt.DistFraction > 0)
            {
                ret.Add(pt.Location);
            }

            return(ret);
        }
Exemple #7
0
        /// <summary>
        /// Returns a line path with all points before pt removed
        /// </summary>
        public LinePath RemoveBefore(PointOnPath pt)
        {
            LinePath ret = new LinePath(Count - pt.Index);

            if (pt.DistFraction < 1)
            {
                ret.Add(pt.Location);
            }

            for (int i = pt.Index + 1; i < Count; i++)
            {
                ret.Add(this[i]);
            }

            return(ret);
        }
Exemple #8
0
        public static LinePath FromPath(IPath path)
        {
            if (path.Count == 0)
            {
                return(new LinePath());
            }

            LinePath ret = new LinePath(path.Count + 1);

            ret.Add(path[0].Start);

            for (int i = 0; i < path.Count; i++)
            {
                ret.Add(path[i].End);
            }

            return(ret);
        }
Exemple #9
0
        public LinePath ShiftLateral(double[] dists)
        {
            if (dists == null)
            {
                throw new ArgumentNullException();
            }
            if (dists.Length != Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            LinePath path = new LinePath(this.Count);

            if (this.Count == 0)
            {
                return(path);
            }
            else if (this.Count == 1)
            {
                path.Add(this[0]);
                return(path);
            }

            // get the normal of the first point
            Coordinates v0 = GetSegment(0).UnitVector.Rotate90();

            // offset and add it
            path.Add(this[0] + v0 * dists[0]);

            // handle all the intermediate points
            for (int i = 1; i < Count - 1; i++)
            {
                Coordinates vi = (this[i + 1] - this[i - 1]).Normalize().Rotate90();
                path.Add(this[i] + vi * dists[i]);
            }

            // get the normal of the last point
            Coordinates vn = EndSegment.UnitVector.Rotate90();

            path.Add(this[this.Count - 1] + vn * dists[this.Count - 1]);

            return(path);
        }
Exemple #10
0
        public LinePath ShiftLateral(double dist)
        {
            if (this.Count < 2)
            {
                throw new InvalidOperationException("Cannot shift a line with less than two points.");
            }
            // create a list of shift line segments
            List <LineSegment> segs = new List <LineSegment>();

            foreach (LineSegment ls in GetSegmentEnumerator())
            {
                segs.Add(ls.ShiftLateral(dist));
            }

            // find the intersection points between all of the segments
            LinePath boundPoints = new LinePath(this.Count);

            // add the first point
            boundPoints.Add(segs[0].P0);

            // loop through the stuff
            for (int i = 0; i < segs.Count - 1; i++)
            {
                // find the intersection
                Line l0 = (Line)segs[i];
                Line l1 = (Line)segs[i + 1];

                Coordinates pt;
                if (l0.Intersect(l1, out pt))
                {
                    boundPoints.Add(pt);
                }
                else
                {
                    boundPoints.Add(segs[i].P1);
                }
            }

            // add the last point
            boundPoints.Add(segs[segs.Count - 1].P1);

            return(boundPoints);
        }
Exemple #11
0
        public LinePath SubPath(int start, int end)
        {
            LinePath ret = new LinePath(end - start + 1);

            for (int i = start; i <= end; i++)
            {
                ret.Add(this[i]);
            }

            return(ret);
        }
Exemple #12
0
        public LinePath SplineInterpolate(double desiredSpacing)
        {
            CubicBezier[] beziers = SmoothingSpline.BuildCatmullRomSpline(this.ToArray(), null, null);
            LinePath      newPath = new LinePath();

            // insert the first point
            newPath.Add(this[0]);
            for (int i = 0; i < beziers.Length; i++)
            {
                double splineLength = beziers[i].ArcLength;
                int    numT         = (int)(splineLength / desiredSpacing);
                double tspacing     = 1.0 / numT;

                double t;
                for (t = tspacing; t < 1; t += tspacing)
                {
                    newPath.Add(beziers[i].Bt(t));
                }

                newPath.Add(this[i + 1]);
            }

            return(newPath);
        }
Exemple #13
0
        public LinePath SubPath(PointOnPath start, PointOnPath end)
        {
            Debug.Assert(start.Valid);
            Debug.Assert(end.Valid);

            LinePath ret = new LinePath();

            if (start.Index < end.Index || ((start.Index == end.Index) && (start.Dist < end.Dist)))
            {
                if (start.DistFraction < 0.999999999)
                {
                    ret.Add(GetPoint(start));
                }

                // iterate through and add all the end point
                for (int i = start.Index + 1; i <= end.Index; i++)
                {
                    ret.Add(this[i]);
                }

                if (end.DistFraction > 0)
                {
                    ret.Add(GetPoint(end));
                }

                return(ret);
            }
            else
            {
                // end is first
                if (start.DistFraction > 0)
                {
                    ret.Add(GetPoint(start));
                }

                for (int i = start.Index; i > end.Index; i--)
                {
                    ret.Add(this[i]);
                }

                if (end.DistFraction < 1)
                {
                    ret.Add(GetPoint(end));
                }

                return(ret);
            }
        }