VertexList.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. namespace PaintDotNet.SystemLayer.GpcWrapper
  4. {
  5. internal sealed class VertexList
  6. {
  7. public int NofVertices;
  8. public Vertex[] Vertex;
  9. public VertexList()
  10. {
  11. }
  12. public VertexList(Vertex[] v)
  13. : this(v, false)
  14. {
  15. }
  16. public VertexList(Vertex[] v, bool takeOwnership)
  17. {
  18. if (takeOwnership)
  19. {
  20. this.Vertex = v;
  21. this.NofVertices = v.Length;
  22. }
  23. else
  24. {
  25. this.Vertex = (Vertex[])v.Clone();
  26. this.NofVertices = v.Length;
  27. }
  28. }
  29. public VertexList(PointF[] p)
  30. {
  31. NofVertices = p.Length;
  32. Vertex = new Vertex[NofVertices];
  33. for (int i = 0; i < p.Length; i++)
  34. Vertex[i] = new Vertex((double)p[i].X, (double)p[i].Y);
  35. }
  36. public GraphicsPath ToGraphicsPath()
  37. {
  38. GraphicsPath graphicsPath = new GraphicsPath();
  39. graphicsPath.AddLines(ToPoints());
  40. return graphicsPath;
  41. }
  42. public PointF[] ToPoints()
  43. {
  44. PointF[] vertexArray = new PointF[NofVertices];
  45. for (int i = 0; i < NofVertices; i++)
  46. {
  47. vertexArray[i] = new PointF((float)Vertex[i].X, (float)Vertex[i].Y);
  48. }
  49. return vertexArray;
  50. }
  51. public GraphicsPath TristripToGraphicsPath()
  52. {
  53. GraphicsPath graphicsPath = new GraphicsPath();
  54. for (int i = 0; i < NofVertices - 2; i++)
  55. {
  56. graphicsPath.AddPolygon(new PointF[3]{ new PointF( (float)Vertex[i].X, (float)Vertex[i].Y ),
  57. new PointF( (float)Vertex[i+1].X, (float)Vertex[i+1].Y ),
  58. new PointF( (float)Vertex[i+2].X, (float)Vertex[i+2].Y ) });
  59. }
  60. return graphicsPath;
  61. }
  62. public override string ToString()
  63. {
  64. string s = "Polygon with " + NofVertices + " vertices: ";
  65. for (int i = 0; i < NofVertices; i++)
  66. {
  67. s += Vertex[i].ToString();
  68. if (i != NofVertices - 1)
  69. s += ",";
  70. }
  71. return s;
  72. }
  73. }
  74. }