0

I have a object that renders a grid of lines (used for a plot object I am working on) that will update frequently and shift all the lines around. If the grid will update at 60 fps would using CGContextFillRects or CGContextAddLineToPoint (rectangles vs lines) be more efficient?

Let's assume I am going to implementing things in a pretty efficient way. For example with the line technique I would use CGContextMoveToPoint and CGContextAddLineToPoint before stroking the entire grid line in one go with CGContextStrokePath. For both techniques I will generate the data required to draw my shapes somewhere other than the drawRect method.

Initially I feel like CGContextFillRects is better because it has less code involved in the actual drawing at the high level I am operating on so at a glance it seems more efficient. This said I don't need rectangles, and am really making lines in the end here so perhaps generating a rectangle would be more involved than my graphing processing should be when all I really need is a line. What do you all think? Lines or Rectangles for my fast moving/scaling grid?

1 Answers1

0

Typically with computer graphics, drawing fewer pixels is preferable. CGContextAddLines looks like it accomplishes what you want, and might be shorter in code length than CGContextAddLineToPoint.

Gavin Higham
  • 89
  • 1
  • 4