getWrapPosition function
Implementation
Offset getWrapPosition(double nextX, double nextY, double maxX, double maxY) {
if (nextX > maxX) {
// Exceeding right bound
nextX = nextX - maxX;
} else if (nextX < 0) {
// Exceeding left bound
nextX = nextX + maxX;
}
if (nextY > maxY) {
// Exceeding bottom bound
nextY = nextY - maxY;
} else if (nextY < 0) {
// Exceeding top bound
nextY = nextY + maxY;
}
return Offset(nextX, nextY);
}