Bresenham's algorithm - thx wikipedia and Adafruit_GFX
| 167 | |
| 168 | // Bresenham's algorithm - thx wikipedia and Adafruit_GFX |
| 169 | void OLEDDisplay::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) { |
| 170 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); |
| 171 | if (steep) { |
| 172 | _swap_int16_t(x0, y0); |
| 173 | _swap_int16_t(x1, y1); |
| 174 | } |
| 175 | |
| 176 | if (x0 > x1) { |
| 177 | _swap_int16_t(x0, x1); |
| 178 | _swap_int16_t(y0, y1); |
| 179 | } |
| 180 | |
| 181 | int16_t dx, dy; |
| 182 | dx = x1 - x0; |
| 183 | dy = abs(y1 - y0); |
| 184 | |
| 185 | int16_t err = dx / 2; |
| 186 | int16_t ystep; |
| 187 | |
| 188 | if (y0 < y1) { |
| 189 | ystep = 1; |
| 190 | } else { |
| 191 | ystep = -1; |
| 192 | } |
| 193 | |
| 194 | for (; x0<=x1; x0++) { |
| 195 | if (steep) { |
| 196 | setPixel(y0, x0); |
| 197 | } else { |
| 198 | setPixel(x0, y0); |
| 199 | } |
| 200 | err -= dy; |
| 201 | if (err < 0) { |
| 202 | y0 += ystep; |
| 203 | err += dx; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void OLEDDisplay::drawRect(int16_t x, int16_t y, int16_t width, int16_t height) { |
| 209 | drawHorizontalLine(x, y, width); |
nothing calls this directly
no outgoing calls
no test coverage detected