public TangentHandle(BezierHandle handle, PointF point) { this.handle = handle; this.mCurrentPoint = point; mRectangle = new RectangleF(point,new SizeF(5,5)); pen = new Pen(Color.Orange,1F); }
/// <summary> /// Constructor /// </summary> /// <param name="connection">the connection this painter is painting</param> public BezierPainter(Connection connection) : base(connection) { base.Points = Connection.GetConnectionPoints(); if (Points.Length > 1) { mHandles = new BezierHandleCollection(); BezierHandle hd; for (int k = 1; k < Points.Length - 1; k++) //this range is linked to the fact that connections have an adjacent point a little of the shape's edge { if (k == 1 || k == Points.Length - 2) //start and final handle should be single-type { hd = new BezierHandle(Points[k], HandleTypes.Single); } else { hd = new BezierHandle(Points[k], HandleTypes.Symmetric); } hd.Curve = this; mHandles.Add(hd); } } else { throw new Exception("A curve requires at least two handles"); } Init(); }
/// <summary> /// Constructor /// </summary> /// <param name="mHandle"></param> /// <param name="point"></param> public TangentHandle(BezierHandle mHandle, PointF point) { this.mHandle = mHandle; this.CurrentPoint = point; Rectangle = new RectangleF(point, new SizeF(5, 5)); pen = new Pen(Color.Orange, 1F); }
/// <summary> /// Constrcuts a collection on the basis of a PointF collection /// </summary> /// <param name="list">An ArrayList of PointF's</param> public BezierHandleCollection(ArrayList list) { BezierHandle hl; for(int k=0;k<list.Count; k++) { hl = new BezierHandle((PointF) list[k]); Add(hl); } }
/// <summary> /// Constrcuts a collection on the basis of a PointF collection /// </summary> /// <param name="list">An ArrayList of PointF's</param> public BezierHandleCollection(ArrayList list) { BezierHandle hl; for (int k = 0; k < list.Count; k++) { hl = new BezierHandle((PointF)list[k]); Add(hl); } }
/// <summary> /// Removes an handle /// </summary> /// <param name="handle">the handle to be removed</param> internal void RemoveHandle(BezierHandle handle) { if (mHandles.Count > 2) { mHandles.Remove(handle); Init(); } else { throw new Exception("A curves requires at least to handles"); } }
/// <summary> /// Adds an intermediate connection point /// </summary> /// <param name="p">the location of the additional connection-point</param> internal override void AddConnectionPoint(PointF p) { //figure out where the new point is in the series int before = 0; for (int h = 0; h < mHandles.Count - 1; h++) { RectangleF rec = RectangleF.Union(new RectangleF(mHandles[h].CurrentPoint, new Size(5, 5)), new RectangleF(mHandles[h + 1].CurrentPoint, new Size(5, 5))); if (rec.Contains(p)) { before = h; break; } } BezierHandle hd = new BezierHandle(p); hd.Curve = this; this.mHandles.Insert(before + 1, hd); Init(); }
/// <summary> /// Gets for the given sub-elemts of the Bezier curve an intermediate point /// </summary> /// <param name="percent">the percentage along the curve</param> /// <param name="handle1">the first handle of the segment</param> /// <param name="handle2">the second handle of the segment</param> /// <returns></returns> private PointF GetBezier(float percent, BezierHandle handle1, BezierHandle handle2) { TangentHandle tangent1 = null, tangent2 = null; if (handle1.HandleType == HandleTypes.Single) { if (handle1.Tangent1.Enabled) { tangent1 = handle1.Tangent1; } else { tangent1 = handle1.Tangent2; } } else { tangent1 = handle1.Tangent2; } if (handle2.HandleType == HandleTypes.Single) { if (handle2.Tangent1.Enabled) { tangent2 = handle2.Tangent1; } else { tangent2 = handle2.Tangent2; } } else { tangent2 = handle2.Tangent1; } return(GetBezier(percent, handle1.CurrentPoint, tangent1.CurrentPoint, tangent2.CurrentPoint, handle2.CurrentPoint)); }
public int Add(BezierHandle handle) { return this.InnerList.Add(handle); }
/// <summary> /// Inserts an item in the collection /// </summary> /// <param name="index"></param> /// <param name="handle"></param> public void Insert(int index, BezierHandle handle) { this.InnerList.Insert(index, handle); }
/// <summary> /// Adds an item to the collection /// </summary> /// <param name="handle"></param> /// <returns></returns> public int Add(BezierHandle handle) { return(this.InnerList.Add(handle)); }
private PointF GetBezier(float percent, BezierHandle handle1, BezierHandle handle2) { TangentHandle tangent1 = null, tangent2=null; if(handle1.HandleType==HandleTypes.Single) { if(handle1.Tangent1.Enabled) tangent1 = handle1.Tangent1; else tangent1 = handle1.Tangent2; } else tangent1 = handle1.Tangent2; if(handle2.HandleType==HandleTypes.Single) { if(handle2.Tangent1.Enabled) tangent2 = handle2.Tangent1; else tangent2 = handle2.Tangent2; } else tangent2 = handle2.Tangent1; return GetBezier(percent,handle1.CurrentPoint,tangent1.CurrentPoint,tangent2.CurrentPoint,handle2.CurrentPoint); }
// public BezierPainter() // { // // mHandles = new BezierHandleCollection(this); // mHandles.Add(new BezierHandle(10,10)); // mHandles.Add( new BezierHandle(50,50)); // mHandles.Add( new BezierHandle(100,100)); // mHandles.Add(new BezierHandle(150,150)); // Init(); // } // public BezierPainter(BezierHandleCollection mHandles) // { // // if(mHandles.Count>1) // { // this.mHandles = mHandles; // for(int k =0; k<mHandles.Count; k++) // {mHandles[k].Curve = this;} // } // else // throw new Exception("A curve requires at least two handles"); // // Init(); // } // public BezierPainter(PointF[] points) // { // if(points.Length>1) // { // mHandles = new BezierHandleCollection(); // BezierHandle hd; // for(int k=0; k<points.Length; k++) // { // if(k==0 || k==points.Length-1) //start and final handle should be single-type // hd = new BezierHandle(points[k],HandleTypes.Single); // else // hd = new BezierHandle(points[k],HandleTypes.Symmetric); // // hd.Curve = this; // mHandles.Add(hd); // } // } // else // throw new Exception("A curve requires at least two handles"); // // Init(); // } public BezierPainter(Connection connection) : base(connection) { mPoints = mConnection.GetConnectionPoints(); if(mPoints.Length>1) { mHandles = new BezierHandleCollection(); BezierHandle hd; for(int k=1; k<mPoints.Length-1; k++) { if(k==1 || k==mPoints.Length-2) //start and final handle should be single-type hd = new BezierHandle(mPoints[k],HandleTypes.Single); else hd = new BezierHandle(mPoints[k],HandleTypes.Symmetric); hd.Curve = this; mHandles.Add(hd); } } else throw new Exception("A curve requires at least two handles"); Init(); }
/// <summary> /// Removes an handle /// </summary> /// <param name="handle"></param> internal void RemoveHandle(BezierHandle handle) { if(mHandles.Count>2) { mHandles.Remove(handle); Init(); } else throw new Exception("A curves requires at least to handles"); }
internal override void AddConnectionPoint(PointF p) { //figure out where the new point is in the series int before = 0; for(int h =0;h<mHandles.Count-1; h++) { RectangleF rec = RectangleF.Union(new RectangleF(mHandles[h].CurrentPoint,new Size(5,5)),new RectangleF(mHandles[h+1].CurrentPoint,new Size(5,5))); if(rec.Contains(p)) { before = h; break; } } BezierHandle hd = new BezierHandle(p); hd.Curve = this; this.mHandles.Insert(before+1,hd); Init(); }
/// <summary> /// Removes and item from the collection /// </summary> /// <param name="handle"></param> public void Remove(BezierHandle handle) { this.InnerList.Remove(handle); }
public void Insert(int index, BezierHandle handle) { this.InnerList.Insert(index, handle); }
/// <summary> /// Returns whether the given handle is contained in the collection /// </summary> /// <param name="value">a Bezier handle</param> /// <returns>true if withing the collection, otherwise false</returns> public bool Contains(BezierHandle value) { return(((IList)this).Contains((object)value)); }
public void Remove(BezierHandle handle) { this.InnerList.Remove(handle); }
/// <summary> /// Returns the index of the given handle /// </summary> /// <param name="value"></param> /// <returns></returns> public int IndexOf(BezierHandle value) { return(((IList)this).IndexOf((object)value)); }