MCPcopy Create free account
hub / github.com/NetHack/NetHack / selection_do_line

Function selection_do_line

src/selvar.c:625–680  ·  view source on GitHub ↗

bresenham line algo */

Source from the content-addressed store, hash-verified

623
624/* bresenham line algo */
625void
626selection_do_line(
627 coordxy x1, coordxy y1,
628 coordxy x2, coordxy y2,
629 struct selectionvar *ov)
630{
631 int d0, dx, dy, ai, bi, xi, yi;
632
633 if (x1 < x2) {
634 xi = 1;
635 dx = x2 - x1;
636 } else {
637 xi = -1;
638 dx = x1 - x2;
639 }
640 if (y1 < y2) {
641 yi = 1;
642 dy = y2 - y1;
643 } else {
644 yi = -1;
645 dy = y1 - y2;
646 }
647
648 selection_setpoint(x1, y1, ov, 1);
649
650 if (!dx && !dy) {
651 /* single point - already all done */
652 ;
653 } else if (dx > dy) {
654 ai = (dy - dx) * 2;
655 bi = dy * 2;
656 d0 = bi - dx;
657 do {
658 if (d0 >= 0) {
659 y1 += yi;
660 d0 += ai;
661 } else
662 d0 += bi;
663 x1 += xi;
664 selection_setpoint(x1, y1, ov, 1);
665 } while (x1 != x2);
666 } else {
667 ai = (dx - dy) * 2;
668 bi = dx * 2;
669 d0 = bi - dy;
670 do {
671 if (d0 >= 0) {
672 x1 += xi;
673 d0 += ai;
674 } else
675 d0 += bi;
676 y1 += yi;
677 selection_setpoint(x1, y1, ov, 1);
678 } while (y1 != y2);
679 }
680}
681
682void

Callers 3

l_selection_lineFunction · 0.85
l_selection_rectFunction · 0.85
l_selection_fillrectFunction · 0.85

Calls 1

selection_setpointFunction · 0.85

Tested by

no test coverage detected