public M rotate(int deg) {
		int rot = (deg + 45) / 90 % 4;
		M m = rot % 2 == 0 ? new M(width, height) : new M(height, width);
		for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) {
			switch (rot) {
			case 0: m.item(x, y, item(x, y)); break;
			case 1: m.item(y, m.height-x-1, item(x, y)); break;
			case 2: m.item(m.width-x-1, m.height-y-1, item(x, y)); break;
			case 3: m.item(m.width-y-1, x, item(x, y)); break;
			}
		}
		return m;
	}