optimize<CommitGraph>: ignore duplicated point in Line

This commit is contained in:
leo 2021-05-19 09:39:46 +08:00
parent d23e42b93f
commit 302702f578

View file

@ -38,11 +38,14 @@ namespace SourceGit.Views.Controls {
public double LastY; public double LastY;
public Line Line; public Line Line;
private Point end;
public LineHelper(string next, bool isMerged, int color, Point start) { public LineHelper(string next, bool isMerged, int color, Point start) {
Next = next; Next = next;
IsMerged = isMerged; IsMerged = isMerged;
LastX = start.X; LastX = start.X;
LastY = start.Y; LastY = start.Y;
end = start;
Line = new Line(); Line = new Line();
Line.Color = color % PENS.Length; Line.Color = color % PENS.Length;
@ -51,19 +54,23 @@ namespace SourceGit.Views.Controls {
public void Add(double x, double y, bool isEnd = false) { public void Add(double x, double y, bool isEnd = false) {
if (x > LastX) { if (x > LastX) {
Line.Points.Add(new Point(LastX, LastY)); Add(new Point(LastX, LastY));
Line.Points.Add(new Point(x, y - HALF_HEIGHT)); Add(new Point(x, y - HALF_HEIGHT));
} else if (x < LastX) { } else if (x < LastX) {
Line.Points.Add(new Point(LastX, LastY + HALF_HEIGHT)); Add(new Point(LastX, LastY + HALF_HEIGHT));
Line.Points.Add(new Point(x, y)); Add(new Point(x, y));
} }
LastX = x; LastX = x;
LastY = y; LastY = y;
if (isEnd) { if (isEnd) Add(new Point(LastX, LastY));
var last = Line.Points.Last(); }
if (LastX != last.X || LastY != last.Y) Line.Points.Add(new Point(LastX, LastY));
private void Add(Point p) {
if (p.Y > end.Y) {
Line.Points.Add(p);
end = p;
} }
} }
} }
@ -270,7 +277,7 @@ namespace SourceGit.Views.Controls {
} else { } else {
ctx.QuadraticBezierTo(new Point(last.X, cur.Y), cur, true, false); ctx.QuadraticBezierTo(new Point(last.X, cur.Y), cur, true, false);
} }
} else if (cur.Y != last.Y) { } else {
ctx.LineTo(cur, true, false); ctx.LineTo(cur, true, false);
} }