public override VectorPoint Copy()
        {
            StraightLinePoint point = new StraightLinePoint(X, Y);

            point.Length = Length;
            return(point);
        }
		public override VectorPoint Split(float t,VectorPath path){
			
			// Create the next one:
			StraightLinePoint point=new StraightLinePoint(X,Y);
			
			// Get previous:
			float previousX=Previous.X;
			float previousY=Previous.Y;
			
			// Get deltas:
			float dx=X-previousX;
			float dy=Y-previousY;
			
			float nX=previousX + (t*dx);
			float nY=previousY + (t*dy);
			
			X=nX;
			Y=nY;
			
			path.PathNodeCount++;
			
			// Insert after this:
			if(Next==null){
				path.LatestPathNode=point;
			}else{
				point.Next=Next;
				Next.Previous=point;
			}
			
			point.Previous=this;
			Next=point;
			
			return point;
		}
Example #3
0
        public StraightLinePoint LineTo(float x, float y)
        {
            // Create the straight line:
            StraightLinePoint newNode = new StraightLinePoint(x, y);

            // Add it:
            AddPathNode(newNode);

            return(newNode);
        }
        public override VectorPoint DeleteControl(int id, VectorPath path)
        {
            // Create:
            VectorPoint pt = new StraightLinePoint(X, Y);

            // Remove this and add in it's place:
            ReplaceWith(pt, path);

            return(pt);
        }
Example #5
0
        /// <summary>Closes the path quickly and safely.</summary>
        public void ClosePathFast()
        {
            if (CloseNode == null || LatestPathNode == null)
            {
                return;
            }

            StraightLinePoint point = LineTo(CloseNode.X, CloseNode.Y);

            point.Close          = true;
            CloseNode.ClosePoint = point;
        }
        public override VectorPoint Split(float t, VectorPath path)
        {
            // Create the next one:
            StraightLinePoint point = new StraightLinePoint(X, Y);

            // Get previous:
            float previousX = Previous.X;
            float previousY = Previous.Y;

            // Get deltas:
            float dx = X - previousX;
            float dy = Y - previousY;

            float nX = previousX + (t * dx);
            float nY = previousY + (t * dy);

            X = nX;
            Y = nY;

            path.PathNodeCount++;

            // Insert after this:
            if (Next == null)
            {
                path.LatestPathNode = point;
            }
            else
            {
                point.Next    = Next;
                Next.Previous = point;
            }

            // Update lengths:
            point.Length = (1f - t) * Length;
            Length       = t * Length;

            point.Previous = this;
            Next           = point;

            if (IsClose)
            {
                IsClose                   = false;
                point.IsClose             = true;
                path.CloseNode.ClosePoint = point;
            }

            return(point);
        }
Example #7
0
        /// <summary>A full path close.</summary>
        public void ClosePath()
        {
            if (CloseNode == null || LatestPathNode == null)
            {
                return;
            }

            if (LatestPathNode.X == CloseNode.X && LatestPathNode.Y == CloseNode.Y)
            {
                LatestPathNode.IsClose = true;
                CloseNode.ClosePoint   = LatestPathNode;
            }
            else
            {
                StraightLinePoint point = LineTo(CloseNode.X, CloseNode.Y);
                point.Close          = true;
                CloseNode.ClosePoint = point;
            }
        }
        /// <summary>Gets the point at the given t location.
        /// Similar to Split but doesn't apply the point to the path.
        /// Instead, the following point is added too.</summary>
        public override VectorPoint PointAt(float t, bool addNext)
        {
            // Get previous:
            float previousX = Previous.X;
            float previousY = Previous.Y;

            // Get deltas:
            float dx = X - previousX;
            float dy = Y - previousY;

            float nX = previousX + (t * dx);
            float nY = previousY + (t * dy);

            // Create the from:
            StraightLinePoint from = new StraightLinePoint(nX, nY);

            if (addNext)
            {
                // Create a copy:
                StraightLinePoint to = new StraightLinePoint(X, Y);

                to.Previous = from;
                from.Next   = to;

                // Update length:
                to.Length = (1f - t) * Length;

                if (IsClose)
                {
                    to.IsClose = true;
                }
            }

            // Update length:
            from.Length = t * Length;

            return(from);
        }
        public override VectorPoint Split(float t, VectorPath path)
        {
            // Create the next one:
            StraightLinePoint point = new StraightLinePoint(X, Y);

            // Get previous:
            float previousX = Previous.X;
            float previousY = Previous.Y;

            // Get deltas:
            float dx = X - previousX;
            float dy = Y - previousY;

            float nX = previousX + (t * dx);
            float nY = previousY + (t * dy);

            X = nX;
            Y = nY;

            path.PathNodeCount++;

            // Insert after this:
            if (Next == null)
            {
                path.LatestPathNode = point;
            }
            else
            {
                point.Next    = Next;
                Next.Previous = point;
            }

            point.Previous = this;
            Next           = point;

            return(point);
        }
//--------------------------------------
Example #11
0
        /// <summary>Converts this path to straight lines only.
        /// Accuracy is the approx average length of each line segment.</summary>
        public void ToStraightLines(float accuracy)
        {
            if (Width == 0f)
            {
                // Calc lengths etc:
                RecalculateBounds();
            }

            MoveToPoint prevMoveTo = null;
            VectorPoint point      = FirstPathNode;

            while (point != null)
            {
                // If it's straight/ a MoveTo, skip:
                if (point.IsCurve)
                {
                    VectorLine line = point as VectorLine;

                    // Replace it with n line segments:
                    int segmentCount = (int)(line.Length / accuracy);

                    if (segmentCount < 1)
                    {
                        segmentCount = 1;
                    }

                    // Setup:
                    float delta    = 1f / (float)segmentCount;
                    float progress = delta;

                    // Sample it segmentCount times:
                    VectorPoint previous = point.Previous;

                    for (int i = 0; i < segmentCount; i++)
                    {
                        float x;
                        float y;
                        line.SampleAt(progress, out x, out y);

                        // Create line segment:
                        StraightLinePoint slp = new StraightLinePoint(x, y);
                        slp.Previous = previous;

                        if (previous == null)
                        {
                            FirstPathNode = slp;
                        }
                        else
                        {
                            previous.Next = slp;
                        }

                        previous  = slp;
                        progress += delta;
                    }

                    // Increase node count:
                    PathNodeCount += segmentCount - 1;

                    // Link up after too:
                    if (point.Next == null)
                    {
                        LatestPathNode = previous;
                    }
                    else
                    {
                        point.Next.Previous = previous;
                    }

                    if (point.IsClose)
                    {
                        previous.IsClose = true;

                        if (prevMoveTo != null)
                        {
                            prevMoveTo.ClosePoint = previous;
                        }
                    }
                }
                else if (point is MoveToPoint)
                {
                    prevMoveTo = point as MoveToPoint;
                }

                // Next one:
                point = point.Next;
            }

            // Recalc:
            RecalculateBounds();
        }
		public override VectorPoint Copy(){
			
			StraightLinePoint point=new StraightLinePoint(X,Y);
			point.Length=Length;
			point.NormalX=NormalX;
			point.NormalY=NormalY;
			
			return point;
			
		}