MCPcopy Create free account
hub / github.com/PricelessToolkit/MailBoxGuard / fillTriangle

Method fillTriangle

Code/Arduino_libraries/SSD1306/OLEDDisplay.cpp:314–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314void OLEDDisplay::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
315 int16_t x2, int16_t y2) {
316 int16_t a, b, y, last;
317
318 if (y0 > y1) {
319 _swap_int16_t(y0, y1);
320 _swap_int16_t(x0, x1);
321 }
322 if (y1 > y2) {
323 _swap_int16_t(y2, y1);
324 _swap_int16_t(x2, x1);
325 }
326 if (y0 > y1) {
327 _swap_int16_t(y0, y1);
328 _swap_int16_t(x0, x1);
329 }
330
331 if (y0 == y2) {
332 a = b = x0;
333 if (x1 < a) {
334 a = x1;
335 } else if (x1 > b) {
336 b = x1;
337 }
338 if (x2 < a) {
339 a = x2;
340 } else if (x2 > b) {
341 b = x2;
342 }
343 drawHorizontalLine(a, y0, b - a + 1);
344 return;
345 }
346
347 int16_t
348 dx01 = x1 - x0,
349 dy01 = y1 - y0,
350 dx02 = x2 - x0,
351 dy02 = y2 - y0,
352 dx12 = x2 - x1,
353 dy12 = y2 - y1;
354 int32_t
355 sa = 0,
356 sb = 0;
357
358 if (y1 == y2) {
359 last = y1; // Include y1 scanline
360 } else {
361 last = y1 - 1; // Skip it
362 }
363
364 for (y = y0; y <= last; y++) {
365 a = x0 + sa / dy01;
366 b = x0 + sb / dy02;
367 sa += dx01;
368 sb += dx02;
369
370 if (a > b) {
371 _swap_int16_t(a, b);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected