getWrapPosition function

Offset getWrapPosition(
  1. double nextX,
  2. double nextY,
  3. double maxX,
  4. double maxY,
)

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);
}