public static IMask RotateRight(this IMask matrix2, int r) { if (r < 0) { r = (4 + (r % 4)); } switch (r % 4) { case 0: return(matrix2); case 1: return(new Mask(matrix2.Select(p => new VectorInt2(matrix2.Size.Y - p.Y - 1, p.X)))); case 2: return(new Mask(matrix2.Select(p => new VectorInt2(matrix2.Size.X - p.X - 1, matrix2.Size.Y - p.Y - 1)))); case 3: return(new Mask(matrix2.Select(p => new VectorInt2(p.Y, matrix2.Size.X - p.X - 1)))); default: throw new Exception(); } }