/// <summary>"Simplifies" the curve values ensuring that it's possible to offset the parts of the path. /// Used by the path stroke system.</summary> public void SimplifyCurve() { VectorPoint current = FirstPathNode; while (current != null) { if (current.IsCurve) { CurveLinePoint clp = current as CurveLinePoint; if (clp != null) { // Simplify: clp.SimplifyCurve(this); } else { // Convert a QLP to a CLP: QuadLinePoint qlp = current as QuadLinePoint; if (qlp != null) { // Create but with both control points being the same: clp = new CurveLinePoint(qlp.X, qlp.Y); clp.Control1X = qlp.Control1X; clp.Control1Y = qlp.Control1Y; clp.Control2X = qlp.Control1X; clp.Control2Y = qlp.Control1Y; clp.IsClose = qlp.IsClose; // Replace the node now: if (qlp.Previous == null) { FirstPathNode = clp; } else { qlp.Previous.Next = clp; } if (qlp.Next == null) { LatestPathNode = clp; } else { qlp.Next.Previous = clp; } } } } current = current.Next; } }
public void CurveTo(float c1x, float c1y, float c2x, float c2y, float x, float y) { // Create the curve line: CurveLinePoint newNode = new CurveLinePoint(x, y); newNode.Control1X = c1x; newNode.Control1Y = c1y; newNode.Control2X = c2x; newNode.Control2Y = c2y; // Add it: AddPathNode(newNode); }
public override VectorPoint Copy() { CurveLinePoint point = new CurveLinePoint(X, Y); point.Length = Length; point.Control1X = Control1X; point.Control1Y = Control1Y; point.Control2X = Control2X; point.Control2Y = Control2Y; return(point); }
public override VectorPoint AddControl(float x, float y, VectorPath path, out int id) { // Create: CurveLinePoint pt = new CurveLinePoint(X, Y); // Get the "progress" of x/y along the line, vs control point progress. float C = X - Previous.X; float D = Y - Previous.Y; float len_sq = C * C + D * D; float newProg = ProgressAlongFast(x, y, C, D, len_sq); float p1Prog = ProgressAlongFast(Control1X, Control1Y, C, D, len_sq); // Should this new control be control point #1? bool first = (newProg < p1Prog); if (first) { // Pt 1: pt.Control1X = x; pt.Control1Y = y; pt.Control2X = Control1X; pt.Control2Y = Control1Y; id = 1; } else { // Pt 2: pt.Control1X = Control1X; pt.Control1Y = Control1Y; pt.Control2X = x; pt.Control2Y = y; id = 2; } // Remove this and add in it's place: ReplaceWith(pt, path); return(pt); }
//--------------------------------------
public override VectorPoint Copy(){ CurveLinePoint point=new CurveLinePoint(X,Y); point.Length=Length; point.NormalX=NormalX; point.NormalY=NormalY; point.Control1X=Control1X; point.Control1Y=Control1Y; point.Control2X=Control2X; point.Control2Y=Control2Y; point.NormalC1X=NormalC1X; point.NormalC1Y=NormalC1Y; point.NormalC2X=NormalC2X; point.NormalC2Y=NormalC2Y; return point; }
public override VectorPoint Split(float t,VectorPath path){ float invert=1f-t; float p0x=Previous.X; float p0y=Previous.Y; float p1x=Control1X; float p1y=Control1Y; float p2x=Control2X; float p2y=Control2Y; float p3x=X; float p3y=Y; // The new points: float p4x=p0x * invert + p1x * t; float p4y=p0y * invert + p1y * t; float p5x=p1x * invert + p2x * t; float p5y=p1y * invert + p2y * t; float p6x=p2x * invert + p3x * t; float p6y=p2y * invert + p3y * t; float p7x=p4x * invert + p5x * t; float p7y=p4y * invert + p5y * t; float p8x=p5x * invert + p6x * t; float p8y=p5y * invert + p6y * t; float p9x=p7x * invert + p8x * t; float p9y=p7y * invert + p8y * t; // This curve will become the new 1st half: Control1X=p4x; Control1Y=p4y; Control2X=p7x; Control2Y=p7y; X=p9x; Y=p9y; // Create the next one: CurveLinePoint point=new CurveLinePoint(p3x,p3y); point.Control1X=p8x; point.Control1Y=p8y; point.Control2X=p6x; point.Control2Y=p6y; 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; }
public override VectorPoint Split(float t, VectorPath path) { float invert = 1f - t; float p0x = Previous.X; float p0y = Previous.Y; float p1x = Control1X; float p1y = Control1Y; float p2x = Control2X; float p2y = Control2Y; float p3x = X; float p3y = Y; // The new points: float p4x = p0x * invert + p1x * t; float p4y = p0y * invert + p1y * t; float p5x = p1x * invert + p2x * t; float p5y = p1y * invert + p2y * t; float p6x = p2x * invert + p3x * t; float p6y = p2y * invert + p3y * t; float p7x = p4x * invert + p5x * t; float p7y = p4y * invert + p5y * t; float p8x = p5x * invert + p6x * t; float p8y = p5y * invert + p6y * t; float p9x = p7x * invert + p8x * t; float p9y = p7y * invert + p8y * t; // This curve will become the new 1st half: Control1X = p4x; Control1Y = p4y; Control2X = p7x; Control2Y = p7y; X = p9x; Y = p9y; // Create the next one: CurveLinePoint point = new CurveLinePoint(p3x, p3y); point.Control1X = p8x; point.Control1Y = p8y; point.Control2X = p6x; point.Control2Y = p6y; path.PathNodeCount++; // Insert after this: if (Next == null) { path.LatestPathNode = point; } else { point.Next = Next; Next.Previous = point; } // Update lengths: point.Length = invert * Length; Length = t * Length; point.Previous = this; Next = point; if (IsClose) { IsClose = false; point.IsClose = true; path.CloseNode.ClosePoint = point; } return(point); }
public override VectorPoint PointAt(float t, bool addNext) { float invert = 1f - t; float p0x = Previous.X; float p0y = Previous.Y; float p1x = Control1X; float p1y = Control1Y; float p2x = Control2X; float p2y = Control2Y; float p3x = X; float p3y = Y; // The new points: float p4x = p0x * invert + p1x * t; float p4y = p0y * invert + p1y * t; float p5x = p1x * invert + p2x * t; float p5y = p1y * invert + p2y * t; float p6x = p2x * invert + p3x * t; float p6y = p2y * invert + p3y * t; float p7x = p4x * invert + p5x * t; float p7y = p4y * invert + p5y * t; float p8x = p5x * invert + p6x * t; float p8y = p5y * invert + p6y * t; float p9x = p7x * invert + p8x * t; float p9y = p7y * invert + p8y * t; // Create the new first half: CurveLinePoint from = new CurveLinePoint(p9x, p9y); from.Control1X = p4x; from.Control1Y = p4y; from.Control2X = p7x; from.Control2Y = p7y; if (addNext) { // Create the next one: CurveLinePoint to = new CurveLinePoint(p3x, p3y); to.Control1X = p8x; to.Control1Y = p8y; to.Control2X = p6x; to.Control2Y = p6y; to.Previous = from; from.Next = to; // Update length: to.Length = invert * Length; if (IsClose) { to.IsClose = true; } } from.Length = t * Length; return(from); }