MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / tilesBetween

Method tilesBetween

source/gamemap/TileContainer.cpp:721–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

719}
720
721std::list<Tile*> TileContainer::tilesBetween(int x1, int y1, int x2, int y2) const
722{
723 std::list<Tile*> path;
724
725 double deltax = x2 - x1;
726 double deltay = y2 - y1;
727 // We don't have to check for deltay == 0 because if deltax > 0 and deltay == 0,
728 // we will never have std::abs(deltax) < std::abs(deltay) and, thus, we will
729 // never compute std::abs(deltax / deltay);
730 if(deltax == 0)
731 {
732 // Vertical line, no need to compute
733 int diffY = 1;
734 if(y1 > y2)
735 diffY = -1;
736
737 for(int y = y1; y != y2; y += diffY)
738 {
739 Tile* tile = getTile(x1, y);
740 if(tile == nullptr)
741 break;
742
743 path.push_back(tile);
744 }
745 }
746 else if(std::abs(deltax) >= std::abs(deltay))
747 {
748 double error = 0;
749 double deltaerr = std::abs(deltay / deltax);
750 int diffX = 1;
751 if(x1 > x2)
752 diffX = -1;
753
754 int diffY = 1;
755 if(y1 > y2)
756 diffY = -1;
757
758 int y = y1;
759 for(int x = x1; x != x2; x += diffX)
760 {
761 Tile* tile = getTile(x, y);
762 if(tile == nullptr)
763 break;
764
765 path.push_back(tile);
766 error += deltaerr;
767 if(error >= 0.5)
768 {
769 y += diffY;
770 error = error - 1.0;
771 }
772 }
773 }
774 else // if(std::abs(deltax) < std::abs(deltay))
775 {
776 double error = 0;
777 double deltaerr = std::abs(deltax / deltay);
778 int diffX = 1;

Callers 1

computeDestinationMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected