diff --git a/Paint_2/BezierPencil.cs b/Paint_2/BezierPencil.cs index a804069..455afdb 100644 --- a/Paint_2/BezierPencil.cs +++ b/Paint_2/BezierPencil.cs @@ -96,10 +96,10 @@ namespace Paint_2 } private void AdjustedBezierGenerator(Graphics gr, List points, Color color, int width) { - /*foreach (Point p in points) + foreach (Point p in points) { gr.FillEllipse(new SolidBrush(color), new Rectangle(new Point(p.X - width / 2, p.Y - width / 2), new Size(width,width))); - }*/ + } if (points.Count >= 3) { float precision = 0.01f; @@ -194,33 +194,36 @@ namespace Paint_2 string result = ""; string newLine = Environment.NewLine; - if (points.Count >= 4 && points.Count % 2 == 0) + if (points.Count >= 3) { float precision = 0.01f; for (float t = 0; t <= 1; t += precision) { List DumpList = new List(); - List WorkingList = new List(points); + List WorkingList = new List(); - while (WorkingList.Count != 1) + foreach (Point p in points) { - if (WorkingList.Count > 1) + WorkingList.Add(new Point(p.X, p.Y)); + } + while (WorkingList.Count > 1) + { + for (int i = 0; i < WorkingList.Count - 1; i++) { - for (int pos = 0; pos < WorkingList.Count - 1; pos++) - { - DumpList.Add(Utils.Lerp(WorkingList[pos], WorkingList[pos + 1], t)); - } + Point p1 = WorkingList[i]; + Point p2 = WorkingList[i + 1]; + Point tmp = Utils.Lerp(p1, p2, t); + DumpList.Add(tmp); } - else + WorkingList.Clear(); + foreach (Point p in DumpList) { - DumpList.Add(Utils.Lerp(WorkingList[0], WorkingList[1], precision)); + WorkingList.Add(new Point(p.X, p.Y)); } - WorkingList = new List(DumpList); - DumpList = new List(); + DumpList.Clear(); } result += ""; result += newLine; - //gr.FillEllipse(new SolidBrush(color), new Rectangle(WorkingList[0].X - Widths[0] / 2, WorkingList[0].Y - Widths[0] / 2, width, width)); } } return result;