Created
February 1, 2022 13:46
-
-
Save lokedhs/dc6a7992df59e52980b398aa28111544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class SelectedArea(val x: Int, val y: Int, val width: Int, val height: Int) { | |
companion object { | |
fun computeSelectedArea(selectedCells: ObservableList<TablePosition<*, *>>): SelectedArea? { | |
if (selectedCells.size == 0) { | |
return null | |
} | |
val minCol = selectedCells.minOf { it.column } | |
val maxCol = selectedCells.maxOf { it.column } | |
val minRow = selectedCells.minOf { it.row } | |
val maxRow = selectedCells.maxOf { it.row } | |
val numCols = (maxCol - minCol) + 1 | |
val numRows = (maxRow - minRow) + 1 | |
val markers = IntArray(numRows * numCols) | |
selectedCells.forEach { p -> | |
markers[((p.row - minRow) * numCols) + (p.column - minCol)]++ | |
} | |
if (!markers.all { it == 1 }) { | |
return null | |
} | |
return SelectedArea(minCol, minRow, numCols, numRows) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment