Fixed the SVG generator of the bezier pencil

This commit is contained in:
2022-06-22 09:42:21 +02:00
parent 640796a1b1
commit e243b37884

View File

@@ -96,10 +96,10 @@ namespace Paint_2
} }
private void AdjustedBezierGenerator(Graphics gr, List<Point> points, Color color, int width) private void AdjustedBezierGenerator(Graphics gr, List<Point> 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))); 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) if (points.Count >= 3)
{ {
float precision = 0.01f; float precision = 0.01f;
@@ -194,33 +194,36 @@ namespace Paint_2
string result = ""; string result = "";
string newLine = Environment.NewLine; string newLine = Environment.NewLine;
if (points.Count >= 4 && points.Count % 2 == 0) if (points.Count >= 3)
{ {
float precision = 0.01f; float precision = 0.01f;
for (float t = 0; t <= 1; t += precision) for (float t = 0; t <= 1; t += precision)
{ {
List<Point> DumpList = new List<Point>(); List<Point> DumpList = new List<Point>();
List<Point> WorkingList = new List<Point>(points); List<Point> WorkingList = new List<Point>();
while (WorkingList.Count != 1) foreach (Point p in points)
{ {
if (WorkingList.Count > 1) WorkingList.Add(new Point(p.X, p.Y));
{
for (int pos = 0; pos < WorkingList.Count - 1; pos++)
{
DumpList.Add(Utils.Lerp(WorkingList[pos], WorkingList[pos + 1], t));
} }
} while (WorkingList.Count > 1)
else
{ {
DumpList.Add(Utils.Lerp(WorkingList[0], WorkingList[1], precision)); for (int i = 0; i < WorkingList.Count - 1; i++)
{
Point p1 = WorkingList[i];
Point p2 = WorkingList[i + 1];
Point tmp = Utils.Lerp(p1, p2, t);
DumpList.Add(tmp);
} }
WorkingList = new List<Point>(DumpList); WorkingList.Clear();
DumpList = new List<Point>(); foreach (Point p in DumpList)
{
WorkingList.Add(new Point(p.X, p.Y));
}
DumpList.Clear();
} }
result += "<ellipse cx=\"" + WorkingList[0].X + "\" cy=\"" + WorkingList[0].Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>"; result += "<ellipse cx=\"" + WorkingList[0].X + "\" cy=\"" + WorkingList[0].Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
result += newLine; 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; return result;