Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
        public IEnumerable <Vector2> GetSubpathEnumerator(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 < 1)
                {
                    yield return(start.Location);
                }

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

                if (end.DistFraction > 0)
                {
                    yield return(end.Location);
                }
            }
            else
            {
                // end is first
                if (start.DistFraction > 0)
                {
                    yield return(start.Location);
                }

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

                if (end.DistFraction < 1)
                {
                    yield return(end.Location);
                }
            }
        }
Exemplo n.º 10
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
            Vector2 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++)
            {
                Vector2 vi = (this[i + 1] - this[i - 1]).Normalize().Rotate90();
                path.Add(this[i] + vi * dists[i]);
            }

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

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

            return(path);
        }
Exemplo n.º 11
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
            for (int i = 0; i < segs.Count - 1; i++)
            {
                // find the intersection
                Line l0 = (Line)segs[i];
                Line l1 = (Line)segs[i + 1];

                Vector2 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);
        }
Exemplo n.º 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);
        }