private void DrawSection(Graphics g, PointBuffer points, int start, int length) { if (length > 1) // DrawLines crashes if there isn't at least two points { Point[] _buffer; _buffer = ArrayPool <Point> .Shared.Allocate(length); points.CopyTo(start, _buffer, 0, length); g.DrawLines(_tailPen, _buffer); ArrayPool <Point> .Shared.Free(_buffer); } }
private void DrawStrandTail(Graphics g, PointBuffer points) { if (points.Size > 1) { // don't do this! //g.DrawLines(_bodyPen, points.ToArray()); if (!this.HasSplitResults(points)) { Point[] _buffer; // this isn't great, but as Graphics.DrawLines // isn't enlightened enough to take a start and length, // we copy the buffer out of the CircularBuffer into an // existing byte array so in theory we aren't allocating // an array over and over again _buffer = ArrayPool <Point> .Shared.Allocate(points.Size); points.CopyTo(_buffer); g.DrawLines(_tailPen, _buffer); ArrayPool <Point> .Shared.Free(_buffer); } else { int start; Point previous; Point current; // if we've wrapped the playing field, I can't just // call DrawLines with the entire buffer as we'll get // lines drawn across the entire playing field, so // instead I need to break it down into smaller buffers start = 0; previous = points.PeekAt(0); for (int i = 1; i < points.Size; i++) { current = points.PeekAt(i); if (Geometry.GetDistance(previous, current) > 1) { // here we have a split, so let us grab a subset of // the buffer and draw our lines this.DrawSection(g, points, start, i - start); start = i; } previous = current; } if (start < points.Size) { this.DrawSection(g, points, start, points.Size - start); } } } }