diff --git a/orx-shapes/src/commonMain/kotlin/primitives/RectangleGrid.kt b/orx-shapes/src/commonMain/kotlin/primitives/RectangleGrid.kt index 3acf1f7c..42c96a77 100644 --- a/orx-shapes/src/commonMain/kotlin/primitives/RectangleGrid.kt +++ b/orx-shapes/src/commonMain/kotlin/primitives/RectangleGrid.kt @@ -78,3 +78,21 @@ fun Rectangle.grid( } } } + +/** + * Transposes a 2D list of rectangles, switching rows and columns. + * + * This method takes a list of lists and rearranges its elements such that + * the rows become columns and the columns become rows. + * + * @return A new 2D list of rectangles where rows and columns are swapped. + */ +fun List>.transpose() : List> { + val columns = MutableList>(this[0].size) { mutableListOf() } + for (row in this) { + for ((index, column) in row.withIndex()) { + columns[index].add(column) + } + } + return columns +} \ No newline at end of file