@@ -21,6 +21,12 @@ val Grid<*>.width: Int get() = firstOrNull()?.size ?: 0
2121val Grid <* >.height: Int get() = size
2222val Grid <* >.area: Area get() = origin to lastPoint
2323
24+ val Iterable <Point >.area: Area get() = areaOrNull ? : error(" No points given" )
25+ val Iterable <Point >.areaOrNull: Area ? get() = boundingArea()
26+ val MapGrid <* >.area: Area get() = areaOrNull ? : error(" No points given in Map" )
27+ val MapGrid <* >.areaOrNull: Area ? get() = keys.boundingArea()
28+
29+
2430/* *
2531 * The last (bottom right) point in this [Grid] or `-1 to -1` for an empty Grid.
2632 */
@@ -165,6 +171,23 @@ fun <T> MapGrid<T>.formatted(
165171 }
166172}
167173
174+ fun <T > MapGrid<T>.formatted (
175+ area : Area ? = null,
176+ filler : Any = ' ',
177+ reverseX : Boolean = false,
178+ reverseY : Boolean = false,
179+ showHeaders : Boolean = true,
180+ transform : (Point , T ? ) -> String? = { _, value -> "$value" },
181+ ): String {
182+ val relevantArea = area ? : keys.boundingArea() ? : return " empty map, nothing to show"
183+ val default = filler.toString()
184+ return relevantArea.buildFormatted(reverseX, reverseY, showHeaders) { col, row ->
185+ val point = col to row
186+ val value = get(point)
187+ transform(col to row, value) ? : default
188+ }
189+ }
190+
168191fun Iterable<Point>.plot (
169192 restrictArea : Area ? = null, on : String = "#", off : String = " ",
170193 reverseX : Boolean = false,
0 commit comments