Adafruit-GFX-Library
Adafruit-GFX-Library copied to clipboard
Added functions to draw arcs
The provided code adds new library functions to draw arcs and filled arcs. It is based on existing circle drawing code. To realise the trigonometric functions a fixed-point math library is added. This should ensure that the change supports existing platforms.
(Just my 2Ω)
I think this change would expand up the size of the Adafruit_GFX API. There's no floating-point math in GFX at this point, and this is important for MCUs with no FPU. Arduino Uno is probably still the most popular target of the library.
That said, you might investigate drawing arcs by reusing the midpoint-algorithm from the drawCircle function [update: Oh, nevermind you are already doing that], and accepting the arc bounds in a fixed-point integer format, maybe arc seconds or even rectilinear boundaries or something like trigint_angle_t. You'd need something that can be evaluated by integer relational operations to produce an early stop condition for the drawCircle algorithm.
https://en.wikipedia.org/wiki/Midpoint_circle_algorithm#Drawing_incomplete_octants
Some prior art for integer trig functions. Divides the circle into 16384 units called trigint_angle_t, so angles can be given as int16_t. https://www.dribin.org/dave/trigint/
Thanks for the advices! I did some investigations and came up with a little fixed point library for trigonometric functions implemented as int16_t.
What is the status on this PR? Are there reasons why it should not be merged?