Point updatePosition(Point now, double ox, double oy, int rat) {
		double nx = now.x + ox, ny = now.y + oy;
		int id_rat = rat;
		// hit the left fence
		if (nx < 0) {
			// System.err.println("RAT HITS THE LEFT FENCE!!!");
			// move the point to the left fence
			Point temp = new Point(0, now.y);
			// how much we have already moved in x-axis?
			double moved = 0 - now.x;
			// how much we still need to move
			// BUT in opposite direction
			double ox2 = -(ox - moved);
			//Random random = new Random();
			
			int theta = random.nextInt(360);
			thetas[rat] = theta;
			return updatePosition(temp, ox2, oy, id_rat);
		}
		// hit the right fence
		if (nx > dimension) {
			// System.err.println("RAT HITS THE RIGHT FENCE!!!");
			// move the point to the right fence
			Point temp = new Point(dimension, now.y);
			double moved = (dimension - now.x);
			double ox2 = -(ox - moved);
			//Random random = new Random();
			
			int theta = random.nextInt(360);
			thetas[rat] = theta;
			return updatePosition(temp, ox2, oy, id_rat);
		}
		// hit the up fence
		if (ny < 0) {
			// System.err.println("RAT HITS THE UP FENCE!!!");
			// move the point to the up fence
			Point temp = new Point(now.x, 0);
			double moved = 0 - now.y;
			double oy2 = -(oy - moved);
			//Random random = new Random();
		
			int theta = random.nextInt(360);
			thetas[rat] = theta;
			return updatePosition(temp, ox, oy2, id_rat);
		}
		// hit the bottom fence
		if (ny > dimension) {
			// System.err.println("RAT HITS THE BOTTOM FENCE!!!");
			Point temp = new Point(now.x, dimension);
			double moved = (dimension - now.y);
			double oy2 = -(oy - moved);
			//Random random = new Random();
			int theta = random.nextInt(360);
			thetas[rat] = theta;
			return updatePosition(temp, ox, oy2, id_rat);
		}
		assert nx >= 0 && nx <= dimension;
		assert ny >= 0 && ny <= dimension;
		// hit the middle fence
		if (hitTheFence(now.x, now.y, nx, ny)) {
			// System.err.println("SHEEP HITS THE CENTER FENCE!!!");
			// System.err.println(nx + " " + ny);
			// System.err.println(ox + " " + oy);
			// move the point to the fence
			Point temp = new Point(dimension/2, now.y);
			double moved = (dimension/2 - now.x);
			double ox2 = -(ox - moved);
			//Random random = new Random();
			int theta = random.nextInt(360);
			thetas[rat] = theta;
			return updatePosition(temp, ox2, oy, id_rat);
		}
		// otherwise, we are good
		return new Point(nx, ny);
	}